Skip to content

CRDTProvider

Defined in: packages/core/src/crdt-provider.ts:13

CRDTProvider is an interface with a set of methods for manipulating CRDT documents.

MessageType

The sync message that gets sent when changes are made to a document

DocType

The CRDT document type

ChangesType

A block of CRDT change(s)

ChangeFnType

A function for applying changes to a document

optional applySnapshot(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().

DocType

Current CRDT document.

ChangesType

Snapshot state from getSnapshot().

DocType

The updated document with the snapshot state merged in.


getHistory(document): ChangesType

Defined in: packages/core/src/crdt-provider.ts:46

Gets all changes for the document.

DocType

CRDT document to inspect.

ChangesType


optional getSnapshot(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())

DocType

CRDT document to snapshot.

ChangesType

A snapshot representation. If the snapshot format differs from the incremental change format, implement applySnapshot() as well.


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.

DocType

CRDT document to change.

string

A description of the change made.

ChangeFnType

A function that modifies a CRDT document (provided as a parameter). This function will be run as a part of .localChange(...)

[DocType, ChangesType]


newDocument(): DocType

Defined in: packages/core/src/crdt-provider.ts:17

Create a new empty (contains the equivalent of {}) CRDT document.

DocType


remoteChange(document, changes): DocType

Defined in: packages/core/src/crdt-provider.ts:39

Apply CRDT document changes made by a remote peer.

DocType

CRDT document to update.

ChangesType

An object describing changes made by a peer. CRDT-specific.

DocType