Last active
January 5, 2018 16:30
-
-
Save axelnormand/ec5c68b6366e07bd9193b75781ba43d1 to your computer and use it in GitHub Desktop.
Select util function for redux - saves milliseconds in your typing :)
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
// @flow | |
export const select = (selectors: Object) => (state: Object): Object => { | |
const keys = Object.keys(selectors); | |
const ret = {}; | |
keys.forEach(key => { | |
if (!selectors[key]){ | |
throw new Error( | |
` | |
Could not find key '${key}' in selectors. | |
Perhaps you the selector doesn't exist or is misspelt? | |
Or maybe imported selector in component is misspelt? | |
`, | |
); | |
} | |
ret[key] = selectors[key](state); | |
}); | |
return ret; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment