goodsReducer.js 997 B

123456789101112131415161718192021
  1. import { gqlGoodFind, gqlGoodFindOne, gqlGoodsCount } from '../gql/gqlGoods';
  2. import { createPromiseReducerSlice, actionPromiseGeneric } from './promiseReducer';
  3. const currentGood = 'currentGood';
  4. const actionGoodFindOne = (id) =>
  5. actionPromiseGoods(currentGood, gqlGoodFindOne(id));
  6. const getCurrentGood = state => (
  7. state.goods[currentGood]?.payload
  8. )
  9. const actionGoodFind = (fromPage = 0, pageSize = undefined, searchStr = null, queryExt = {}) =>
  10. actionPromiseGoods('goods', gqlGoodFind(fromPage, pageSize, searchStr, queryExt));
  11. const actionGoodsCount = (searchStr = null, queryExt = {}) =>
  12. actionPromiseGoods('goodsCount', gqlGoodsCount(searchStr, queryExt));
  13. const goodsReducerSlice = createPromiseReducerSlice('goods');
  14. const actionPromiseGoods = (name, promise) =>
  15. actionPromiseGeneric(goodsReducerSlice, name, promise);
  16. let goodsReducer = goodsReducerSlice.reducer;
  17. export { goodsReducer, actionGoodFindOne, actionGoodFind, actionGoodsCount, getCurrentGood }