0.3.0 • Published 7 years ago
@lyra/document-store v0.3.0
Document store
Lyra / saga document store
Example
// If you are interested in everything that happens with document `lol42`
const subscription = documents.byId('lol42').subscribe(event => {
console.log('Something happened with document lol42!', event)
})
// After a while, when you are no longer interested in updates fom document `lol42`:
subscription.unsubscribe()How it works
When you add a subscriber to a document the first thing that happens is that the subscriber function is called with a snapshot of the document's current state. This happens as soon as the snapshot is retrieved. If there is a cached version of it on the client, the snapshot is received immediately (synchronously).
From that moment on, you will receive a new event every time something happens to the document, until you unsubscribe again.
API
createDocumentStore({serverConnection: ServerConnection}) : DocumentStore
ServerConnection must be an object with the following api:
byId(id : string) : Observable<DocumentEvent>query(query : string) : Observable<QueryResultEvent>(todo, add more)
DocumentStore
Query methods
byId(id : string) : Observable<DocumentEvent>byIds(ids : Array<string>) : Observable<QueryResultEvent>query(query : string) : Observable<QueryResultEvent>
Mutation methods
update(id : string, spec : UpdateSpec) : Observable<OperationEvent>create(document : Document) : Observable<OperationEvent>replace(documentId : string, document : Document) : Observable<OperationEvent>createOrReplace(document : Document) : Observable<OperationEvent>delete(documentId : string) : : Observable<OperationEvent>
Document
_id : string_type : string
DocumentEventType
DocumentEvent
type : stringeither one ofsnapshot,updatesnapshot : Document