Hi, Thank you for your good example of yjs-scalable-ws-backed.
Your code help me to understand how yjs provider work.
I have a question about this part
const persistedUpdates = await getUpdates(doc);
const dbYDoc = new Y.Doc();
dbYDoc.transact(() => {
for (const u of persistedUpdates) {
Y.applyUpdate(dbYDoc, u.update);
}
});
Y.applyUpdate(doc, Y.encodeStateAsUpdate(dbYDoc));
Why just directly update doc like this?
doc.transact(() => for (const u of persistedUpdates) {
Y.applyUpdate(dbYDoc, u.update);
})
I could't guess the reason why make new yjsDocument, apply update and encode new yjsUpdate for apply already exist document.
Hi, Thank you for your good example of yjs-scalable-ws-backed. Your code help me to understand how yjs provider work.
I have a question about this part const persistedUpdates = await getUpdates(doc); const dbYDoc = new Y.Doc(); dbYDoc.transact(() => { for (const u of persistedUpdates) { Y.applyUpdate(dbYDoc, u.update); } }); Y.applyUpdate(doc, Y.encodeStateAsUpdate(dbYDoc));
Why just directly update doc like this? doc.transact(() => for (const u of persistedUpdates) { Y.applyUpdate(dbYDoc, u.update); }) I could't guess the reason why make new yjsDocument, apply update and encode new yjsUpdate for apply already exist document.