-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does undo/redo merge past state into current state? #196
Comments
Hey @KevinMusgrave, thanks for the note. I hadn't considered what would happen with dynamic keys. However, I'm surprised that it is not working as expected. If you have time, could you share a Stackblitz reproduction? The function Lines 86 to 92 in 65a1c99
The workaround of one permanent top-level key seems reasonable. |
Here's a stackblitz project to reproduce: https://stackblitz.com/edit/vitejs-vite-ykmbl1au?file=src%2Fcounter.js
Assuming I haven't made a mistake somewhere, the fix would be to call |
Sometimes I have a zustand state where I add top-level keys dynamically. For example, it might start off like:
Then I might later do:
If undo/redo is merging past states into the current state, then the "some_id" won't be removed.
I'm guessing it is merging, based on this line:
zundo/src/temporal.ts
Line 25 in 65a1c99
It's not a big deal, as I can just add a permanent top-level key and put the dynamic keys inside of that. Adding an option to overwrite state could be nice though, unless there's a way to do that already.
The text was updated successfully, but these errors were encountered: