fn

createNativeProvider

The built-in CRDT provider backed by @robonen/crdt: a fractional-ordered set of blocks, each a text RGA + mark store. Writekit steps map to CRDT ops via DocumentCrdt; ops sync as op batches over any transport.

Signature

ts
export function createNativeProvider(options: NativeProviderOptions): CrdtProvider{ ... }

Parameters

ParameterTypeDescription
optionsNativeProviderOptions

Returns

CrdtProvider
PropertyTypeDescription
namestring
load() => WritekitDocumentThe current document materialized from CRDT state.
applyLocal(tr: Transaction) => voidTranslate a local transaction's steps into CRDT ops and apply them.
applyUpdate(bytes: Uint8Array, origin?: unknown) => voidMerge a remote update (encoded ops) into the CRDT.
encodeStateVector() => Uint8ArrayEncode this replica's version vector for a sync handshake.
encodeDelta(remoteStateVector?: Uint8Array) => Uint8ArrayEncode ops a remote is missing (by its state vector); omit for a full snapshot.
onLocalOps(listener: (bytes: Uint8Array) => void) => () => voidSubscribe to locally-produced op batches (to broadcast). Returns unsubscribe.
onRemoteApplied(listener: () => void) => () => voidSubscribe to "remote ops were applied" (to reflect into writekit state). Returns unsubscribe.
setLocalSelection(selection: Selection | null) => voidPublish the local selection as presence (anchored to char ids).
onLocalAwareness(listener: (bytes: Uint8Array) => void) => () => voidSubscribe to locally-produced awareness frames (to broadcast). Returns unsubscribe.
applyAwareness(bytes: Uint8Array) => voidMerge a remote awareness frame.
onAwareness(listener: (cursors: RemoteCursor[]) => void) => () => voidSubscribe to the resolved set of remote cursors. Returns unsubscribe.
gc(stableStateVector?: Uint8Array) => { blocks: number; chars: number }Compact tombstones and removed blocks covered by stableStateVector (or this replica's version when omitted). Safe only at quiescence — all peers fully synced, nothing in flight. Returns how much was dropped.
destroy() => void