kapv89 / yjs-scalable-ws-backend

MIT License
147 stars 25 forks source link

Question about getUpdates! #5

Open molink-huseong opened 2 years ago

molink-huseong commented 2 years ago

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.

kapv89 commented 2 years ago

Hi @molink-huseong just got back from a vacation ... will reply to your question tomorrow