mobx-bonsai
Version:
A fast lightweight alternative to MobX-State-Tree + Y.js two-way binding
44 lines (43 loc) • 1.21 kB
TypeScript
import type * as Y from "yjs";
import { YjsStructure } from "./yjsTypes/types";
import { Dispose } from "../utils/disposable";
/**
* Creates a node that is bound to a Y.js data structure.
* Y.js Map and Array instances are bound to MobX objects and arrays, respectively.
*/
export declare const bindYjsToNode: <T extends object>({ yjsDoc, yjsObject, yjsOrigin, }: {
/**
* The Y.js document.
*/
yjsDoc: Y.Doc;
/**
* The Y.js data structure to bind.
*/
yjsObject: YjsStructure;
/**
* The Y.js origin symbol used for binding transactions.
* One will be automatically generated if not provided.
*/
yjsOrigin?: symbol;
}) => {
/**
* The bound node.
*/
node: T;
/**
* Resolves the corresponding Y.js value for a given target node.
*
* @param node - The node to resolve in the bound Yjs structure.
* @returns The resolved Y.js value.
* @throws Error if the target node is not found in the bound tree.
*/
getYjsValueForNode: (node: object) => unknown;
/**
* Disposes the binding.
*/
dispose: Dispose;
/**
* Disposes the binding.
*/
[Symbol.dispose](): void;
};