Refactor Doc class to delegate mutations through DocStore#68
Conversation
Per docs-collaboration design, only explicit snapshot() calls create undo entries. Mutation methods no longer auto-push to undo stack. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Needed by Doc.deleteSelection() which removes middle blocks by index during multi-block selection deletion.
Task 2 implementer reverted Task 1's snapshot-only undo changes. Restore them: mutation methods do not call pushUndo() or clear redoStack. Only snapshot() creates undo entries. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Doc now takes a DocStore in its constructor and delegates all mutations (insert, delete, split, merge, style) through store methods. Maintains a cached Document for reads, refreshed after each mutation.
The design spec requires refresh() to be callable externally when remote changes arrive via YorkieDocStore.
TextEditor now uses doc.deleteBlockByIndex() instead of directly splicing doc.document.blocks, ensuring mutations go through DocStore.
Doc now receives the DocStore in its constructor so all mutations go through the store automatically. syncToStore() is no longer needed. Undo/redo uses doc.refresh() instead of directly assigning doc.document.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Verification: verify:selfResult: ✅ PASS in 95.8s
Verification: verify:integrationResult: ✅ PASS |
Summary
MemDocStoreto use snapshot-only undo contract: only explicitsnapshot()calls create undo entries, individual mutations no longer auto-push to undo stackdeleteBlockByIndex(index)toDocStoreinterface andMemDocStoreDocclass to take aDocStorein its constructor, delegate all mutations through store methods, and maintain a cachedDocumentrefreshed viarefresh()blocks.splice()inTextEditor.deleteSelection()withdoc.deleteBlockByIndex()syncToStore()from editor —Docnow writes through to the store directlyContext
This is the foundation for adding real-time collaborative editing via Yorkie's Tree CRDT (see
docs/design/docs-collaboration.md). By routing all mutations through theDocStoreinterface, a futureYorkieDocStorecan be plugged in without changingDocorTextEditor.Test plan
pnpm verify:fastpasses (1383+ tests across all packages)🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests