Class ModelApi<N>

Local changes API for a JSON CRDT model. This class is the main entry point for executing local user actions on a JSON CRDT document.

Type Parameters

Implements

Constructors

Properties

builder: PatchBuilder

Patch builder for the local changes.

model: Model<N>

Model instance on which the API operates.

onBeforeLocalChange: FanOut<number> = ...

Emitted before local changes through model.api are applied.

onBeforePatch: FanOut<Patch> = ...

Emitted before a patch is applied using model.applyPatch().

onBeforeReset: FanOut<void> = ...

Emitted before the model is reset, using the .reset() method.

onBeforeTransaction: FanOut<void> = ...

Emitted before a transaction is started.

onChange: MergeFanOut<number | void | Patch> = ...

Emitted when the model changes. Combines onReset, onPatch and onLocalChange.

onChanges: MicrotaskBufferFanOut<number | void | Patch> = ...

Emitted when the model changes. Same as .onChange, but this event is emitted once per microtask.

onFlush: FanOut<Patch> = ...

Emitted when the model.api builder change buffer is flushed.

onLocalChange: FanOut<number> = ...

Emitted after local changes through model.api are applied.

onLocalChanges: MicrotaskBufferFanOut<number> = ...

Emitted after local changes through model.api are applied. Same as .onLocalChange, but this event buffered withing a microtask.

onPatch: FanOut<Patch> = ...

Emitted after a patch is applied using model.applyPatch().

onReset: FanOut<void> = ...

Emitted after the model is reset, using the .reset() method.

onTransaction: FanOut<void> = ...

Emitted after transaction completes.

stopAutoFlush?: (() => void) = undefined

Type declaration

    • (): void
    • Returns void

Accessors

Methods

  • Begins to automatically flush buffered operations into patches, grouping operations by microtasks or by transactions. To capture the patch, listen to the .onFlush event.

    Returns (() => void)

    Callback to stop auto flushing.

      • (): void
      • Returns void

  • Locates a bin node and returns a local changes API for it. If the node doesn't exist or the node at the path is not a bin node, throws an error.

    Parameters

    • Optional path: ApiPath

      Path at which to locate a node.

    Returns BinApi

    A local changes API for a bin node.

  • Locates a con node and returns a local changes API for it. If the node doesn't exist or the node at the path is not a con node, throws an error.

    Parameters

    • Optional path: ApiPath

      Path at which to locate a node.

    Returns ConApi<ConNode<any>>

    A local changes API for a con node.

    Todo

    Rename to con.

  • Given a JSON/CBOR value, constructs CRDT nodes recursively out of it and sets the root node of the model to the constructed nodes.

    Parameters

    • json: unknown

      JSON/CBOR value to set as the view of the model.

    Returns this

    Reference to itself.

  • Locates a str node and returns a local changes API for it. If the node doesn't exist or the node at the path is not a str node, throws an error.

    Parameters

    • Optional path: ApiPath

      Path at which to locate a node.

    Returns StrApi

    A local changes API for a str node.

  • Parameters

    • callback: (() => void)
        • (): void
        • Returns void

    Returns FanOutUnsubscribe