y-utility provides essential helper functionalities for Yjs, a CRDT implementation for collaborative applications. The current stable version is 0.1.4, with releases occurring periodically to address bugs and integrate with newer Yjs versions. Key features include `YMultiDocUndoManager`, which extends Yjs's built-in `UndoManager` to handle undo/redo operations across multiple `Y.Doc` instances, essential for managing complex, nested document structures. It also offers `YKeyValue`, an optimized key-value store designed to address performance inefficiencies and document size growth observed when using `Y.Map` for frequently updated, alternating key-value pairs, thereby reducing metadata overhead and improving encoding size. This library targets environments running Node.js version 16 or newer, aligning with modern JavaScript module standards.
npm install y-utilityVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up and use `YMultiDocUndoManager` to manage undo/redo history across multiple `Y.Doc` instances and their shared types.
Update imports and class instantiations from `MultiDocUndoManager` to `YMultiDocUndoManager`.
For datasets approaching or exceeding 1 million objects, monitor performance closely. Consider alternative data structures or custom optimizations if `YKeyValue` becomes a bottleneck. The core Yjs team is exploring future solutions.
For dynamic key-value scenarios with frequent updates and deletions, use `YKeyValue` instead of `Y.Map` to benefit from optimized document size and performance.
Downgrade your `yjs` dependency to a version prior to 13.6.13, or check for updates to `y-utility` that explicitly address compatibility with `yjs` 13.6.13 and newer.
Implement custom logic to manage the `undoStack` and `redoStack` properties of the undo manager, such as splicing them to limit their size, especially when items are popped off the stack, to allow underlying Yjs items to be garbage collected.
Ensure you are importing from the correct subpath: `import { YMultiDocUndoManager } from 'y-utility/y-multidoc-undomanager'`.For modern Node.js environments (>=16), use ESM `import`. If using CommonJS, check your bundler configuration or consider using the explicit CommonJS export path if available (e.g., `require('y-utility/dist/y-keyvalue.cjs')`).Install `yjs` with `npm install yjs@^13.5.29` or ensure your existing `yjs` version is within the compatible range.