-
-
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 store function
- Loading branch information
taylorhakes
committed
Jun 30, 2015
1 parent
34fe400
commit 0405d79
Showing
2 changed files
with
33 additions
and
5 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,11 +1,15 @@ | ||
import mapValues from '../utils/mapValues'; | ||
import pick from '../utils/pick'; | ||
import mapValues from './mapValues'; | ||
import pick from './pick'; | ||
|
||
export default function composeStores(stores) { | ||
const finalStores = pick(stores, (val) => typeof val === 'function'); | ||
return function Composition(atom = {}, action) { | ||
return mapValues(finalStores, (store, key) => | ||
store(atom[key], action) | ||
); | ||
return mapValues(finalStores, (store, key) => { | ||
const state = store(atom[key], action); | ||
if (state === undefined) { | ||
throw new Error(`Store ${key} returns undefined. By default should return original state.`); | ||
} | ||
return state; | ||
}); | ||
}; | ||
} |
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