Skip to content

Instantly share code, notes, and snippets.

@piq9117
Created August 30, 2016 18:44
Show Gist options
  • Save piq9117/34c04472f0f9ee6ebd8cbe7b1e327671 to your computer and use it in GitHub Desktop.
Save piq9117/34c04472f0f9ee6ebd8cbe7b1e327671 to your computer and use it in GitHub Desktop.
// addProps :: {k: v} -> {k: v}
const addProps = props => Object.assign({}, {iceCreamFlavor: '', favoriteFood: []}, props)
function iceCreamFlavor (state, action) {
// flavor :: Flavor
const flavor = addProps(Object.assign({}, state[action.data.id], {
[action.data.prop]: action.data.flavor
}))
return R.assocPath([action.data.id])(flavor)(state)
}
/*
The action to add the icecream flavor looks like this:
const action = {
type: 'ICE_CREAM_FLAVOR',
data: {
id: 'developer2',
prop: 'iceCreamFlavor',
flavor: 'wasabi'
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment