-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
How to reset store and it's sub-stores? #178
Comments
Hey @lishine Reseting the whole store, i.e. placing the reset on the root, should reset all the sub-stores too. 👍 Quick reference... let initialState = {}
const store = createStore({
...,
reset: action((state, payload) => ({
...initialState,
}),
});
initialState = store.getState();
// Later... reset store
store.dispatch.reset(); |
Oh, I got it ! Cool! |
I went further, in order not to import the initialState into store part file, I put it into store root. Is it possible to have access to the Store State in actions? model:
creating:
store part:
|
Also, the reset happens unpredictably because thunk is used, some not sync nature |
Hey @lishine |
I hope I will do it. The only real misunderstanding of mine is the nature of thunk #179 . If it is async, of course I would not want to use it for reset. And I will use it carefully anyway. BTW, the initState assignment should be done only in the first createStore in case of SSR:
|
#146 This is a way to reset store.
But usually I have sub-stores, how do I reset the whole store part and sub-parts efficiently? I have to call reset for each sub-store:
Or maybe walk down the tree, search reset() and call it.
Is there some idea on a better solution?
The text was updated successfully, but these errors were encountered: