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
add to docs: Instructions on how to clear the ReSwift state. #367
Comments
Actually, I'll reopen so a maintainer sees this and could decide if it's worthy of adding to the docs. |
Is there an easy way to do this with a nested store? eg:
|
i've done it with the following code
|
Why do you reinit your state on the default case? That doesn't seem that good? (Not sure if it clears or not in your case) |
In my implementation I dispatch an action whenever I want to reset my state. This action can be dispatched either in deinit, viewWillDisapper or viewDidLoad (or of course anywhere else). When the Reducer get this action it will reset the state and return the initial one.
Usually I reset my state in deinit or in view did load (before I subscribe to the store) |
@carstenhag @ranhsd @dav92lee Would any of you like to whip up a small chapter for the docs and open a PR? That's the best place for reference code :) |
Took me 10 minutes to figure this out, actually, I just had forgotten to call
store.dispatch(ClearStore())
. I am sleepy, for my defense.I thought this would help beginners with this lib. Maybe add it to the docs or somewhere? At least with this issue it can be found via search engines.
In your
StoresReducer.swift
file, add another case.To your
Actions.swift
, add an empty Action:Finally, inside your clearing function (Maybe an Action for a debug button) add
If your views subscribe to store changes, the view should immediately behave how an initial installation of your app would.
The text was updated successfully, but these errors were encountered: