Created
August 30, 2016 18:44
-
-
Save piq9117/34c04472f0f9ee6ebd8cbe7b1e327671 to your computer and use it in GitHub Desktop.
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
// 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