Skip to content

Instantly share code, notes, and snippets.

@clucasalcantara
Last active October 13, 2018 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clucasalcantara/229aa5153b8aa6c8ac0893ac4582d794 to your computer and use it in GitHub Desktop.
Save clucasalcantara/229aa5153b8aa6c8ac0893ac4582d794 to your computer and use it in GitHub Desktop.
Cart Reducer
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