index.js 658 B

1234567891011121314151617181920212223242526272829
  1. import { createReducer } from '@reduxjs/toolkit';
  2. import {
  3. actionGoodsSuccess,
  4. actionGoodsReject,
  5. actionGoodSuccess,
  6. actionGoodReject,
  7. } from '../action';
  8. const initialState = { goods: [], good: {} };
  9. const reducerGoods = createReducer(initialState, {
  10. [actionGoodsSuccess]: (state, { payload: goods }) => {
  11. const good = state.good;
  12. return { goods, good };
  13. },
  14. [actionGoodsReject]: (state, _) => {
  15. return state;
  16. },
  17. [actionGoodSuccess]: (state, { payload: good }) => {
  18. const goods = state.goods;
  19. return { goods, good };
  20. },
  21. [actionGoodReject]: (state, _) => {
  22. return state;
  23. },
  24. });
  25. export default reducerGoods;