Skip to main content

yjs

import * as Y from 'yjs'

const ydoc = new Y.Doc()
const ymap = ydoc.getMap()
ymap.set('keyA', 'valueA')

const ydocRemote = new Y.Doc()
const ymapRemote = ydocRemote.getMap()
ymapRemote.set('keyB', 'valueB')

const update = Y.encodeStateAsUpdate(ydocRemote)
Y.applyUpdate(ydoc, update)

console.log(ymap.toJSON()) // => { keyA: 'valueA', keyB: 'valueB' }