forked from angular-redux/ng-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
144 lines (131 loc) · 5.04 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
144
import { Action, AnyAction, Store, Unsubscribe } from 'redux';
declare namespace ngRedux {
export type Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;
export interface Dispatch<A extends Action = AnyAction> {
<T extends A>(action: T): T;
}
export interface MiddlewareArg<D extends Dispatch = Dispatch, S = any> {
dispatch: D;
getState(): S;
}
export interface Middleware<DispatchExt = {}, S = any, D extends Dispatch = Dispatch> {
(api: MiddlewareArg<D, S>): (next: Dispatch<AnyAction>) => (action: any) => any;
}
/* config */
export interface Config {
debounce: DebounceConfig;
}
export interface DebounceConfig {
wait?: number;
maxWait?: number;
}
/* API */
export interface INgRedux {
/**
* Replaces the reducer currently used by the store to calculate the state.
*
* You might need this if your app implements code splitting and you want to
* load some of the reducers dynamically. You might also need this if you
* implement a hot reloading mechanism for Redux.
*
* @param nextReducer The reducer for the store to use instead.
*/
replaceReducer(nextReducer: Reducer): void;
/**
* A *dispatching function* (or simply *dispatch function*) is a function that
* accepts an action or an async action; it then may or may not dispatch one
* or more actions to the store.
*
* We must distinguish between dispatching functions in general and the base
* `dispatch` function provided by the store instance without any middleware.
*
* The base dispatch function *always* synchronously sends an action to the
* store's reducer, along with the previous state returned by the store, to
* calculate a new state. It expects actions to be plain objects ready to be
* consumed by the reducer.
*
* Middleware wraps the base dispatch function. It allows the dispatch
* function to handle async actions in addition to actions. Middleware may
* transform, delay, ignore, or otherwise interpret actions or async actions
* before passing them to the next middleware.
*
* @template A The type of things (actions or otherwise) which may be
* dispatched.
*/
dispatch<A extends Action>(action: A): A;
/**
* Reads the state tree managed by the store.
*
* @returns The current state tree of your application.
*/
getState<S = any>(): S;
/**
* Adds a change listener. It will be called any time an action is
* dispatched, and some part of the state tree may potentially have changed.
* You may then call `getState()` to read the current state tree inside the
* callback.
*
* You may call `dispatch()` from a change listener, with the following
* caveats:
*
* 1. The subscriptions are snapshotted just before every `dispatch()` call.
* If you subscribe or unsubscribe while the listeners are being invoked,
* this will not have any effect on the `dispatch()` that is currently in
* progress. However, the next `dispatch()` call, whether nested or not,
* will use a more recent snapshot of the subscription list.
*
* 2. The listener should not expect to see all states changes, as the state
* might have been updated multiple times during a nested `dispatch()` before
* the listener is called. It is, however, guaranteed that all subscribers
* registered before the `dispatch()` started will be called with the latest
* state by the time it exits.
*
* @param listener A callback to be invoked on every dispatch.
* @returns A function to remove this change listener.
*/
subscribe(listener: () => void): Unsubscribe;
/**
* Connects a component to a Redux store.
*
* @param mapStateToTarget
* @param mapDispatchToTarget
*/
connect(
mapStateToTarget: null | ((state: any) => { [key: string]: any; }),
mapDispatchToTarget?: object | ((dispatch: Function) => object)
): (target: Function | object) => Unsubscribe;
}
/* provider */
export interface INgReduxProvider {
/**
* callback for creating Redux store.
*
* @param storeCreator
*/
createStore<S = any>(storeCreator: (middlewares?: (Middleware | string)[], storeEnhancers?: Function[]) => Store<S>): void;
/**
* Creates Redux store.
*
* @param reducer
* @param middlewares
* @param storeEnhancers
* @param initialState
*/
createStoreWith<S = any, I = any>(reducer: Reducer<S>, middlewares?: (Middleware | string)[], storeEnhancers?: Function[], initialState?: I): void;
/**
* Initializes ngRedux with an existing Redux store.
*
* @param store
* @param middlewares
* @param storeEnhancers
*/
provideStore<S = any>(store: Store<S>, middlewares?: (Middleware | string)[], storeEnhancers?: Function[]): void;
/**
* ngRedux config object
*/
config: Config;
}
}
declare var ngRedux: string;
export as namespace ngRedux;
export default ngRedux;