CRDTProvider
Defined in: packages/core/src/crdt-provider.ts:13
CRDTProvider is an interface with a set of methods for manipulating CRDT documents.
Type Param
Section titled “Type Param”MessageType
The sync message that gets sent when changes are made to a document
Type Parameters
Section titled “Type Parameters”DocType
Section titled “DocType”DocType
The CRDT document type
ChangesType
Section titled “ChangesType”ChangesType
A block of CRDT change(s)
ChangeFnType
Section titled “ChangeFnType”ChangeFnType
A function for applying changes to a document
Methods
Section titled “Methods”applySnapshot()?
Section titled “applySnapshot()?”
optionalapplySnapshot(document,snapshot):DocType
Defined in: packages/core/src/crdt-provider.ts:73
Apply a full-state snapshot produced by getSnapshot().
Implement this when the snapshot format differs from incremental changes
(e.g. Automerge’s save() output cannot be applied via applyChanges()).
When not implemented, the caller falls back to remoteChange().
Parameters
Section titled “Parameters”document
Section titled “document”DocType
Current CRDT document.
snapshot
Section titled “snapshot”ChangesType
Snapshot state from getSnapshot().
Returns
Section titled “Returns”DocType
The updated document with the snapshot state merged in.
getHistory()
Section titled “getHistory()”getHistory(
document):ChangesType
Defined in: packages/core/src/crdt-provider.ts:46
Gets all changes for the document.
Parameters
Section titled “Parameters”document
Section titled “document”DocType
CRDT document to inspect.
Returns
Section titled “Returns”ChangesType
getSnapshot()?
Section titled “getSnapshot()?”
optionalgetSnapshot(document):ChangesType
Defined in: packages/core/src/crdt-provider.ts:60
Get a compacted state snapshot of the document. Used for onboarding new members without replaying individual changes.
For Yjs: Y.encodeStateAsUpdateV2(doc) (directly applicable via remoteChange())
For Automerge: Automerge.save(doc) (requires applySnapshot() since save format
differs from the incremental change format used by remoteChange())
Parameters
Section titled “Parameters”document
Section titled “document”DocType
CRDT document to snapshot.
Returns
Section titled “Returns”ChangesType
A snapshot representation. If the snapshot format differs from the
incremental change format, implement applySnapshot() as well.
localChange()
Section titled “localChange()”localChange(
document,message,changeFn): [DocType,ChangesType]
Defined in: packages/core/src/crdt-provider.ts:27
Apply locally made changes to provided CRDT document as defined by changeFn.
Parameters
Section titled “Parameters”document
Section titled “document”DocType
CRDT document to change.
message
Section titled “message”string
A description of the change made.
changeFn
Section titled “changeFn”ChangeFnType
A function that modifies a CRDT document (provided as a parameter).
This function will be run as a part of .localChange(...)
Returns
Section titled “Returns”[DocType, ChangesType]
newDocument()
Section titled “newDocument()”newDocument():
DocType
Defined in: packages/core/src/crdt-provider.ts:17
Create a new empty (contains the equivalent of {}) CRDT document.
Returns
Section titled “Returns”DocType
remoteChange()
Section titled “remoteChange()”remoteChange(
document,changes):DocType
Defined in: packages/core/src/crdt-provider.ts:39
Apply CRDT document changes made by a remote peer.
Parameters
Section titled “Parameters”document
Section titled “document”DocType
CRDT document to update.
changes
Section titled “changes”ChangesType
An object describing changes made by a peer. CRDT-specific.
Returns
Section titled “Returns”DocType