connect.d.ts 1.35 KB
Newer Older
何乐's avatar
何乐 committed
1 2
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
何乐's avatar
何乐 committed
3
import { RouterTypes } from 'umi';
何乐's avatar
何乐 committed
4 5 6
import { GlobalModelState } from './global';
import { UserModelState } from './user';
import { DefaultSettings as SettingModelState } from '../../config/defaultSettings';
陈帅's avatar
陈帅 committed
7
import { MenuDataItem } from '@ant-design/pro-layout';
陈帅's avatar
陈帅 committed
8
export { GlobalModelState, SettingModelState, UserModelState };
何乐's avatar
何乐 committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

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

/**
 * @type P: Type of payload
 * @type C: Type of callback
 */
export type Dispatch = <P = any, C = (payload: P) => void>(action: {
  type: string;
  payload?: P;
  callback?: C;
  [key: string]: any;
}) => any;

export interface Loading {
  global: boolean;
  effects: { [key: string]: boolean | undefined };
  models: {
    global?: boolean;
    menu?: boolean;
    setting?: boolean;
    user?: boolean;
  };
}

export interface ConnectState {
  global: GlobalModelState;
  loading: Loading;
陈帅's avatar
陈帅 committed
40
  settings: SettingModelState;
何乐's avatar
何乐 committed
41 42 43
  user: UserModelState;
}

陈帅's avatar
陈帅 committed
44 45 46 47
export interface Route extends MenuDataItem {
  routes?: Route[];
}

何乐's avatar
何乐 committed
48 49 50
/**
 * @type T: Params matched in dynamic routing
 */
何乐's avatar
何乐 committed
51 52
export interface ConnectProps<T extends { [key: string]: any } = {}>
  extends Partial<RouterTypes<Route>> {
何乐's avatar
何乐 committed
53 54 55 56
  dispatch?: Dispatch;
}

export default ConnectState;