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

Warn when reducer is not a function #3026

Conversation

baibhavx
Copy link

@baibhavx baibhavx commented Jun 15, 2018

const rootReducer = combineReducers({ 
  todos: todosReducer, 
  steps: {} // no warning, this is simply ignored 
})
  • If the object supplied to combineReducers has a key whose value is not a function, it simply ignores it. With this fix, it gives a warning, letting the user know that each key in the object must point to a function.

Copy link
Member

@timdorr timdorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs at least one test case to go with the change.

@baibhavx baibhavx force-pushed the feature/combine-reducer-warns-unless-reducer-is-function branch 4 times, most recently from 4b6047c to 4e31693 Compare June 15, 2018 18:37
@baibhavx
Copy link
Author

npm_ci_fail

@timdorr I added the tests to my commit but the build fails at `npm ci` with `zlib: unexpected end of file` and I have no idea why that is happening. If possible, please suggest how to make this pass. Thanks!

@@ -121,6 +121,8 @@ export default function combineReducers(reducers) {
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
warning(`No reducer provided for key "${key}"`)
} else if (typeof reducers[key] !== 'function') {
warning(`"${key}" is not a function`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably be confusing by itself. I'd add more context to the message: The reducer for "${key}" is not a function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I've updated the error message to The reducer for "${key}" is not a function format.

@timdorr
Copy link
Member

timdorr commented Jun 15, 2018

Yeah, something is up with Travis. Not your fault, though! I'll see if I can figure it out...

@baibhavx baibhavx force-pushed the feature/combine-reducer-warns-unless-reducer-is-function branch from 4e31693 to a410afd Compare June 15, 2018 19:50
@timdorr timdorr closed this Jun 16, 2018
@baibhavx baibhavx deleted the feature/combine-reducer-warns-unless-reducer-is-function branch June 16, 2018 21:17
@baibhavx baibhavx restored the feature/combine-reducer-warns-unless-reducer-is-function branch June 16, 2018 21:17
@baibhavx baibhavx deleted the feature/combine-reducer-warns-unless-reducer-is-function branch June 16, 2018 21:17
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

Successfully merging this pull request may close these issues.

2 participants