-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
120 lines (102 loc) · 2.7 KB
/
index.d.ts
1
2
3
4
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import {
Reducer,
Action,
ReducersMapObject,
Dispatch,
MiddlewareAPI
} from 'redux';
export interface onActionFunc {
(api: MiddlewareAPI<any>): void;
}
export interface ReducerEnhancer {
(reducer: Reducer<any>): void
}
export interface Hooks {
onError?: (e: Error, dispatch: Dispatch<any>) => void;
onAction?: onActionFunc | onActionFunc[];
onStateChange?: () => void;
onReducer?: ReducerEnhancer;
onEffect?: () => void;
onHmr?: () => void;
extraReducers?: ReducersMapObject;
}
export type DvaOption = Hooks & {
initialState?: Object;
history?: Object;
}
export interface EffectsCommandMap {
put: <A extends Action>(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: HistoryModule.History;
dispatch: Dispatch<any>;
}
export interface SubscriptionsMapObject {
[key: string]: Subscription;
}
export interface Model {
namespace: string,
state?: any,
reducers?: ReducersMapObject | ReducersMapObjectWithEnhancer,
effects?: EffectsMapObject,
subscriptions?: SubscriptionsMapObject,
}
export interface RouterAPI {
history: HistoryModule.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,
/**
* 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;