redux: Change composeStores to throw if undefined is returned

Right now it’s easy to forget a default case and have your reducer return nothing in some circumstances. There have been some WIP attempts to address it: #174. Here’s the issue that spawned that PR: #173.

But let’s take a moment to think about what composeStores really is. It’s a shortcut right? It’s a bit opinionated already: it assumes plain objects as the initial state. See #153.

Can we make it a bit more opinionated for convenience? We could make it return the previous state if the reducer returns undefined.

Edit: see this instead.

Pros:

  • Solves issues like #173 nicely
  • Slightly less boilerplate in the “vanilla Redux” code

Cons:

  • Dilutes the contract of reducers by introducing some magic

Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (18 by maintainers)

Most upvoted comments

Yes, I’m just checking for positive value !token, but it doesn’t matter. undefined is more native than false or even null. Furthermore, null is forbidden in my project.

I think null suits better in this case. undefined is absence of prove, and null is prove of absence.