I have a Y.Doc that is shared using WebSocketProvider in a room, room A. I now want to clone the document to another room (room B), so that a client of room B will initially see the same as the client of room A at the moment of cloning, but, thereafter, room B will not be updated with changes in room A and vice versa. I have tried this:
// ...
// code to create a ydoc with shared types linked to room 'A' using 'websocket' and apply various insertions etc.
// ...
//
let state = Y.encodeStateAsUpdate(ydoc);
let clonedDoc = new Y.Doc();
let ws = new WebsocketProvider(websocket, 'B', clonedDoc)
ws.on('sync', () => {
Y.applyUpdate(clonedDoc, state)
});
I am assuming that applying state
as an update to the empty clonedDoc
will yield a copy of the state of room A in room B. However, if I run the above code, and access the cloned room, I find a ydoc
that has the same structure (i.e. has the same shared types) as the room being cloned, but all the values are missing. What am I doing wrong?