connect.d.ts 1.33 KB
Newer Older
何乐's avatar
何乐 committed
1
import { AnyAction } from 'redux';
陈帅's avatar
陈帅 committed
2 3
import { EffectsCommandMap } from 'dva';
import { MenuDataItem } from '@ant-design/pro-layout';
何乐's avatar
何乐 committed
4
import { RouterTypes } from 'umi';
何乐's avatar
何乐 committed
5 6
import { GlobalModelState } from './global';
import { DefaultSettings as SettingModelState } from '../../config/defaultSettings';
陈帅's avatar
陈帅 committed
7
import { UserModelState } from './user';
何乐's avatar
何乐 committed
8

陈帅's avatar
陈帅 committed
9
export { GlobalModelState, SettingModelState, UserModelState };
何乐's avatar
何乐 committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

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
25
  settings: SettingModelState;
何乐's avatar
何乐 committed
26 27 28
  user: UserModelState;
}

陈帅's avatar
陈帅 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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;

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

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