Created
December 7, 2017 06:27
-
-
Save shivekkhurana/42491dca912b9388e90f92541caeee16 to your computer and use it in GitHub Desktop.
Automate writing redux reducers
This file contains hidden or 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
export default function keducer(prefix, actionMutationMap={}) { | |
return (state={}, action) => { | |
return actionMutationMap[action.type] ? | |
actionMutationMap[action.type](state, action.payload) : | |
action.type.indexOf(`${prefix}.`) === 0 ? {…state, …(action.payload)} : state | |
; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Phonetic : "Kay-Deu-Cer"
Allow for a map like declaration of reducers.
Copies entire payload if no action definition is present, or run the definition if it exists.
ex: