1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export as namespace ReduxActions;
|
13 |
|
14 |
|
15 |
|
16 | export interface BaseAction {
|
17 | type: string;
|
18 | }
|
19 |
|
20 | export interface Action<Payload> extends BaseAction {
|
21 | payload: Payload;
|
22 | error?: boolean | undefined;
|
23 | }
|
24 |
|
25 | export interface ActionMeta<Payload, Meta> extends Action<Payload> {
|
26 | meta: Meta;
|
27 | }
|
28 |
|
29 |
|
30 | export interface CombinedActionType {
|
31 | _dummy: undefined;
|
32 | }
|
33 |
|
34 | export type ReducerMapValue<State, Payload> = Reducer<State, Payload> | ReducerNextThrow<State, Payload> | ReducerMap<State, Payload>;
|
35 |
|
36 | export interface ReducerMap<State, Payload> {
|
37 | [actionType: string]: ReducerMapValue<State, Payload>;
|
38 | }
|
39 |
|
40 | export interface ReducerMapMeta<State, Payload, Meta> {
|
41 | [actionType: string]: ReducerMeta<State, Payload, Meta> | ReducerNextThrowMeta<State, Payload, Meta> | ReducerMapMeta<State, Payload, Meta>;
|
42 | }
|
43 |
|
44 | export interface ReducerNextThrow<State, Payload> {
|
45 | next?(state: State, action: Action<Payload>): State;
|
46 | throw?(state: State, action: Action<Payload>): State;
|
47 | }
|
48 |
|
49 | export interface ReducerNextThrowMeta<State, Payload, Meta> {
|
50 | next?(state: State, action: ActionMeta<Payload, Meta>): State;
|
51 | throw?(state: State, action: ActionMeta<Payload, Meta>): State;
|
52 | }
|
53 |
|
54 | export type BaseActionFunctions<TAction> =
|
55 | ActionFunction0<TAction> |
|
56 | ActionFunction1<any, TAction> |
|
57 | ActionFunction2<any, any, TAction> |
|
58 | ActionFunction3<any, any, any, TAction> |
|
59 | ActionFunction4<any, any, any, any, TAction> |
|
60 | ActionFunctionAny<TAction>;
|
61 |
|
62 | export type ActionFunctions<Payload> = BaseActionFunctions<Action<Payload>>;
|
63 |
|
64 | export type ActionWithMetaFunctions<Payload, Meta> = BaseActionFunctions<ActionMeta<Payload, Meta>>;
|
65 |
|
66 | export type Reducer<State, Payload> = (state: State, action: Action<Payload>) => State;
|
67 |
|
68 | export type ReducerMeta<State, Payload, Meta> = (state: State, action: ActionMeta<Payload, Meta>) => State;
|
69 |
|
70 | export type ReduxCompatibleReducer<State, Payload> = (state: State | undefined, action: Action<Payload>) => State;
|
71 |
|
72 | export type ReduxCompatibleReducerMeta<State, Payload, Meta> = (state: State | undefined, action: ActionMeta<Payload, Meta>) => State;
|
73 |
|
74 |
|
75 | export type ActionFunction0<R> = () => R;
|
76 | export type ActionFunction1<T1, R> = (t1: T1) => R;
|
77 | export type ActionFunction2<T1, T2, R> = (t1: T1, t2: T2) => R;
|
78 | export type ActionFunction3<T1, T2, T3, R> = (t1: T1, t2: T2, t3: T3) => R;
|
79 | export type ActionFunction4<T1, T2, T3, T4, R> = (t1: T1, t2: T2, t3: T3, t4: T4) => R;
|
80 | export type ActionFunctionAny<R> = (...args: any[]) => R;
|
81 |
|
82 |
|
83 | export function createAction(
|
84 | actionType: string
|
85 | ): ActionFunctionAny<Action<any>>;
|
86 |
|
87 | export function createAction<Payload>(
|
88 | actionType: string,
|
89 | payloadCreator: ActionFunction0<Payload>
|
90 | ): ActionFunction0<Action<Payload>>;
|
91 |
|
92 | export function createAction<Payload, Arg1>(
|
93 | actionType: string,
|
94 | payloadCreator: ActionFunction1<Arg1, Payload>
|
95 | ): ActionFunction1<Arg1, Action<Payload>>;
|
96 |
|
97 | export function createAction<Payload, Arg1, Arg2>(
|
98 | actionType: string,
|
99 | payloadCreator: ActionFunction2<Arg1, Arg2, Payload>
|
100 | ): ActionFunction2<Arg1, Arg2, Action<Payload>>;
|
101 |
|
102 | export function createAction<Payload, Arg1, Arg2, Arg3>(
|
103 | actionType: string,
|
104 | payloadCreator: ActionFunction3<Arg1, Arg2, Arg3, Payload>
|
105 | ): ActionFunction3<Arg1, Arg2, Arg3, Action<Payload>>;
|
106 |
|
107 | export function createAction<Payload, Arg1, Arg2, Arg3, Arg4>(
|
108 | actionType: string,
|
109 | payloadCreator: ActionFunction4<Arg1, Arg2, Arg3, Arg4, Payload>
|
110 | ): ActionFunction4<Arg1, Arg2, Arg3, Arg4, Action<Payload>>;
|
111 |
|
112 | export function createAction<Payload>(
|
113 | actionType: string
|
114 | ): ActionFunction1<Payload, Action<Payload>>;
|
115 |
|
116 | export function createAction<Meta>(
|
117 | actionType: string,
|
118 | payloadCreator: null | undefined,
|
119 | metaCreator: ActionFunctionAny<Meta>
|
120 | ): ActionFunctionAny<ActionMeta<any, Meta>>;
|
121 |
|
122 | export function createAction<Payload, Meta>(
|
123 | actionType: string,
|
124 | payloadCreator: ActionFunctionAny<Payload>,
|
125 | metaCreator: ActionFunctionAny<Meta>
|
126 | ): ActionFunctionAny<ActionMeta<Payload, Meta>>;
|
127 |
|
128 | export function createAction<Payload, Meta, Arg1>(
|
129 | actionType: string,
|
130 | payloadCreator: ActionFunction1<Arg1, Payload>,
|
131 | metaCreator: ActionFunction1<Arg1, Meta>
|
132 | ): ActionFunction1<Arg1, ActionMeta<Payload, Meta>>;
|
133 |
|
134 | export function createAction<Payload, Meta, Arg1, Arg2>(
|
135 | actionType: string,
|
136 | payloadCreator: ActionFunction2<Arg1, Arg2, Payload>,
|
137 | metaCreator: ActionFunction2<Arg1, Arg2, Meta>
|
138 | ): ActionFunction2<Arg1, Arg2, ActionMeta<Payload, Meta>>;
|
139 |
|
140 | export function createAction<Payload, Meta, Arg1, Arg2, Arg3>(
|
141 | actionType: string,
|
142 | payloadCreator: ActionFunction3<Arg1, Arg2, Arg3, Payload>,
|
143 | metaCreator: ActionFunction3<Arg1, Arg2, Arg3, Meta>
|
144 | ): ActionFunction3<Arg1, Arg2, Arg3, ActionMeta<Payload, Meta>>;
|
145 |
|
146 | export function createAction<Payload, Meta, Arg1, Arg2, Arg3, Arg4>(
|
147 | actionType: string,
|
148 | payloadCreator: ActionFunction4<Arg1, Arg2, Arg3, Arg4, Payload>,
|
149 | metaCreator: ActionFunction4<Arg1, Arg2, Arg3, Arg4, Meta>
|
150 | ): ActionFunction4<Arg1, Arg2, Arg3, Arg4, ActionMeta<Payload, Meta>>;
|
151 |
|
152 | export function handleAction<State, Payload>(
|
153 | actionType: string | ActionFunctions<Payload> | CombinedActionType,
|
154 | reducer: Reducer<State, Payload> | ReducerNextThrow<State, Payload>,
|
155 | initialState: State
|
156 | ): ReduxCompatibleReducer<State, Payload>;
|
157 |
|
158 | export function handleAction<State, Payload, Meta>(
|
159 | actionType: string | ActionWithMetaFunctions<Payload, Meta> | CombinedActionType,
|
160 | reducer: ReducerMeta<State, Payload, Meta> | ReducerNextThrowMeta<State, Payload, Meta>,
|
161 | initialState: State
|
162 | ): ReduxCompatibleReducerMeta<State, Payload, Meta>;
|
163 |
|
164 | export interface Options {
|
165 | prefix?: string | undefined;
|
166 | namespace?: string | undefined;
|
167 | }
|
168 |
|
169 | export function handleActions<StateAndPayload>(
|
170 | reducerMap: ReducerMap<StateAndPayload, StateAndPayload>,
|
171 | initialState: StateAndPayload,
|
172 | options?: Options
|
173 | ): ReduxCompatibleReducer<StateAndPayload, StateAndPayload>;
|
174 |
|
175 | export function handleActions<State, Payload>(
|
176 | reducerMap: ReducerMap<State, Payload>,
|
177 | initialState: State,
|
178 | options?: Options
|
179 | ): ReduxCompatibleReducer<State, Payload>;
|
180 |
|
181 | export function handleActions<State, Payload, Meta>(
|
182 | reducerMap: ReducerMapMeta<State, Payload, Meta>,
|
183 | initialState: State,
|
184 | options?: Options
|
185 | ): ReduxCompatibleReducerMeta<State, Payload, Meta>;
|
186 |
|
187 |
|
188 | export function combineActions(...actionTypes: Array<ActionFunctions<any> | string | symbol>): CombinedActionType;
|
189 |
|
190 | export interface ActionMap<Payload, Meta> {
|
191 | [actionType: string]:
|
192 | ActionMap<Payload, Meta> |
|
193 | ActionFunctionAny<Payload> |
|
194 | [ActionFunctionAny<Payload>, ActionFunctionAny<Meta>] |
|
195 | undefined;
|
196 | }
|
197 |
|
198 | export function createActions<Payload>(
|
199 | actionMapOrIdentityAction: ActionMap<Payload, any> | string,
|
200 | ...identityActions: Array<string | Options>
|
201 | ): {
|
202 | [actionName: string]: ActionFunctionAny<Action<Payload>>
|
203 | };
|
204 |
|
205 | export function createActions(
|
206 | actionMapOrIdentityAction: ActionMap<any, any> | string,
|
207 | ...identityActions: Array<string | Options>
|
208 | ): {
|
209 | [actionName: string]: ActionFunctionAny<Action<any>>
|
210 | };
|