Initial state must be always passed to reducer
steida opened this issue ยท 5 comments
My workaround.
function recycle(reducer, actions = [], initialState) {
return (state, action) => {
if (actions.indexOf(action.type) >= 0) {
return reducer(initialState, {type: '@@redux-recycle/INIT'});
// if (initialState === undefined) {
// return reducer(undefined, { type: '@@redux-recycle/INIT' })
// }
// return initialState
}
return reducer(state, action)
}
}
That's because I am using immutable values, which have to be revived like this: https://github.com/este/este/blob/master/src/common/todos/reducer.js#L16
Returning plain initialState simply doesn't work, since state must be revived immutable value.
Reducers shouldn't react to @@redux-recycle/INIT
anyway, so we can probably just do (as you proposed):
return reducer(initialState, { type: '@@redux-recycle/INIT' })
Would you mind doing a PR for this? ๐
Two OSS maintainers waiting for each other :-) Maybe next week ;)
@steida Haha, it's alright, I was gonna do it this weekend anyway ๐
I released 1.1.0
(as long as you don't parse @@redux-recycle/INIT
, which you really shouldn't, that update shouldn't break anything), can you check if it works now?
Yes, it works. Thank you!
You're welcome ๐