1.148.1 • Published 5 years ago

@sanity/document-store v1.148.1

Weekly downloads
3,263
License
MIT
Repository
github
Last release
5 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

5 years ago

0.147.8

5 years ago

0.147.0

6 years ago

0.147.0-alpha.1

6 years ago

0.147.0-alpha.2

6 years ago

0.147.0-alpha.0

6 years ago

0.146.0

6 years ago

0.146.0-alpha.2

6 years ago

0.146.0-alpha.1

6 years ago

0.145.0

6 years ago

0.145.0-alpha.32

6 years ago

0.144.0

6 years ago

0.142.6

6 years ago

0.142.0

6 years ago

0.141.7-next.20

6 years ago

0.141.7-next.19

6 years ago

0.141.7-next.18

6 years ago

0.141.5

6 years ago

0.141.4

6 years ago

0.141.3

6 years ago

0.141.1

6 years ago

0.140.30

6 years ago

0.141.0-alpha.12

6 years ago

0.140.0

6 years ago

0.139.3-parrot.0

6 years ago

0.139.3-canary.0

6 years ago

0.139.1

6 years ago

0.140.0-alpha.4

6 years ago

0.140.0-alpha.3

6 years ago

0.140.0-alpha.1

6 years ago

0.139.0

6 years ago

0.139.0-rc.0

6 years ago

0.138.0

6 years ago

0.138.0-alpha.21

7 years ago

0.138.0-alpha.20

7 years ago

0.138.0-alpha.14

7 years ago

0.137.0

7 years ago

0.136.3

7 years ago

0.136.1-canary.5

7 years ago

0.136.0

7 years ago

0.135.3-next.6

7 years ago

0.135.0

7 years ago

0.135.0-next.2

7 years ago

0.135.0-next.1

7 years ago

0.134.2

7 years ago

0.135.0-beta.0

7 years ago

0.134.0

7 years ago

0.133.2

7 years ago

0.133.1

7 years ago

0.133.0

7 years ago

0.132.5

7 years ago

0.132.4-next.0

7 years ago

0.132.2

7 years ago

0.132.0

7 years ago

0.128.3

7 years ago

0.128.1

7 years ago

0.128.0

7 years ago

0.127.1

7 years ago

0.126.2

7 years ago

0.126.0

7 years ago

0.125.8

7 years ago

0.125.6

7 years ago

0.125.4

7 years ago

0.125.0

7 years ago

0.125.0-rc.4

7 years ago

0.124.12

7 years ago

0.125.0-rc.3

7 years ago

0.125.0-rc.2

7 years ago

0.125.0-rc.1

7 years ago

0.125.0-rc.0

7 years ago

0.124.0

7 years ago

0.121.0

8 years ago

0.120.0

8 years ago

0.119.0

8 years ago

0.118.4

8 years ago

0.118.0

8 years ago

0.117.0

8 years ago

0.116.0

8 years ago

0.116.0-rc.0

8 years ago

0.115.2

8 years ago

0.115.1

8 years ago

0.115.0

8 years ago

0.113.7

8 years ago

0.113.3

8 years ago

0.113.1

8 years ago

0.113.0

8 years ago

0.113.0-rc.0

8 years ago

0.112.0

8 years ago

0.111.6-beta.0

8 years ago

0.111.5

8 years ago

0.111.2

8 years ago

0.110.0

8 years ago

0.109.0

8 years ago

0.109.0-beta.0

8 years ago

0.108.0

8 years ago

0.108.0-beta.2

8 years ago

0.108.0-beta.1

8 years ago

0.107.27

8 years ago

0.106.28-next

8 years ago

0.106.27-next

8 years ago

0.106.21

8 years ago

0.106.16

8 years ago

0.106.14

8 years ago

0.106.13

8 years ago

0.106.12

8 years ago

0.106.10

8 years ago

0.106.2

8 years ago

0.105.12

8 years ago

0.105.8

8 years ago

0.105.6

8 years ago

0.105.1

8 years ago

0.105.0

8 years ago

0.105.0-drafts.2

8 years ago

0.104.45

8 years ago

0.105.0-drafts.0

8 years ago

0.104.44

8 years ago

0.104.43

8 years ago

0.104.34

8 years ago

0.104.30

8 years ago

0.104.26

8 years ago

0.104.23

8 years ago

0.104.22

8 years ago

0.104.13

8 years ago

0.104.12

8 years ago

0.104.10

8 years ago

0.104.9

8 years ago

0.103.13

8 years ago

0.103.12

8 years ago

0.103.9

8 years ago

0.103.6

8 years ago

0.103.5

8 years ago

0.103.0

8 years ago

0.102.5-next

8 years ago

0.102.4-next

8 years ago

0.102.2-next

8 years ago

0.102.1-next

8 years ago

0.102.0-next

8 years ago

0.101.20-next

8 years ago

0.101.18-next

8 years ago

0.101.17-next

8 years ago

0.101.16-next

8 years ago

0.101.14-next

8 years ago

0.101.13-next

8 years ago

0.101.12-next

8 years ago

0.101.11-next

8 years ago

0.101.10-next

8 years ago

0.101.7-next

8 years ago

0.101.6-next

8 years ago

0.101.5-next

8 years ago

0.101.0

8 years ago

0.100.15

8 years ago

0.100.3

8 years ago

0.99.4

8 years ago

0.99.3

8 years ago

0.99.0

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.2.0-mutator.1

9 years ago

0.2.0-mutator.0

9 years ago

0.1.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago