UNPKG

mobx-bonsai-yjs

Version:

Y.js two-way binding for mobx-bonsai

44 lines (43 loc) 1.26 kB
import { _Dispose } from 'mobx-bonsai'; import { YjsStructure } from './yjsTypes/types'; import type * as Y from "yjs"; /** * 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, or a function that returns the symbol. * One will be automatically generated if not provided. */ yjsOrigin?: symbol | (() => 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; };