model.ts 1.01 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import { AnyAction, Reducer } from 'redux';
2

陈帅's avatar
陈帅 committed
3
import { EffectsCommandMap } from 'dva';
陈帅's avatar
陈帅 committed
4
import { AdvancedProfileData } from './data';
陈帅's avatar
陈帅 committed
5
import { queryAdvancedProfile } from './service';
陈帅's avatar
陈帅 committed
6 7 8

export type Effect = (
  action: AnyAction,
陈帅's avatar
陈帅 committed
9
  effects: EffectsCommandMap & { select: <T>(func: (state: AdvancedProfileData) => T) => T },
陈帅's avatar
陈帅 committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
) => void;

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

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

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

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

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

export default Model;