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

Be less opinionated in combineReducers #715

Closed
ashaffer opened this issue Sep 13, 2015 · 6 comments
Closed

Be less opinionated in combineReducers #715

ashaffer opened this issue Sep 13, 2015 · 6 comments

Comments

@ashaffer
Copy link
Contributor

I know I can just make my own, and I will do that for now, but it seems like combineReducers should not be quite so opinionated about the state shape. For instance, in my app, I want to do something like this:

reduceReducers(
  handleActions(someGlobalActions),
  combineReducers({
    entities,
    collections: combineReducers({
      explore,
      following
    })
  })
})

But this does not work in a very non-obvious way. It doesn't work because combineReducers will drop any keys that are not in the state shape passed to it, so all of the things done in my global actions will not be recorded.

@gaearon
Copy link
Contributor

gaearon commented Sep 13, 2015

If we allow (and pass through) arbitrary keys, we wouldn't be able to guard against a very common beginner mistake when the shape of the initial state doesn't match the reducer shape. Utilities that ship with Redux just illustrate patterns and provide guidance to beginners. It's indeed often better to write your own when you know what you need. In this case, I believe your pattern of usage deviates from the simple case combineReducers() was designed for.

Still, I agree silently omitting keys isn't nice. We should at least warn this is happening. There is code for this, but it only executes once—perhaps we should always run it? (In development only, of course.)

@gaearon
Copy link
Contributor

gaearon commented Sep 13, 2015

cc @ellbee

@ellbee
Copy link
Contributor

ellbee commented Sep 13, 2015

I agree that silently omitting the keys isn't nice. The state shape check is only executed once because it felt unnecessary to be calling it every time. I don't think calling it every time would have any bad side effects and it would warn for cases like this.

@gaearon
Copy link
Contributor

gaearon commented Sep 13, 2015

I'm happy to accept a pull request amending this, given that the warning wording makes sense in both situations.

@gaearon
Copy link
Contributor

gaearon commented Sep 14, 2015

Fixed by #720, will be released in the next minor release.

@gaearon gaearon closed this as completed Sep 14, 2015
@gaearon
Copy link
Contributor

gaearon commented Sep 25, 2015

The new warning is out in 3.0.1.
Please verify!

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

No branches or pull requests

3 participants