import { queryFakeList } from '../services/api'; export default { namespace: 'list', state: { list: [], loading: true, }, effects: { *fetch({ payload, callback }, { call, put }) { yield put({ type: 'changeLoading', payload: true, }); const response = yield call(queryFakeList, payload); yield put({ type: 'save', payload: Array.isArray(response) ? response : [], }); yield put({ type: 'changeLoading', payload: false, }); if (callback) { callback(); } }, }, reducers: { save(state, action) { return { ...state, list: action.payload, }; }, changeLoading(state, action) { return { ...state, loading: action.payload, }; }, }, };