Last active
August 30, 2016 04:51
-
-
Save piq9117/64ccc28ab9971cfaf7c4a0102375e72b 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
function addFood (state, action) { | |
// favoriteFood :: {k: v} -> {k: v} | |
const favoriteFood = favorite => Object.assign({}, {favoriteFood: []}, favorite) | |
// food :: {k: v} -> {k: v} | |
const food = favoriteFood( | |
Object.assign({}, state[action.data.id], { | |
[action.data.prop]: state[action.data.id].favoriteFood.concat(action.data.food) | |
}) | |
) | |
// assocPath :: [String] -> {k: v} -> {k: v} -> {k: v} | |
return R.assocPath([action.data.id])(food)(state) | |
} | |
export default function reducer (state = people, action) { | |
switch (action.type) { | |
case 'ADD_FOOD': | |
return addFood(state, action) | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment