connect.d.ts 1.36 KB
Newer Older
何乐's avatar
何乐 committed
1
import { Route } from '@/components/SiderMenu';
何乐's avatar
何乐 committed
2 3
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
何乐's avatar
何乐 committed
4
import { RouterTypes } from 'umi';
何乐's avatar
何乐 committed
5 6 7 8 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 40 41 42 43 44 45 46 47 48 49
import { GlobalModelState } from './global';
import { MenuModelState } from './menu';
import { UserModelState } from './user';
import { DefaultSettings as SettingModelState } from '../../config/defaultSettings';

export { GlobalModelState, MenuModelState, SettingModelState, UserModelState };

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;
  menu: MenuModelState;
  setting: SettingModelState;
  user: UserModelState;
}

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

export default ConnectState;