yorkie-js-sdk
yorkie-js-sdk copied to clipboard
Add tldraw undo/redo example
What this PR does / why we need it?
Hello ~ 👋
I've been working on a project that's very similar to tldraw. However, while the undo/redo functionality is essential, it's not an easy feature to implement.
I've tried adding the undo/redo feature to the tldraw example based on some considerations, even though I'm not very proficient with TypeScript. I'd like to share my idea and discuss it further.
Brief Explanation
- The history is managed per client, similar to tools like Figma and Google Slides.
- The onChangePage handler creates the history.
- Each unit of work in the history is referred to as a "command".
- However, the "onChangePage" handler gets called too often, leading to a bloated history. I've reduced the fps value of "useThrottleCallback" to mitigate this, but we might need to find a better solution.
- Every time undo or redo is performed, a snapshot of the current state of the yorkie doc is first created. The command then applies its original snapshot content to the yorkie doc. This is done to incorporate changes made by other users.
- The text does not undo/redo in the desired direction. This aspect needs further consideration.
I'd appreciate any feedback or suggestions.
Any background context you want to provide?
What are the relevant tickets?
Fixes #
Checklist
- [x] Added relevant tests or not required
- [x] Didn't break anything
Codecov Report
Patch and project coverage have no change.
Comparison is base (
2a49cfc) 88.88% compared to head (ade23a3) 88.88%.
Additional details and impacted files
@@ Coverage Diff @@
## main #645 +/- ##
=======================================
Coverage 88.88% 88.88%
=======================================
Files 80 80
Lines 8958 8958
Branches 825 825
=======================================
Hits 7962 7962
Misses 688 688
Partials 308 308
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Every interesting PR :) FYI, undo/redo implementation is in progress at https://github.com/yorkie-team/yorkie-js-sdk/pull/635, so check it out.
I've checked it. 👍 After submitting the PR, I noticed it. I'm very pleased to see that Yorkie supports undo and redo. Our project currently uses the undo and redo method as per the submitted PR, which makes the code very complex. I'm really looking forward to it. 😄
@LakHyeonKim I will notice right away you when we implement undo/redo :)
@krapie Haha😁 thank you very much!