-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
index.d.ts
143 lines (131 loc) 路 4.32 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Type definitions for dva 1.0.0
// Project: dva
// Definitions by: dva <https://github.com/dvajs/dva>
/*
* @refer https://github.com/reactjs/redux/blob/master/index.d.ts
* @template S State object type.
*/
export interface Action {
type: any;
}
export type Reducer<S> = <A extends Action>(state: S, action: A) => S;
export type Effect<S> = <A extends Action>(action: A, saga:{ call?:Function, put?:Function, select?:Function }) => S;
export type Subscription<Function> = <Function>(signature: {dispatch?:Function, history:Function})=>void;
interface Reducers {
Reducer: Reducer
}
interface Effects {
Effect: Effect
}
interface Subscriptions {
Subscription: Subscription
}
declare namespace 'dva' {
export default function dva(opts?:Object):{
/**
*
* Register an object of hooks on the application.
* Support these hooks:
* onError(fn): called when an effect or subscription emit an error
* onAction(array|fn): called when an action is dispatched, used for registering redux middleware, support Array for convenience
* onStateChange(fn): called after a reducer changes the state
* onReducer(fn): used for apply reducer enhancer
* onEffect(fn): used for wrapping effect to add custom behavior, e.g. dva-loading for automatical loading state
* onHmr(fn): used for hot module replacement
* extraReducers(object): used for adding extra reducers, e.g. redux-form needs extra form reducer
*
*/
use: (hooks:{
onError(fn:Function),
onAction(actions:Function | Array),
onStateChange(fn:Function),
onReducer(fn:Function),
onEffect(fn:Function),
onHmr(fn:Function),
extraReducers(reducer:Object)
})=>void,
/**
*
* Start the application. selector is optional. If no selector arguments, it will return a function that return JSX elements.
*
*/
start: (selector?:HTMLElement | String)=>void,
/*
*
* Create a new model. Takes the following arguments:
* namespace: namespace the model
* state: initial value
* reducers: synchronous operations that modify state. Triggered by actions. Signature of (state, action) => state, same as Redux.
* effects: asynchronous operations that don't modify state directly. Triggered by actions, can call actions. Signature of (action, { put, call, select }),
* subscriptions: asynchronous read-only operations that don't modify state directly. Can call actions. Signature of ({ dispatch, history }).
*
* put(action) in effects, and dispatch(action) in subscriptions
*
* Send a new action to the models. put in effects is the same as dispatch in subscriptions.
*
*/
model: (model:{
namespace: string,
state: any,
reducers?: Reducers,
effects?: Effects,
subscriptions?: Subscriptions,
})=>void,
/**
*
* Config router. Takes a function with arguments { history }, and expects router config. It use the same api as react-router, return jsx elements or JavaScript Object for dynamic routing.
*
*/
router: (router:JSX.Element|Function)=>JSX.Element,
};
/**
*
* To Connect Models on Components
*
* @refer
* https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options
*
*/
export function connect(mapStateToProps?:Object, mapDispatchToProps?:Object, mergeProps?:Object, options?:Object):Function;
}
/**
* https://github.com/reactjs/react-router
*/
declare module 'dva/router' {
import React = __React;
interface RouterProps {
history?: Object
}
export class Router extends React.Component<RouterProps, {}> {
render():JSX.Element
}
interface RouteProps {
path?: string,
component?: React.ReactNode
}
export class Route extends React.Component<RouteProps, {}> {
render():JSX.Element
}
/**
* https://github.com/reactjs/react-router-redux
*/
interface RouterRedux {
routerStateReducer: Function,
ReduxRouter: Function,
reduxReactRouter: Function,
isActive: Function,
historyAPI: Function,
push: Function,
replace: Function,
setState: Function,
go: Function,
goBack: Function,
goForward: Function,
}
}
/**
* https://github.com/fis-components/whatwg-fetch
*/
declare module 'dva/fetch' {
export default Function;
}