-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error on undefined value from reducer function
- Loading branch information
taylorhakes
committed
Jul 8, 2015
1 parent
069d641
commit b8e7e1e
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import mapValues from '../utils/mapValues'; | ||
import pick from '../utils/pick'; | ||
import invariant from 'invariant'; | ||
|
||
export default function composeReducers(reducers) { | ||
const finalReducers = pick(reducers, (val) => typeof val === 'function'); | ||
|
||
return function composition(state = {}, action) { | ||
return mapValues(finalReducers, (store, key) => | ||
store(state[key], action) | ||
); | ||
return mapValues(finalReducers, (reducer, key) => { | ||
const newState = reducer(state[key], action); | ||
invariant( | ||
typeof newState !== 'undefined', | ||
`Reducer ${key} returns undefined. By default reducer should return original state.` | ||
); | ||
return newState; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters