Last active
October 13, 2018 06:16
-
-
Save clucasalcantara/229aa5153b8aa6c8ac0893ac4582d794 to your computer and use it in GitHub Desktop.
Cart Reducer
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
const actionTypes { | |
SHOW_ALL: 'CART/SHOW_ALL', | |
ADD_PRODUCT: 'CART/ADD_PRODUCT', | |
REMOVE_PRODUCT: 'CART/REMOVE_PRODUCT', | |
} | |
const cart = (state, action) => { | |
switch (action) { | |
case actionTypes.SHOW_ALL: | |
return state | |
case actionTypes.ADD_PRODUCT: | |
return { | |
...state, | |
...action.product | |
} | |
case actionTypes.REMOVE_PRODUCT: | |
return state.filter(t.id => !action.product.id) | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment