import { AnyAction , Reducer } from 'redux' ; import { EffectsCommandMap } from 'dva' ; import { AnalysisData } from '../data' ; import { fakeChartData } from '../service' ; export type Effect = ( action : AnyAction , effects : EffectsCommandMap & { select : < T > ( func : ( state : AnalysisData ) => T ) => T ; } ) => void ; export interface AnalysisType { namespace : String ; state : AnalysisData ; effects : { fetch : Effect ; fetchSalesData : Effect ; } ; reducers : { save : Reducer < AnalysisData > ; clear : Reducer < AnalysisData > ; } ; } const initState = { visitData : [ ] , visitData2 : [ ] , salesData : [ ] , searchData : [ ] , offlineData : [ ] , offlineChartData : [ ] , salesTypeData : [ ] , salesTypeDataOnline : [ ] , salesTypeDataOffline : [ ] , radarData : [ ] , } ; const Analysis = { namespace : 'analysis' , state : initState , 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 initState ; } , } , } ; export default Analysis ;