Last active
August 24, 2016 14:37
-
-
Save HenrikJoreteg/5e84f0b9d709b0c93abf0a458cbf54d5 to your computer and use it in GitHub Desktop.
reducer pattern with blocks
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
import { DO_THING, DO_OTHER_THING, SOMETHING_ELSE } from './actions' | |
export default (state, { type, payload }) => { | |
switch (type) { | |
case DO_THING: { | |
// by using blocks in our case statements we can create locally scoped vars | |
// and returning early keeps things readable | |
const scopedVariable = payload.thing | |
return Object.assign({}, state, {do: scopedVariable}) | |
} | |
case DO_OTHER_THING: { | |
return Object.assign({}, state, {doOther: 'thing'}) | |
} | |
case SOMETHING_ELSE: { | |
return Object.assign({}, state, {something: 'else'}) | |
} | |
} | |
return state | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment