list.js 848 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
import { queryFakeList } from '../services/api';

export default {
  namespace: 'list',

  state: {
    list: [],
  },

  effects: {
afc163's avatar
afc163 committed
11
    *fetch({ payload }, { call, put }) {
12 13 14 15 16 17 18
      const response = yield call(queryFakeList, payload);
      yield put({
        type: 'queryList',
        payload: Array.isArray(response) ? response : [],
      });
    },
    *appendFetch({ payload }, { call, put }) {
19 20
      const response = yield call(queryFakeList, payload);
      yield put({
afc163's avatar
afc163 committed
21
        type: 'appendList',
afc163's avatar
afc163 committed
22
        payload: Array.isArray(response) ? response : [],
23 24 25 26 27
      });
    },
  },

  reducers: {
28 29 30 31 32 33
    queryList(state, action) {
      return {
        ...state,
        list: action.payload,
      };
    },
afc163's avatar
afc163 committed
34
    appendList(state, action) {
35 36
      return {
        ...state,
afc163's avatar
afc163 committed
37
        list: state.list.concat(action.payload),
38 39 40 41
      };
    },
  },
};