yorkie-js-sdk icon indicating copy to clipboard operation
yorkie-js-sdk copied to clipboard

Add tldraw undo/redo example

Open LakHyeonKim opened this issue 2 years ago • 6 comments
trafficstars

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

LakHyeonKim avatar Sep 14 '23 14:09 LakHyeonKim

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 14 '23 14:09 CLAassistant

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.

codecov[bot] avatar Sep 15 '23 01:09 codecov[bot]

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.

krapie avatar Sep 16 '23 14:09 krapie

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 avatar Sep 18 '23 01:09 LakHyeonKim

@LakHyeonKim I will notice right away you when we implement undo/redo :)

krapie avatar Sep 18 '23 03:09 krapie

@krapie Haha😁 thank you very much!

LakHyeonKim avatar Sep 18 '23 07:09 LakHyeonKim