import { Reducer, Action, ReducersMapObject, Dispatch, MiddlewareAPI, StoreEnhancer, } from 'redux'; import {History} from 'history'; export interface onActionFunc { (api: MiddlewareAPI): void; } export interface ReducerEnhancer { (reducer: Reducer): void; } export interface Hooks { onError?: (e: Error, dispatch: Dispatch) => void; onAction?: onActionFunc | onActionFunc[]; onStateChange?: () => void; onReducer?: ReducerEnhancer; onEffect?: () => void; onHmr?: () => void; extraReducers?: ReducersMapObject; extraEnhancers?: StoreEnhancer[]; fetchConfig?: any; } export type DvaOption = Hooks & { initialState?: Object; history?: Object; }; export interface EffectsCommandMap { put: (action: A) => any; call: Function; select: Function; take: Function; cancel: Function; [key: string]: any; } export type Effect = (action: Action, effects: EffectsCommandMap) => void; export type EffectType = 'takeEvery' | 'takeLatest' | 'watcher' | 'throttle'; export type EffectWithType = [Effect, {type: EffectType}]; export type Subscription = (api: SubscriptionAPI, done: Function) => void; export type ReducersMapObjectWithEnhancer = [ ReducersMapObject, ReducerEnhancer ]; export interface EffectsMapObject { [key: string]: Effect | EffectWithType; } export interface SubscriptionAPI { history: History; dispatch: Dispatch; } export interface SubscriptionsMapObject { [key: string]: Subscription; } export interface Model { namespace: string; state?: any; reducers?: ReducersMapObject | ReducersMapObjectWithEnhancer; effects?: EffectsMapObject; subscriptions?: SubscriptionsMapObject; } export interface RouterAPI { history: History; app: DvaInstance; } export interface Router { (api?: RouterAPI): JSX.Element | Object; } export interface DvaInstance { /** * Register an object of hooks on the application. * * @param hooks */ use: (hooks: Hooks) => void; /** * Register a model. * * @param model */ model: (model: Model) => void; /** * Unregister a model. * * @param namespace */ unmodel: (namespace: string) => void; /** * Config router. Takes a function with arguments { history, dispatch }, * and expects router config. It use the same api as react-router, * return jsx elements or JavaScript Object for dynamic routing. * * @param router */ router: (router: Router) => void; /** * Start the application. Selector is optional. If no selector * arguments, it will return a function that return JSX elements. * * @param selector */ start: (selector?: HTMLElement | string) => any; } export default function dva(opts?: DvaOption): DvaInstance; /** * Connects a React component to Dva. */ export function connect( mapStateToProps?: Function, mapDispatchToProps?: Function, mergeProps?: Function, options?: Object ): Function;