@mocanvas/sync · interface

Crdt

interface Crdt<R extends UnknownRecord = UnknownRecord>

This one ships without a description. The signature above is read from the package, and the guides cover the area it belongs to.


Methods · 7

applyState(state: CrdtState): RecordsDiff<R>

Adopt a peer's stamps wholesale. This is what a replica that is joining with no state of its own does, together with that peer's records: it takes the peer's stamps instead of starting blank, so its own later writes sort after everything already in the room. The returned diff removes whatever the peer has tombstoned and we still hold. Only for a replica holding no stamps at all: the caller adopts the peer's records wholesale alongside it, so a replica with work of its own must merge the snapshot through stampedDiffFromSnapshot instead of taking it.

collectTombstones(): void

Drop tombstones past the count or age bound. Called after every merge.

getState(): CrdtState

This replica's stamps, for a snapshot message.

mergeRemote(stamped: StampedDiff<R>): RecordsDiff<R>

Merge a peer's message. The returned diff holds only the fields that won, as whole records the store can apply — never a blind overwrite.

size(): number

Number of records the state currently tracks (tests and diagnostics).

stampLocal(diff: RecordsDiff<R>): StampedDiff<R>

Stamp a diff the local user just made and return the message to send. The whole diff shares one stamp: it was one operation.

takeOutgoing(): StampedDiff<R> | null

Writes this replica minted while merging, which the caller must broadcast. A record kept alive by an edit that outranks a delete is re-claimed whole under a fresh stamp: the tombstone leaves the fields it dominates with no provenance at all, and only a stamped body can put every replica on the same one. Empty when there is nothing to send.


Properties · 2

readonly clientId: string
readonly clock: LamportClock

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.