Add persist options for temporal store#61
Conversation
|
Thanks for this! @SugarF0x I'll help update the tests. Would you like me to make a PR in your fork, is it okay to push to this branch (you might have to click "allow edits from maintainers". |
|
@charkour Aye, ive checked maintainers' edits so you can push straight to my fork's main branch |
|
Sorry, there was a bug due to the lastest version of zustand. Would you be willing to update this PR? |
# Conflicts: # packages/zundo/__tests__/createVanillaTemporal.test.ts # packages/zundo/__tests__/options.test.ts # packages/zundo/__tests__/zundo.test.ts # packages/zundo/src/index.ts # packages/zundo/src/temporal.ts # packages/zundo/src/types.ts # pnpm-lock.yaml
|
@charkour aye, fixed that up nicely, working just as fine 👌 |
|
@charkour reconsidered approach, allowed use of practically any kind and any amount of temporal store middlewares while containing the logic within the temporal middleware itself 👌 |
|
Awesome! I'll take a look at it now. Thanks for the work on it! |
|
@SugarF0x, do you like the ability to add different middleware to the temporal store than the main store? Originally, I thought that we could add the temporal state to the main store. What do you think? Maybe both should be an option. |
|
@charkour we could add an option to toggle between the in-store and out-of-store options to base the temporal store at Initially i also thought about adding temporal to the main store but then decided that this would be a bit of a breaking change Plus, Im not too convinced that tampering with one's store directly is not too user friendly since that happens implicitly Imagine adding an Change merge order and now we have a different issue - user declared While that could be pointed out in the README as a caveat or all the temporal functionality could be shoved under a I dont think either option is inherently good or bad, Im just trying to play devils advocate here Both ideas are good and the final choice is on you as the author In the end, i only ever stuck with the current implementation of having temporal in a dedicated store purely out of the backwards-compatibility consideration |
|
I agree with you and your line of thinking. Let's go forward with keeping the temporal state separate from the user state, but I'll also add a separate function that can be used to inject the temporal state into the user state to make middleware simpler. |
|
@SugarF0x, would you be willing to update the tests for this PR? I can't seem to be able to edit this branch. I'm working on the function that allows you to inject directly into the user's state. |
|
Tests are looking good! Thanks for leading this feature development! I think once this is merged, we can release v2 finally! I'll check this over in a couple hours. |
packages/zundo/src/types.ts
Outdated
| handleSet: StoreApi<TState>['setState'], | ||
| ) => StoreApi<TState>['setState']; | ||
| handleSet?: (handleSet: StoreApi<TState>['setState']) => StoreApi<TState>['setState']; | ||
| storeWrap?: (initializer: StateCreator<TemporalStateWithInternals<TState>, [], []>) => StateCreator<TemporalStateWithInternals<TState>, [], []> |
There was a problem hiding this comment.
What other names did you think of for storeWrap? I'm wondering if there is a better one we could use.
Perhaps, temporalMiddleware or simply middleware? Maybe storeMiddleware or wrapTemporalStore?
I'm not sure if there are other examples is in the zustand ecosystem that use this pattern we could copy.
What do you think?
There was a problem hiding this comment.
storeWrap was more of a WIP TBD name, either middlewares or middlewareInjection would be much more suitable
alternatively, this could be called storeInitializerInjection since the purpose if it is to add some custom functionality e.g. middlewares to a store initializator which is the zustand name for the function we pass to create method
There was a problem hiding this comment.
Okay, I prefer the name wrapTemporal or wrapTemporalStore.
What do you think?
Once these small comments are addressed, we can merge this in, add docs, and release a new version! Thank you for all the great help.
There was a problem hiding this comment.
Happy to be working on this, amazing opportunity to both learn more about middlewares as well as to do some good for the people using this much like i do
wrapTemporalStore sounds good to me
packages/zundo/src/index.ts
Outdated
| }; | ||
|
|
||
| export const temporal = zundoImpl as unknown as Zundo; | ||
| export { TemporalStateWithInternals }; |
There was a problem hiding this comment.
ideally we should not be exposing that, its currently sitting here for testing purposes
charkour
left a comment
There was a problem hiding this comment.
This is looking good! Thanks for this.
Once this is no longer a draft, we can merge it in!
|
ye i just gotta figure out how to fix the typing system |
|
Sounds good! The types stretch my understanding as well. I'll look into the type errors as well. |
|
@charkour i fixed the typings |
|
Oh wow. Not much type safety there. |
|
Also, the typings are looking good! Thanks again for working on it. |
|
Would you like a review on this? Or is it still a draft? |
|
@charkour ye i think its review worthy at this point |
# Conflicts: # packages/zundo/src/temporal.ts
| export default defineConfig({ | ||
| test: { | ||
| globals: true, // required | ||
| setupFiles: ['vitest-localstorage-mock'], |
There was a problem hiding this comment.
This is a nice package. Helpful for testing. Thanks!
# Conflicts: # apps/web/package.json # packages/zundo/package.json # packages/zundo/src/index.ts # pnpm-lock.yaml
|
Thanks for the updates to the branch! |
|
@charkour aye, my pleasure |
|
Yeah, sorry this is taking so long. Let's say one week. That way I'll prioritize reviewing this. Thank you so much for your effort and patience. |
|
I'll merge this into the |
|
Thanks for your patience on this. |



Expose internal temporal store state creator function to allow for middleware injections which include but are not limited to persist
Todo: