WishListReducer.js 804 B

123456789101112131415161718192021222324252627282930
  1. export const WishListReducer = (state = {}, { type, good = {}}) => {
  2. const { _id } = good
  3. const types = {
  4. WISHLIST_ADD() {
  5. return {
  6. ...state,
  7. [_id]: {
  8. good
  9. }
  10. }
  11. },
  12. WISHLIST_REMOVE() {
  13. let { [_id]: remove, ...newState } = state
  14. return {
  15. ...newState
  16. }
  17. },
  18. WISHLIST_CLEAR() {
  19. return {}
  20. },
  21. }
  22. if (type in types) {
  23. return types[type]()
  24. }
  25. return state
  26. }
  27. export const actionWishListAdd = (good) => ({type: "WISHLIST_ADD", good})
  28. export const actionWishListRemove = (good) => ({type: 'WISHLIST_REMOVE', good})
  29. export const actionWishListClear = () => ({type: 'WISHLIST_CLEAR'})