Skip to content

Instantly share code, notes, and snippets.

@ehatricksmith
Created October 27, 2022 22:42
Show Gist options
  • Save ehatricksmith/1b8dfb8d61e3ed1e1fa3ef30ae57e76c to your computer and use it in GitHub Desktop.
Save ehatricksmith/1b8dfb8d61e3ed1e1fa3ef30ae57e76c to your computer and use it in GitHub Desktop.
import * as Y from "yjs";
import * as util from "util";
const ydoc = new Y.Doc();
// Create a top level data type
const yarray = ydoc.getArray("listOfNumbers");
// Insert 1, then replace it with 2
yarray.insert(0, [1]);
yarray.delete(0);
yarray.insert(0, [2]);
// Log the underlying edits
const updates = Y.encodeStateAsUpdate(ydoc);
console.log(
util.inspect(Y.decodeUpdate(updates), { colors: true, depth: null })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment