🌜
🌞
@sanity/document-store

@sanity/document-store

v1.148.1

Sanity / gradient document store

npm install @sanity/document-store

README

Document store

Sanity / gradient 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 : string either one of snapshot, update
  • snapshot : Document

General

License
MIT
Typescript Types
None found
Tree-shakeable
No

Popularity

GitHub Stargazers
3,672
Community Interest
3,215
Number of Forks
323

Maintenance

Commits
10/219/220450
Last Commit
Open Issues
484
Closed Issues
690
Open Pull Requests
24
Closed Pull Requests
245

Versions

Versions Released
10/219/2201
Latest Version Released
Feb 13, 2020
Current Tags
latest1.148.1
rc0.125.0-rc.4
beta0.111.6-beta.0
next0.141.7-next.20
vega0.133.0-vega.cb3cdeee
alpha0.139.3-parrot.0
focus0.122.0-focus.5d5f8af0
canary0.147.8-canary.18
drafts0.105.0-drafts.0
spaces0.122.0-spaces.bc70a23d
babel-70.133.0-babel-7.06032ac5
gql-rtb0.136.3-gql-rtb.417
graphql0.136.1-canary.66
mutator0.2.0-mutator.1
cli-next0.122.0-cli-next.76de446a
weakrefs0.122.0-weakrefs.962100b2
structure0.134.0-alpha.d19d4c0c
ts-client0.147.10-ts-client.1
hints-mode0.146.4-hints-mode.156
cheesy-bites0.144.4-cheesy-bites.121
custom-login0.124.0-default-login.063643d2
asset-sources0.147.0-alpha.2
fix-span-keys0.126.0-fix-span-keys.12d2645d
launch-design0.116.0-alpha.afa81e66
schema-validation0.118.0-alpha.3044306e
realtime-block-editor0.140.0-alpha.4
initial-value-templates0.143.0-initial-value-templates.55
block-tools-white-space-fix0.147.0-block-tools-white-space-fix.2
handle-access-control-errors0.147.0-handle-access-control-errors.38

Dependencies

Dependencies (4)
Dev Dependencies (0)

Contributors

rexxars
rexxars
Commits: 3,199
bjoerge
bjoerge
Commits: 2,780
kristofferj
kristofferj
Commits: 1,632
mariuslundgard
mariuslundgard
Commits: 1,163
skogsmaskin
skogsmaskin
Commits: 747
vicbergquist
vicbergquist
Commits: 249
simen
simen
Commits: 95
judofyr
judofyr
Commits: 60
hermanwikner
hermanwikner
Commits: 54
benedicteb
benedicteb
Commits: 51
saasen
saasen
Commits: 49
mikolajdobrucki
mikolajdobrucki
Commits: 43
ricokahler
ricokahler
Commits: 40
kmelve
kmelve
Commits: 30
evenwestvang
evenwestvang
Commits: 28