json-joy
    Preparing search index...

    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

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    api: ModelApi<any>
    builder: PatchBuilder

    Patch builder for the local changes.

    model: Model<N>

    Model instance on which the API operates.

    node: RootNode
    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<undefined | number | Patch> = ...

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

    onChanges: MicrotaskBufferFanOut<undefined | number | 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

    Accessors

    • get events(): NodeEvents<N>

      Event target for listening to node changes. You can subscribe to "view" events, which are triggered every time the node's view changes.

      node.events.on('view', () => {
      // do something...
      });

      Returns NodeEvents<N>

    • get s(): ProxyNodeVal<N>

      Returns a proxy object for this node. Allows to access the value of the node by accessing the .val property.

      Returns ProxyNodeVal<N>

    Methods

    • Returns the API object of the extension if the node is an extension node. When the ext parameter is provided, it checks if the node is an instance of the given extension and returns the object's TypeScript type. Otherwise, it returns the API object of the extension, but without any type checking.

      Returns undefined | ExtApi<any>

      API of the extension

    • Returns the API object of the extension if the node is an extension node. When the ext parameter is provided, it checks if the node is an instance of the given extension and returns the object's TypeScript type. Otherwise, it returns the API object of the extension, but without any type checking.

      Type Parameters

      • EN extends ExtNode<any, any>
      • EApi extends ExtApi<EN>

      Parameters

      • ext: Extension<any, any, EN, EApi, any, any>

        Extension of the node

      Returns EApi

      API of the extension

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

      Parameters

      • drainNow: boolean = false

      Returns () => void

      Callback to stop auto flushing.

    • Find a child node at the given path starting from this node and wrap it in a local changes API.

      Parameters

      • Optionalpath: ApiPath

        Path to the child node to find.

      Returns ValApi<ValNode<any>>

      Local changes API for the child node at the given path.

    • 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.

      Use .set() instead.

    • Sets the value of the node.

      Parameters

      • json: unknown

        JSON/CBOR value or ID (logical timestamp) of the value to set.

      Returns this

      Reference to itself.

    • Parameters

      • callback: () => void

      Returns FanOutUnsubscribe