Open astrarudra opened 7 months ago
Any workaround to do this ? @charkour ?
Hi @astrarudra,
Thank you so much for the kind words and thank you for your patience. Unfortunately, it's not possible to partialize a nested object and I don't think there's a way to change the code to support this.
However, here is a workaround to try. Create a setter in the zustand store that splits nested
into tracked
and untracked
. Your example would change from nested.nestedProp1
, nested.nestedProp2
, and nested.nestedPropUntracked
to tracked.nestedProp1
, tracked.nestedProp2
, and untracked.nestedPropUntracked
.
Hope this helps!
I'll take a look at adding a merge
function that would make your desired behavior easier to do by default.
Thanks! Ill take a look into the zundo code - Ill try, if i succeed - will send a pull requests :)
Thanks! I did take a look at the zundo code and decided it's likely best to make a middleware to handle how states are merged rather than update zundo itself.
hi is there an example of what to do here? i dont care for changes in all of my object properties, only some of them
First and foremost, I would like to express my appreciation for the incredible work you have done with Zundo. It has proven to be an invaluable tool for managing state and implementing undo/redo functionality in Zustand-powered applications.
I am reaching out to raise an issue I've encountered while using Zundo in conjunction with Zustand, particularly concerning the handling of nested objects within the store during undo and redo operations.
In my application's store, I have a structure that includes multiple properties, among which are nested, simple1, and simple2. While implementing undo and redo functionality, I have utilized the partialize function to specify which properties should be considered for linking to undo and redo actions. However, I have encountered a challenge specifically with the nested object.
The nested object contains several properties, such as nestedProp1, nestedProp2, nestedProp3, and nestedProp4. However, for undo and redo operations, I am only interested in tracking changes to nestedProp1 and nestedProp2. Unfortunately, the current implementation of partialize does not provide a straightforward way to achieve this level of granularity.
Is there a way to achieve this?
Here is an example of the current partialize implementation:
partialize: (state) => {
}