Skip to content
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

Initial state must be always passed to reducer #2

Closed
steida opened this issue Feb 19, 2016 · 5 comments
Closed

Initial state must be always passed to reducer #2

steida opened this issue Feb 19, 2016 · 5 comments

Comments

@steida
Copy link

steida commented Feb 19, 2016

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.

@omnidan
Copy link
Owner

omnidan commented Feb 19, 2016

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? 😄

@steida
Copy link
Author

steida commented Feb 19, 2016

Two OSS maintainers waiting for each other :-) Maybe next week ;)

@omnidan
Copy link
Owner

omnidan commented Feb 20, 2016

@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?

@steida
Copy link
Author

steida commented Feb 20, 2016

Yes, it works. Thank you!

@steida steida closed this as completed Feb 20, 2016
@omnidan
Copy link
Owner

omnidan commented Feb 20, 2016

You're welcome 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants