How would you guys do this without putting
'auth/logout': (state) => {
state = null
return { ...state }
}
in every model?
mark
You can create a rootReducer, rematch works perfectly with Redux things.
Here you have an example using Redux: https://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store/35641992#35641992.
Having this as a plugin would be so nice
You can also re-use a base reducer per model:
import { resetsOnLogout } from './authUtils'
const model = {
baseReducer: resetsOnLogout,
...
}
thank you gentlemen
I'm sorry, can you please providing snippet example of doing resetting state with baseReducer ?
Looking to how this would be done in pure Redux is probably needlessly complicated.
@gungdeaditya, this is the solution I'm using, and I think it is fairly elegant / concise. Just init the store with the rootReducer you need:
const store = init({
plugins,
models,
redux: {
rootReducers: {
RESET_APP: (state, action) => undefined,
},
devtoolOptions: {
disabled: process.env.NODE_ENV === 'production',
},
},
});
And then call RESET_APP whenever you need to by sending a message, ala classic Redux:
dispatch({ type: 'RESET_APP' })
Most helpful comment
Looking to how this would be done in pure Redux is probably needlessly complicated.
@gungdeaditya, this is the solution I'm using, and I think it is fairly elegant / concise. Just
initthe store with the rootReducer you need:And then call RESET_APP whenever you need to by sending a message, ala classic Redux: