1.148.1 • Published 4 years ago

@sanity/document-store v1.148.1

Weekly downloads
3,263
License
MIT
Repository
github
Last release
4 years ago

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
1.148.1

4 years ago

0.147.8

4 years ago

0.147.0

4 years ago

0.147.0-alpha.1

4 years ago

0.147.0-alpha.2

4 years ago

0.147.0-alpha.0

4 years ago

0.146.0

4 years ago

0.146.0-alpha.2

4 years ago

0.146.0-alpha.1

4 years ago

0.145.0

4 years ago

0.145.0-alpha.32

4 years ago

0.144.0

5 years ago

0.142.6

5 years ago

0.142.0

5 years ago

0.141.7-next.20

5 years ago

0.141.7-next.19

5 years ago

0.141.7-next.18

5 years ago

0.141.5

5 years ago

0.141.4

5 years ago

0.141.3

5 years ago

0.141.1

5 years ago

0.140.30

5 years ago

0.141.0-alpha.12

5 years ago

0.140.0

5 years ago

0.139.3-parrot.0

5 years ago

0.139.3-canary.0

5 years ago

0.139.1

5 years ago

0.140.0-alpha.4

5 years ago

0.140.0-alpha.3

5 years ago

0.140.0-alpha.1

5 years ago

0.139.0

5 years ago

0.139.0-rc.0

5 years ago

0.138.0

5 years ago

0.138.0-alpha.21

5 years ago

0.138.0-alpha.20

5 years ago

0.138.0-alpha.14

5 years ago

0.137.0

5 years ago

0.136.3

5 years ago

0.136.1-canary.5

5 years ago

0.136.0

5 years ago

0.135.3-next.6

6 years ago

0.135.0

6 years ago

0.135.0-next.2

6 years ago

0.135.0-next.1

6 years ago

0.134.2

6 years ago

0.135.0-beta.0

6 years ago

0.134.0

6 years ago

0.133.2

6 years ago

0.133.1

6 years ago

0.133.0

6 years ago

0.132.5

6 years ago

0.132.4-next.0

6 years ago

0.132.2

6 years ago

0.132.0

6 years ago

0.128.3

6 years ago

0.128.1

6 years ago

0.128.0

6 years ago

0.127.1

6 years ago

0.126.2

6 years ago

0.126.0

6 years ago

0.125.8

6 years ago

0.125.6

6 years ago

0.125.4

6 years ago

0.125.0

6 years ago

0.125.0-rc.4

6 years ago

0.124.12

6 years ago

0.125.0-rc.3

6 years ago

0.125.0-rc.2

6 years ago

0.125.0-rc.1

6 years ago

0.125.0-rc.0

6 years ago

0.124.0

6 years ago

0.121.0

6 years ago

0.120.0

6 years ago

0.119.0

6 years ago

0.118.4

7 years ago

0.118.0

7 years ago

0.117.0

7 years ago

0.116.0

7 years ago

0.116.0-rc.0

7 years ago

0.115.2

7 years ago

0.115.1

7 years ago

0.115.0

7 years ago

0.113.7

7 years ago

0.113.3

7 years ago

0.113.1

7 years ago

0.113.0

7 years ago

0.113.0-rc.0

7 years ago

0.112.0

7 years ago

0.111.6-beta.0

7 years ago

0.111.5

7 years ago

0.111.2

7 years ago

0.110.0

7 years ago

0.109.0

7 years ago

0.109.0-beta.0

7 years ago

0.108.0

7 years ago

0.108.0-beta.2

7 years ago

0.108.0-beta.1

7 years ago

0.107.27

7 years ago

0.106.28-next

7 years ago

0.106.27-next

7 years ago

0.106.21

7 years ago

0.106.16

7 years ago

0.106.14

7 years ago

0.106.13

7 years ago

0.106.12

7 years ago

0.106.10

7 years ago

0.106.2

7 years ago

0.105.12

7 years ago

0.105.8

7 years ago

0.105.6

7 years ago

0.105.1

7 years ago

0.105.0

7 years ago

0.105.0-drafts.2

7 years ago

0.104.45

7 years ago

0.105.0-drafts.0

7 years ago

0.104.44

7 years ago

0.104.43

7 years ago

0.104.34

7 years ago

0.104.30

7 years ago

0.104.26

7 years ago

0.104.23

7 years ago

0.104.22

7 years ago

0.104.13

7 years ago

0.104.12

7 years ago

0.104.10

7 years ago

0.104.9

7 years ago

0.103.13

7 years ago

0.103.12

7 years ago

0.103.9

7 years ago

0.103.6

7 years ago

0.103.5

7 years ago

0.103.0

7 years ago

0.102.5-next

7 years ago

0.102.4-next

7 years ago

0.102.2-next

7 years ago

0.102.1-next

7 years ago

0.102.0-next

7 years ago

0.101.20-next

7 years ago

0.101.18-next

7 years ago

0.101.17-next

7 years ago

0.101.16-next

7 years ago

0.101.14-next

7 years ago

0.101.13-next

7 years ago

0.101.12-next

7 years ago

0.101.11-next

7 years ago

0.101.10-next

7 years ago

0.101.7-next

7 years ago

0.101.6-next

7 years ago

0.101.5-next

7 years ago

0.101.0

7 years ago

0.100.15

7 years ago

0.100.3

7 years ago

0.99.4

7 years ago

0.99.3

7 years ago

0.99.0

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.2.0-mutator.1

7 years ago

0.2.0-mutator.0

7 years ago

0.1.0

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

8 years ago

0.0.1

8 years ago