zundo
zundo copied to clipboard
Will this work with native persist middleware?
This looks great, but before adding it to my project I'd like to know if and how this middleware will work with zustand's persist middleware. Please advise!
Hi @adanielyan,
Thanks for your great question. Are you asking if the past and future states are persisted, or if your store is persisted?
Thanks.
v2 should work with the persist middleware.
You can test it out with npm i zundo@beta
!
v2 should work with the persist middleware
should, but how? 🤔 so far managed to get persist running of the main store but previous states do not get carried over
@SugarF0x,
Thanks for the question. Right now, using persist will only persist the main store, and not the temporal store.
I haven't tried this, but does it work to wrap myStore.temporal
with the persist
middleware? If not, I can push an update that give the ability to use persist
middleware on the temporal store.
Just let me know. Thanks.
@charkour thanks for the quick reply! Unfortunately, wrapping temporal with persist does not work Would have been fantastic to have such an option to do so!
@SugarF0x, thanks for the info.
Shoot, I was hoping it would work but it makes sense it does not. In v1 of zundo, it didn't play well with other middleware, so I fixed that, but we need to find a way to pass middleware to the temporal store.
zundo v2 creates a second zustand store for the temporal state when v1 injected the temporal state into the user's store. I've been thinking of returning to the v1 approach which should fix your issue. Do you have any input on how you'd like to see this go forward? Thanks.
@charkour ive only started fiddling around with zustand & its ecosystem so not too too familiar with the way things work under the hood yet, so makes me wonder if a middleware can extend given initial state with additional fields, perhaps it would be possible to append temporal to the store root under _temporal
key or something along these lines so that it would act much like an actual part of the store itself 🤔
Awesome, I was thinking along the same lines.
Can't promise a release date for this, but I'll work on it this weekend. Thanks for the input!
@charkour created a quick and extremely dirty proof of concept for in-store temporal state https://github.com/SugarF0x/zundo
Damn, only now did i realize that instead of doing what i did i could have just modified current getVanillaZundo
implementation to add other middlewares support :skull:
That is awesome! Thanks for sharing, that is similar to what I have, but you got a lot further. You're welcome to make a PR and I can suggest code changes.
I'm not sure what you mean by getVanillaZundo
, but that sounds promising.
meant to say createVanillaTemporal
i will fiddle around and see if that can be modified and should either of these two look promising, will get down to doing the typescript bits and updating tests
@charkour updated the implementation to support optional persist middleware on temporal store leaving the functionality almost intact and (hopefully) backwards compatible https://github.com/charkour/zundo/pull/61