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

Throw error on undefined value from reducer function #197

Merged

Conversation

taylorhakes
Copy link
Contributor

Accidentally created against alpha before. Sorry about that.

Updated composeReducers to throw error when reducer returns undefined. Update to #193. #191

@taylorhakes
Copy link
Contributor Author

@gaearon Is this good to merge?

@gaearon
Copy link
Contributor

gaearon commented Jul 6, 2015

Yeah, can you please rebase so it merges cleanly?

@taylorhakes
Copy link
Contributor Author

Just did the rebase. The tests pass locally, but are failing in Travis. Have you seen this before?

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2015

Something to do with linting. I'll merge soon, thanks.

@acdlite
Copy link
Collaborator

acdlite commented Jul 7, 2015

Sorry for only now bringing this up, but I believe the check should go inside the Store class rather than composeReducers(). That way it works for all reducers, not just those created by that function. Also, we use the invariant module for consistency, like @gaearon does here: https://github.com/gaearon/redux/blob/breaking-changes-1.0/src/Store.js#L26-L29

@acdlite
Copy link
Collaborator

acdlite commented Jul 7, 2015

^ In fact the new invariant should go just a few lines below the highlighted portion

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2015

Sorry for only now bringing this up, but I believe the check should go inside the Store class rather than composeReducers().

But then we'll check the root value (which is unlikely to be undefined if you use composeReducers).

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2015

I think we're actually doing the right thing here. First, we want to check the actual app's reducers—not the root one. Second, we don't want this to be a hard limitation—just something the default utilities help you with. You're free to use your own composeReducers that allows undefined for individual reducers, or even not use composeReducers at all.

@acdlite
Copy link
Collaborator

acdlite commented Jul 7, 2015

@gaearon Ah I see. It should go in both places, then, right?

@acdlite
Copy link
Collaborator

acdlite commented Jul 7, 2015

Okay I can agree with that. That makes sense.

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2015

Why do that though? Redux doesn't really care what your root value is like. I'd say it should only be enforced at composeReducers level, as our built-in utilities follow “make it easier for a beginner” approach.

@acdlite
Copy link
Collaborator

acdlite commented Jul 7, 2015

Yep, agreed. Carry on :)

@taylorhakes
Copy link
Contributor Author

Updated code to use invariant

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2015

Can you please rebase on master again? I think the linting problem is fixed there by your earlier PR.

@@ -29,5 +29,28 @@ describe('Utils', () => {
Object.keys(reducer({}, { type: 'push' }))
).toEqual(['stack']);
});
it('should throw an error if undefined return from reducer', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing newline before it

@taylorhakes
Copy link
Contributor Author

I am a little confused. This change was made on top of breaking-changes-1.0. Do you want want me to merge master into breaking-changes-1.0? This change can't be rebased on master because it has to do with reducers.

@gaearon
Copy link
Contributor

gaearon commented Jul 8, 2015

Oh, I didn't mean on master, sorry :-(
I just updated breaking changes branch.

@gaearon gaearon merged commit b8e7e1e into reduxjs:breaking-changes-1.0 Jul 8, 2015
@gaearon
Copy link
Contributor

gaearon commented Jul 8, 2015

All right, this is in.
I slightly tweaked the tests and error messages: de685de.

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.

None yet

3 participants