model.ts 1.03 KB
Newer Older
1
import { queryAdvancedProfile } from './service';
陈帅's avatar
陈帅 committed
2 3 4
import { Reducer } from 'redux';
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
5

陈帅's avatar
陈帅 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import { AdvancedProfileData } from './data';

export type Effect = (
  action: AnyAction,
  effects: EffectsCommandMap & { select: <T>(func: (state: AdvancedProfileData) => T) => T }
) => void;

export interface ModelType {
  namespace: string;
  state: AdvancedProfileData;
  effects: {
    fetchAdvanced: Effect;
  };
  reducers: {
    show: Reducer<AdvancedProfileData>;
  };
}

const Model: ModelType = {
25
  namespace: 'BLOCK_NAME_CAMEL_CASE',
26 27

  state: {
ddcat1115's avatar
ddcat1115 committed
28 29 30
    advancedOperation1: [],
    advancedOperation2: [],
    advancedOperation3: [],
31 32 33
  },

  effects: {
afc163's avatar
afc163 committed
34
    *fetchAdvanced(_, { call, put }) {
ddcat1115's avatar
ddcat1115 committed
35 36 37 38 39
      const response = yield call(queryAdvancedProfile);
      yield put({
        type: 'show',
        payload: response,
      });
40 41 42 43 44 45 46 47 48 49 50 51
    },
  },

  reducers: {
    show(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
陈帅's avatar
陈帅 committed
52 53

export default Model;