Skip to content

Instantly share code, notes, and snippets.

@ehatricksmith
Created October 27, 2022 22:51
Show Gist options
  • Save ehatricksmith/320669c18bb2318ba410c269b0aa60d5 to your computer and use it in GitHub Desktop.
Save ehatricksmith/320669c18bb2318ba410c269b0aa60d5 to your computer and use it in GitHub Desktop.
```tsx
import * as Y from "yjs";
import * as util from "util";
const ydoc = new Y.Doc();
// Create a top level data type
const ytext = ydoc.getText("text");
****// Insert subsequent characters
ytext.insert(0, "A");
ytext.insert(1, "B");
ytext.insert(2, "C");
// 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