import { fakeChartData } from './service'; import { IAnalysisData } from './data'; import { Reducer } from 'redux'; import { EffectsCommandMap } from 'dva'; import { AnyAction } from 'redux'; export type Effect = ( action: AnyAction, effects: EffectsCommandMap & { select: (func: (state: IAnalysisData) => T) => T }, ) => void; export interface ModelType { namespace: string; state: IAnalysisData; effects: { fetch: Effect; fetchSalesData: Effect; }; reducers: { save: Reducer; clear: Reducer; }; } const Model: ModelType = { namespace: 'analysis', state: { visitData: [], visitData2: [], salesData: [], searchData: [], offlineData: [], offlineChartData: [], salesTypeData: [], salesTypeDataOnline: [], salesTypeDataOffline: [], radarData: [], }, effects: { *fetch(_, { call, put }) { const response = yield call(fakeChartData); yield put({ type: 'save', payload: response, }); }, *fetchSalesData(_, { call, put }) { const response = yield call(fakeChartData); yield put({ type: 'save', payload: { salesData: response.salesData, }, }); }, }, reducers: { save(state, { payload }) { return { ...state, ...payload, }; }, clear() { return { visitData: [], visitData2: [], salesData: [], searchData: [], offlineData: [], offlineChartData: [], salesTypeData: [], salesTypeDataOnline: [], salesTypeDataOffline: [], radarData: [], }; }, }, }; export default Model;