state-decorator 7.3.0 → 7.3.1-destroy.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/development.d.ts +10 -10
- package/es/development.d.ts +10 -10
- package/es/graph.d.ts +8 -8
- package/es/helpers.d.ts +67 -67
- package/es/impl.d.ts +209 -208
- package/es/impl.js +1 -1
- package/es/index.d.ts +169 -169
- package/es/index.js +1 -1
- package/es/middlewares.d.ts +3 -3
- package/es/shallow.d.ts +1 -1
- package/es/test.d.ts +126 -122
- package/es/test.js +1 -1
- package/es/test.js.map +1 -1
- package/es/types.d.ts +386 -386
- package/es/v5.d.ts +45 -45
- package/es/v5_test.d.ts +57 -57
- package/es/v5_types.d.ts +213 -213
- package/es/v6.d.ts +21 -21
- package/graph.d.ts +8 -8
- package/helpers.d.ts +67 -67
- package/impl.d.ts +209 -208
- package/impl.js +1 -1
- package/index.d.ts +169 -169
- package/index.js +1 -1
- package/middlewares.d.ts +3 -3
- package/package.json +1 -1
- package/shallow.d.ts +1 -1
- package/test.d.ts +126 -122
- package/test.js +1 -1
- package/test.js.map +1 -1
- package/types.d.ts +386 -386
- package/v5.d.ts +45 -45
- package/v5_test.d.ts +57 -57
- package/v5_types.d.ts +213 -213
- package/v6.d.ts +21 -21
package/es/types.d.ts
CHANGED
|
@@ -1,386 +1,386 @@
|
|
|
1
|
-
export type PromiseResult<Type> = Type extends Promise<infer X> ? X : null;
|
|
2
|
-
export type NotifyFunc = (msg: string) => void;
|
|
3
|
-
export type PromiseIdMap = {
|
|
4
|
-
[promiseId: string]: boolean;
|
|
5
|
-
};
|
|
6
|
-
export type LoadingMap<A> = {
|
|
7
|
-
[pId in keyof A]?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export type LoadingParallelMap<A> = {
|
|
10
|
-
[P in keyof A]?: PromiseIdMap;
|
|
11
|
-
};
|
|
12
|
-
export type InternalLoadingMap<A> = LoadingParallelMap<A>;
|
|
13
|
-
export type LoadingProps<A> = {
|
|
14
|
-
loading: boolean;
|
|
15
|
-
loadingMap: LoadingMap<A>;
|
|
16
|
-
loadingParallelMap: LoadingParallelMap<A>;
|
|
17
|
-
};
|
|
18
|
-
export type LoadingMapProps<A> = Pick<LoadingProps<A>, 'loadingMap'>;
|
|
19
|
-
export type PromiseIdErrorMap = {
|
|
20
|
-
[promiseId: string]: Error;
|
|
21
|
-
};
|
|
22
|
-
export type ErrorMap<A> = {
|
|
23
|
-
[pId in keyof A]?: Error;
|
|
24
|
-
};
|
|
25
|
-
export type ErrorParallelMap<A> = {
|
|
26
|
-
[P in keyof A]?: PromiseIdErrorMap;
|
|
27
|
-
};
|
|
28
|
-
export type ErrorProps<A> = {
|
|
29
|
-
errorMap: ErrorMap<A>;
|
|
30
|
-
};
|
|
31
|
-
export interface DecoratedActions {
|
|
32
|
-
[name: string]: (...args: any[]) => Promise<any> | void;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The State decorator can manage only one asynchronous action of same name at a time.
|
|
36
|
-
* This enum is enumertaing all the policies in such case.
|
|
37
|
-
*/
|
|
38
|
-
export declare enum ConflictPolicy {
|
|
39
|
-
/**
|
|
40
|
-
* Reject the promise.
|
|
41
|
-
*/
|
|
42
|
-
REJECT = "reject",
|
|
43
|
-
/**
|
|
44
|
-
* Return a resolved promise with no result.
|
|
45
|
-
*/
|
|
46
|
-
IGNORE = "ignore",
|
|
47
|
-
/**
|
|
48
|
-
* Execute only the last call that conflicts after the one ongoing.
|
|
49
|
-
*/
|
|
50
|
-
KEEP_LAST = "keepLast",
|
|
51
|
-
/**
|
|
52
|
-
* Execute all calls one after another.
|
|
53
|
-
*/
|
|
54
|
-
KEEP_ALL = "keepAll",
|
|
55
|
-
/**
|
|
56
|
-
* Execute all calls one after another.
|
|
57
|
-
* @see getPromiseId
|
|
58
|
-
*/
|
|
59
|
-
PARALLEL = "parallel",
|
|
60
|
-
/**
|
|
61
|
-
* Reuse the ongoing promise if any and if possible (same arguments). Only for GET requests!
|
|
62
|
-
*/
|
|
63
|
-
REUSE = "reuse",
|
|
64
|
-
/**
|
|
65
|
-
* Abort current promise if it's marked as abortable (make sure to manage properly the rejection)
|
|
66
|
-
*/
|
|
67
|
-
ABORT = "abort"
|
|
68
|
-
}
|
|
69
|
-
export type PromiseProvider<S, DS, F extends (...args: any[]) => any, A, P> = (ctx: GetPromiseInvocationContext<S, DS, F, P, A>) => ReturnType<F> | null;
|
|
70
|
-
/**
|
|
71
|
-
* Simple form of a synchronous action.
|
|
72
|
-
*/
|
|
73
|
-
export type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = Partial<S>> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
74
|
-
export type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
75
|
-
/**
|
|
76
|
-
* Function that update the state when the action is called.
|
|
77
|
-
*/
|
|
78
|
-
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
79
|
-
/**
|
|
80
|
-
* Debounces the action if this parameter is defined.
|
|
81
|
-
*/
|
|
82
|
-
debounceTimeout?: number;
|
|
83
|
-
/**
|
|
84
|
-
* Debounces the action side effects if this parameter is defined.
|
|
85
|
-
*/
|
|
86
|
-
debounceSideEffectsTimeout?: number;
|
|
87
|
-
/**
|
|
88
|
-
* Function that calls side effects, ie. effects that are not changing the state directly.
|
|
89
|
-
*/
|
|
90
|
-
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Try to abort an action, if the action is <code>abortable</code>.
|
|
94
|
-
* @param actionName The action name
|
|
95
|
-
* @param promiseId If the action conflict type is <code>ConflictType.PARALLEL</code>, the identifier of the promise.
|
|
96
|
-
* @returns <code>true</code> if the action is abortable and an action is ongoing, <code>false</code> otherwise.
|
|
97
|
-
*/
|
|
98
|
-
export type AbortActionCallback<A> = (actionName: keyof A, promiseId?: string) => boolean;
|
|
99
|
-
export type GetErrorMessage<S, DS, F extends (...args: any[]) => any, P> = (ctx: ErrorMessageInvocationContext<S, DS, F, P>) => string | null;
|
|
100
|
-
export type ContextState<S> = {
|
|
101
|
-
state: S;
|
|
102
|
-
s: S;
|
|
103
|
-
};
|
|
104
|
-
export type ContextDerivedStateState<DS> = {
|
|
105
|
-
derived: DS;
|
|
106
|
-
ds: DS;
|
|
107
|
-
};
|
|
108
|
-
export type ContextBase<S, P> = ContextState<S> & {
|
|
109
|
-
props: P;
|
|
110
|
-
p: P;
|
|
111
|
-
};
|
|
112
|
-
export type ContextWithDerived<S, DS, P> = ContextBase<S, P> & ContextDerivedStateState<DS>;
|
|
113
|
-
export type InvocationContextActions<A> = {
|
|
114
|
-
actions: A;
|
|
115
|
-
a: A;
|
|
116
|
-
};
|
|
117
|
-
export type WarningNotifyFunc = {
|
|
118
|
-
notifyWarning?: NotifyFunc;
|
|
119
|
-
};
|
|
120
|
-
export type InvocationContext<S, DS, F extends (...args: any[]) => any, P> = ContextWithDerived<S, DS, P> & {
|
|
121
|
-
args: Parameters<F>;
|
|
122
|
-
promiseId: string;
|
|
123
|
-
};
|
|
124
|
-
export type EffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
125
|
-
result: PromiseResult<ReturnType<F>>;
|
|
126
|
-
res: PromiseResult<ReturnType<F>>;
|
|
127
|
-
};
|
|
128
|
-
export type GetPromiseInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = InvocationContextActions<A> & InvocationContext<S, DS, F, P> & {
|
|
129
|
-
abortSignal: AbortSignal;
|
|
130
|
-
};
|
|
131
|
-
export type ErrorEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
132
|
-
error: Error;
|
|
133
|
-
err: Error;
|
|
134
|
-
};
|
|
135
|
-
export type SuccessMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = EffectsInvocationContext<S, DS, F, P>;
|
|
136
|
-
export type ErrorMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = ErrorEffectsInvocationContext<S, DS, F, P>;
|
|
137
|
-
export type ClearErrorFunc<A> = (actionName: keyof A, promiseId?: string) => void;
|
|
138
|
-
export type ClearError<A> = {
|
|
139
|
-
clearError: ClearErrorFunc<A>;
|
|
140
|
-
};
|
|
141
|
-
export type SideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = EffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc & ClearError<A>;
|
|
142
|
-
export type ErrorSideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = ErrorEffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc;
|
|
143
|
-
export type OnMountInvocationContext<S, A, P> = ContextBase<S, P> & InvocationContextActions<A>;
|
|
144
|
-
export type AbortedActions<A> = Partial<Record<keyof A, string[]>>;
|
|
145
|
-
export type OnUnMountInvocationContext<S, A, P> = ContextBase<S, P> & {
|
|
146
|
-
abortedActions: AbortedActions<A>;
|
|
147
|
-
};
|
|
148
|
-
export type EffectsType = 'preEffects' | 'effects' | 'errorEffects' | 'optimisticEffects' | null;
|
|
149
|
-
export type MiddlewareActionContext<S, A, P> = {
|
|
150
|
-
name: keyof A;
|
|
151
|
-
type: EffectsType;
|
|
152
|
-
isAsync: boolean;
|
|
153
|
-
context: InvocationContext<S, any, any, P>;
|
|
154
|
-
};
|
|
155
|
-
export type MiddlewareStoreContext<S, A extends DecoratedActions, P> = {
|
|
156
|
-
actions: StoreActions<S, A, P, any, any>;
|
|
157
|
-
state: S;
|
|
158
|
-
setState: (s: S) => void;
|
|
159
|
-
options: StoreOptions<S, A, P, any>;
|
|
160
|
-
};
|
|
161
|
-
export type MiddlewareFactory<S, A extends DecoratedActions, P> = () => Middleware<S, A, P>;
|
|
162
|
-
/**
|
|
163
|
-
* A state change middleware.
|
|
164
|
-
* Allow to listen and change a state change on the fly.
|
|
165
|
-
*/
|
|
166
|
-
export type Middleware<S, A extends DecoratedActions, P> = {
|
|
167
|
-
/**
|
|
168
|
-
* Initializes the middleware. Called when the store is initializing.
|
|
169
|
-
*/
|
|
170
|
-
init: (storeContext: MiddlewareStoreContext<S, A, P>) => void;
|
|
171
|
-
/**
|
|
172
|
-
* Invoked on a state change has occurred and returns a new state or <code>null</code> if unchanged.
|
|
173
|
-
*/
|
|
174
|
-
effects: (actionContext: MiddlewareActionContext<S, A, P>, oldState: S, newState: S, loading: boolean) => null | {
|
|
175
|
-
state: S;
|
|
176
|
-
loading: boolean;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Destroys the middleware. Called when the store is being destroyed.
|
|
180
|
-
*/
|
|
181
|
-
destroy: () => void;
|
|
182
|
-
};
|
|
183
|
-
export type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
184
|
-
/**
|
|
185
|
-
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
186
|
-
*/
|
|
187
|
-
abortable?: boolean;
|
|
188
|
-
/**
|
|
189
|
-
* A function that provides the success message to pass to the notifySuccess function passed as property to the StateDecorator.
|
|
190
|
-
*/
|
|
191
|
-
getSuccessMessage?: (ctx: SuccessMessageInvocationContext<S, DS, F, P>) => string;
|
|
192
|
-
/**
|
|
193
|
-
* A function that provides the error message to pass to the notifyError function passed as property to the StateDecorator.
|
|
194
|
-
*/
|
|
195
|
-
getErrorMessage?: GetErrorMessage<S, DS, F, P>;
|
|
196
|
-
/**
|
|
197
|
-
* If set, called with the result of the promise to update the current state.
|
|
198
|
-
*/
|
|
199
|
-
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
200
|
-
/**
|
|
201
|
-
* If set, called with the error of the promise to update the current state.
|
|
202
|
-
*/
|
|
203
|
-
errorEffects?: (ctx: ErrorEffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
204
|
-
/**
|
|
205
|
-
* Whether reject the promise instead of handling it.
|
|
206
|
-
*/
|
|
207
|
-
rejectPromiseOnError?: boolean;
|
|
208
|
-
/**
|
|
209
|
-
* When the error will not be managed by an errorEffect, errorSideEffect, getErrorMessage,
|
|
210
|
-
* the state decorator will not display an error message and will not return a failed promise
|
|
211
|
-
* (unless <code>rejectPromiseOnError</code>) is set.
|
|
212
|
-
*/
|
|
213
|
-
isErrorManaged?: boolean;
|
|
214
|
-
/**
|
|
215
|
-
* Handle side effects when the request succeeded.
|
|
216
|
-
* @param result The result of the request
|
|
217
|
-
* @param newData The data after the reducer is applied
|
|
218
|
-
* @param args The argument during the call of the request function
|
|
219
|
-
* @param props The props passed to the state decorator
|
|
220
|
-
* @param actions The actions available
|
|
221
|
-
* @param notifyWarning If specified, a notify function to indicate that the action is a semi success (use successMessage / getSuccessMessage otherwise).
|
|
222
|
-
*/
|
|
223
|
-
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
224
|
-
/**
|
|
225
|
-
* Handle side effects when the request failed.
|
|
226
|
-
* @param error The error of the request
|
|
227
|
-
* @param args The argument during the call of the request function
|
|
228
|
-
* @param props The props passed to the state decorator
|
|
229
|
-
* @param actions The actions available
|
|
230
|
-
* @param notifyWarning If specified, a notify function to indicate that the action is a semi failure (use errorMessage / getErrorMessage otherwise).
|
|
231
|
-
*/
|
|
232
|
-
errorSideEffects?: (ctx: ErrorSideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
233
|
-
/**
|
|
234
|
-
* Retrieve the state to set as current data before the promise is resolved.
|
|
235
|
-
* If the there's no reducer, this data will be used after the promise is done.
|
|
236
|
-
*/
|
|
237
|
-
preEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
238
|
-
/**
|
|
239
|
-
* Retrieve the state to set as current data before the promise is resolved.
|
|
240
|
-
* If the there's no reducer, this data will be used after the promise is done.
|
|
241
|
-
*/
|
|
242
|
-
optimisticEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
243
|
-
/**
|
|
244
|
-
* Policy to apply when a call to an asynchronous action is done but a previous call is still not resolved.
|
|
245
|
-
*/
|
|
246
|
-
conflictPolicy?: ConflictPolicy;
|
|
247
|
-
/**
|
|
248
|
-
* Get an identifier for an action call. Used only when conflictPolicy is ConflictPolicy.PARALLEL.
|
|
249
|
-
* This information will be available in loadingMap. loadingMap[actionName] will be an array of promise identifiers.
|
|
250
|
-
*/
|
|
251
|
-
getPromiseId?: (...args: Parameters<F>) => string;
|
|
252
|
-
/**
|
|
253
|
-
* Number of retries in case of error (failed to fetch).
|
|
254
|
-
* Do not use this if you are creating objects...
|
|
255
|
-
* Default value is 0 (no retry).
|
|
256
|
-
*/
|
|
257
|
-
retryCount?: number;
|
|
258
|
-
/**
|
|
259
|
-
* Seed of delay between each retry in milliseconds.
|
|
260
|
-
* The applied delay is retryDelaySeed * retry count.
|
|
261
|
-
* Default value is 1000 (1 second).
|
|
262
|
-
*/
|
|
263
|
-
retryDelaySeed?: number;
|
|
264
|
-
/**
|
|
265
|
-
* Function to test if the error will trigger an action retry or will fail directly.
|
|
266
|
-
*/
|
|
267
|
-
isTriggerRetryError?: (e: Error) => boolean;
|
|
268
|
-
};
|
|
269
|
-
export type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
270
|
-
/**
|
|
271
|
-
* The request, returns a promise
|
|
272
|
-
*/
|
|
273
|
-
getPromise: PromiseProvider<S, DS, F, A, P>;
|
|
274
|
-
};
|
|
275
|
-
export type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
276
|
-
/**
|
|
277
|
-
* The request, returns a promise that is a GET request.
|
|
278
|
-
* A shortcut to set:
|
|
279
|
-
* - retryCount: 3
|
|
280
|
-
* - conflictPolicy: ConflictPolicy.REUSE
|
|
281
|
-
*/
|
|
282
|
-
getGetPromise: PromiseProvider<S, DS, F, A, P>;
|
|
283
|
-
};
|
|
284
|
-
export type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionPromise<S, F, A, P, DS, FxRes> | AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
|
|
285
|
-
export type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
|
|
286
|
-
/**
|
|
287
|
-
* S: The type of the state
|
|
288
|
-
* A: The type of the actions to pass to the children (used to check keys only).
|
|
289
|
-
*/
|
|
290
|
-
export type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
291
|
-
[Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
|
|
292
|
-
};
|
|
293
|
-
export type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
|
|
294
|
-
indices: number[];
|
|
295
|
-
index: number;
|
|
296
|
-
isInit: boolean;
|
|
297
|
-
getInitialState: (p: P) => S;
|
|
298
|
-
};
|
|
299
|
-
export type OnPropsChangeSideEffectsContext<S, P, A, DS = {}> = OnPropsChangeEffectsContext<S, DS, P> & {
|
|
300
|
-
actions: A;
|
|
301
|
-
a: A;
|
|
302
|
-
};
|
|
303
|
-
type DerivedStateOption<S, P, DS> = {
|
|
304
|
-
[k in keyof DS]: {
|
|
305
|
-
getDeps?: (ctx: ContextBase<S, P>) => any[];
|
|
306
|
-
get: (ctx: ContextBase<S, P> & ContextDerivedStateState<DS>) => DS[k];
|
|
307
|
-
derivedDeps?: (keyof DS)[];
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
export type OnPropsChangeOptions<S, DS, A, P, FxRes = Partial<S>> = {
|
|
311
|
-
onMount?: boolean;
|
|
312
|
-
onMountDeferred?: boolean;
|
|
313
|
-
getDeps: (p: P) => any[];
|
|
314
|
-
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => FxRes;
|
|
315
|
-
sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A, DS>) => void;
|
|
316
|
-
};
|
|
317
|
-
export type StoreOptions<S, A, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
318
|
-
/**
|
|
319
|
-
* The state decorator name. Use in debug traces to identify the useStateDecorator instance.
|
|
320
|
-
*/
|
|
321
|
-
name?: string;
|
|
322
|
-
/**
|
|
323
|
-
* In development only (NODE_ENV="development"), activates state changes traces on the console.
|
|
324
|
-
*/
|
|
325
|
-
logEnabled?: boolean;
|
|
326
|
-
/**
|
|
327
|
-
* Indicates that all asynchronous actions errors are managed externally.
|
|
328
|
-
* Same as setting isErrorManaged to true for all actions.
|
|
329
|
-
*/
|
|
330
|
-
isErrorManaged?: boolean;
|
|
331
|
-
/**
|
|
332
|
-
* List of action names that are marked as loading at initial time.
|
|
333
|
-
* If you must start your initial actions in a useSideEffect, a render is done before
|
|
334
|
-
* first actions can be trigerred, some actions can be marked as loading at initial time.
|
|
335
|
-
*/
|
|
336
|
-
initialActionsMarkedLoading?: (keyof A)[];
|
|
337
|
-
/**
|
|
338
|
-
* One or several configurations of inbound properties change managements.
|
|
339
|
-
*/
|
|
340
|
-
onPropsChange?: OnPropsChangeOptions<S, DS, A, P, FxRes> | OnPropsChangeOptions<S, DS, A, P, FxRes>[];
|
|
341
|
-
/**
|
|
342
|
-
* The callback function called if an asynchronous function succeeded and a success messsage is defined.
|
|
343
|
-
*/
|
|
344
|
-
notifySuccess?: NotifyFunc;
|
|
345
|
-
/**
|
|
346
|
-
* The callback function called if an asynchronous function fails and an error messsage is defined.
|
|
347
|
-
*/
|
|
348
|
-
notifyError?: NotifyFunc;
|
|
349
|
-
/**
|
|
350
|
-
* The callback function injected in onDone and onFail of asynchronous functions to notify a semi success / failed request.
|
|
351
|
-
*/
|
|
352
|
-
notifyWarning?: NotifyFunc;
|
|
353
|
-
/**
|
|
354
|
-
* Initial actions.
|
|
355
|
-
*/
|
|
356
|
-
onMount?: (ctx: OnMountInvocationContext<S, A, P>) => void;
|
|
357
|
-
/**
|
|
358
|
-
* Initial actions executed after initial render.
|
|
359
|
-
*
|
|
360
|
-
*/
|
|
361
|
-
onMountDeferred?: (ctx: OnMountInvocationContext<S, A, P>) => void;
|
|
362
|
-
/**
|
|
363
|
-
* Callback on store destruction.
|
|
364
|
-
*/
|
|
365
|
-
onUnmount?: (ctx: OnUnMountInvocationContext<S, A, P>) => Promise<any> | void;
|
|
366
|
-
/**
|
|
367
|
-
* Compute derived state
|
|
368
|
-
*/
|
|
369
|
-
derivedState?: DerivedStateOption<S, P, DS>;
|
|
370
|
-
/**
|
|
371
|
-
* Disable auto spread of state on effects (v6 behavior).
|
|
372
|
-
*/
|
|
373
|
-
fullStateEffects?: boolean;
|
|
374
|
-
};
|
|
375
|
-
type StoreConfigBase<S, A extends DecoratedActions, P = {}, DS = {}> = {
|
|
376
|
-
actions: StoreActions<S, A, P, DS>;
|
|
377
|
-
middlewares?: MiddlewareFactory<S, A, P>[];
|
|
378
|
-
} & StoreOptions<S, A, P, DS>;
|
|
379
|
-
export type StoreConfigObj<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
380
|
-
initialState: S;
|
|
381
|
-
};
|
|
382
|
-
export type StoreConfigFunc<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
383
|
-
getInitialState: (p: P) => S;
|
|
384
|
-
};
|
|
385
|
-
export type StoreConfig<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigObj<S, A, P, DS> | StoreConfigFunc<S, A, P, DS>;
|
|
386
|
-
export {};
|
|
1
|
+
export type PromiseResult<Type> = Type extends Promise<infer X> ? X : null;
|
|
2
|
+
export type NotifyFunc = (msg: string) => void;
|
|
3
|
+
export type PromiseIdMap = {
|
|
4
|
+
[promiseId: string]: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type LoadingMap<A> = {
|
|
7
|
+
[pId in keyof A]?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type LoadingParallelMap<A> = {
|
|
10
|
+
[P in keyof A]?: PromiseIdMap;
|
|
11
|
+
};
|
|
12
|
+
export type InternalLoadingMap<A> = LoadingParallelMap<A>;
|
|
13
|
+
export type LoadingProps<A> = {
|
|
14
|
+
loading: boolean;
|
|
15
|
+
loadingMap: LoadingMap<A>;
|
|
16
|
+
loadingParallelMap: LoadingParallelMap<A>;
|
|
17
|
+
};
|
|
18
|
+
export type LoadingMapProps<A> = Pick<LoadingProps<A>, 'loadingMap'>;
|
|
19
|
+
export type PromiseIdErrorMap = {
|
|
20
|
+
[promiseId: string]: Error;
|
|
21
|
+
};
|
|
22
|
+
export type ErrorMap<A> = {
|
|
23
|
+
[pId in keyof A]?: Error;
|
|
24
|
+
};
|
|
25
|
+
export type ErrorParallelMap<A> = {
|
|
26
|
+
[P in keyof A]?: PromiseIdErrorMap;
|
|
27
|
+
};
|
|
28
|
+
export type ErrorProps<A> = {
|
|
29
|
+
errorMap: ErrorMap<A>;
|
|
30
|
+
};
|
|
31
|
+
export interface DecoratedActions {
|
|
32
|
+
[name: string]: (...args: any[]) => Promise<any> | void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The State decorator can manage only one asynchronous action of same name at a time.
|
|
36
|
+
* This enum is enumertaing all the policies in such case.
|
|
37
|
+
*/
|
|
38
|
+
export declare enum ConflictPolicy {
|
|
39
|
+
/**
|
|
40
|
+
* Reject the promise.
|
|
41
|
+
*/
|
|
42
|
+
REJECT = "reject",
|
|
43
|
+
/**
|
|
44
|
+
* Return a resolved promise with no result.
|
|
45
|
+
*/
|
|
46
|
+
IGNORE = "ignore",
|
|
47
|
+
/**
|
|
48
|
+
* Execute only the last call that conflicts after the one ongoing.
|
|
49
|
+
*/
|
|
50
|
+
KEEP_LAST = "keepLast",
|
|
51
|
+
/**
|
|
52
|
+
* Execute all calls one after another.
|
|
53
|
+
*/
|
|
54
|
+
KEEP_ALL = "keepAll",
|
|
55
|
+
/**
|
|
56
|
+
* Execute all calls one after another.
|
|
57
|
+
* @see getPromiseId
|
|
58
|
+
*/
|
|
59
|
+
PARALLEL = "parallel",
|
|
60
|
+
/**
|
|
61
|
+
* Reuse the ongoing promise if any and if possible (same arguments). Only for GET requests!
|
|
62
|
+
*/
|
|
63
|
+
REUSE = "reuse",
|
|
64
|
+
/**
|
|
65
|
+
* Abort current promise if it's marked as abortable (make sure to manage properly the rejection)
|
|
66
|
+
*/
|
|
67
|
+
ABORT = "abort"
|
|
68
|
+
}
|
|
69
|
+
export type PromiseProvider<S, DS, F extends (...args: any[]) => any, A, P> = (ctx: GetPromiseInvocationContext<S, DS, F, P, A>) => ReturnType<F> | null;
|
|
70
|
+
/**
|
|
71
|
+
* Simple form of a synchronous action.
|
|
72
|
+
*/
|
|
73
|
+
export type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = Partial<S>> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
74
|
+
export type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
75
|
+
/**
|
|
76
|
+
* Function that update the state when the action is called.
|
|
77
|
+
*/
|
|
78
|
+
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
79
|
+
/**
|
|
80
|
+
* Debounces the action if this parameter is defined.
|
|
81
|
+
*/
|
|
82
|
+
debounceTimeout?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Debounces the action side effects if this parameter is defined.
|
|
85
|
+
*/
|
|
86
|
+
debounceSideEffectsTimeout?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Function that calls side effects, ie. effects that are not changing the state directly.
|
|
89
|
+
*/
|
|
90
|
+
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Try to abort an action, if the action is <code>abortable</code>.
|
|
94
|
+
* @param actionName The action name
|
|
95
|
+
* @param promiseId If the action conflict type is <code>ConflictType.PARALLEL</code>, the identifier of the promise.
|
|
96
|
+
* @returns <code>true</code> if the action is abortable and an action is ongoing, <code>false</code> otherwise.
|
|
97
|
+
*/
|
|
98
|
+
export type AbortActionCallback<A> = (actionName: keyof A, promiseId?: string) => boolean;
|
|
99
|
+
export type GetErrorMessage<S, DS, F extends (...args: any[]) => any, P> = (ctx: ErrorMessageInvocationContext<S, DS, F, P>) => string | null;
|
|
100
|
+
export type ContextState<S> = {
|
|
101
|
+
state: S;
|
|
102
|
+
s: S;
|
|
103
|
+
};
|
|
104
|
+
export type ContextDerivedStateState<DS> = {
|
|
105
|
+
derived: DS;
|
|
106
|
+
ds: DS;
|
|
107
|
+
};
|
|
108
|
+
export type ContextBase<S, P> = ContextState<S> & {
|
|
109
|
+
props: P;
|
|
110
|
+
p: P;
|
|
111
|
+
};
|
|
112
|
+
export type ContextWithDerived<S, DS, P> = ContextBase<S, P> & ContextDerivedStateState<DS>;
|
|
113
|
+
export type InvocationContextActions<A> = {
|
|
114
|
+
actions: A;
|
|
115
|
+
a: A;
|
|
116
|
+
};
|
|
117
|
+
export type WarningNotifyFunc = {
|
|
118
|
+
notifyWarning?: NotifyFunc;
|
|
119
|
+
};
|
|
120
|
+
export type InvocationContext<S, DS, F extends (...args: any[]) => any, P> = ContextWithDerived<S, DS, P> & {
|
|
121
|
+
args: Parameters<F>;
|
|
122
|
+
promiseId: string;
|
|
123
|
+
};
|
|
124
|
+
export type EffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
125
|
+
result: PromiseResult<ReturnType<F>>;
|
|
126
|
+
res: PromiseResult<ReturnType<F>>;
|
|
127
|
+
};
|
|
128
|
+
export type GetPromiseInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = InvocationContextActions<A> & InvocationContext<S, DS, F, P> & {
|
|
129
|
+
abortSignal: AbortSignal;
|
|
130
|
+
};
|
|
131
|
+
export type ErrorEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
132
|
+
error: Error;
|
|
133
|
+
err: Error;
|
|
134
|
+
};
|
|
135
|
+
export type SuccessMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = EffectsInvocationContext<S, DS, F, P>;
|
|
136
|
+
export type ErrorMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = ErrorEffectsInvocationContext<S, DS, F, P>;
|
|
137
|
+
export type ClearErrorFunc<A> = (actionName: keyof A, promiseId?: string) => void;
|
|
138
|
+
export type ClearError<A> = {
|
|
139
|
+
clearError: ClearErrorFunc<A>;
|
|
140
|
+
};
|
|
141
|
+
export type SideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = EffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc & ClearError<A>;
|
|
142
|
+
export type ErrorSideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = ErrorEffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc;
|
|
143
|
+
export type OnMountInvocationContext<S, A, P> = ContextBase<S, P> & InvocationContextActions<A>;
|
|
144
|
+
export type AbortedActions<A> = Partial<Record<keyof A, string[]>>;
|
|
145
|
+
export type OnUnMountInvocationContext<S, A, P> = ContextBase<S, P> & {
|
|
146
|
+
abortedActions: AbortedActions<A>;
|
|
147
|
+
};
|
|
148
|
+
export type EffectsType = 'preEffects' | 'effects' | 'errorEffects' | 'optimisticEffects' | null;
|
|
149
|
+
export type MiddlewareActionContext<S, A, P> = {
|
|
150
|
+
name: keyof A;
|
|
151
|
+
type: EffectsType;
|
|
152
|
+
isAsync: boolean;
|
|
153
|
+
context: InvocationContext<S, any, any, P>;
|
|
154
|
+
};
|
|
155
|
+
export type MiddlewareStoreContext<S, A extends DecoratedActions, P> = {
|
|
156
|
+
actions: StoreActions<S, A, P, any, any>;
|
|
157
|
+
state: S;
|
|
158
|
+
setState: (s: S) => void;
|
|
159
|
+
options: StoreOptions<S, A, P, any>;
|
|
160
|
+
};
|
|
161
|
+
export type MiddlewareFactory<S, A extends DecoratedActions, P> = () => Middleware<S, A, P>;
|
|
162
|
+
/**
|
|
163
|
+
* A state change middleware.
|
|
164
|
+
* Allow to listen and change a state change on the fly.
|
|
165
|
+
*/
|
|
166
|
+
export type Middleware<S, A extends DecoratedActions, P> = {
|
|
167
|
+
/**
|
|
168
|
+
* Initializes the middleware. Called when the store is initializing.
|
|
169
|
+
*/
|
|
170
|
+
init: (storeContext: MiddlewareStoreContext<S, A, P>) => void;
|
|
171
|
+
/**
|
|
172
|
+
* Invoked on a state change has occurred and returns a new state or <code>null</code> if unchanged.
|
|
173
|
+
*/
|
|
174
|
+
effects: (actionContext: MiddlewareActionContext<S, A, P>, oldState: S, newState: S, loading: boolean) => null | {
|
|
175
|
+
state: S;
|
|
176
|
+
loading: boolean;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Destroys the middleware. Called when the store is being destroyed.
|
|
180
|
+
*/
|
|
181
|
+
destroy: () => void;
|
|
182
|
+
};
|
|
183
|
+
export type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
184
|
+
/**
|
|
185
|
+
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
186
|
+
*/
|
|
187
|
+
abortable?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* A function that provides the success message to pass to the notifySuccess function passed as property to the StateDecorator.
|
|
190
|
+
*/
|
|
191
|
+
getSuccessMessage?: (ctx: SuccessMessageInvocationContext<S, DS, F, P>) => string;
|
|
192
|
+
/**
|
|
193
|
+
* A function that provides the error message to pass to the notifyError function passed as property to the StateDecorator.
|
|
194
|
+
*/
|
|
195
|
+
getErrorMessage?: GetErrorMessage<S, DS, F, P>;
|
|
196
|
+
/**
|
|
197
|
+
* If set, called with the result of the promise to update the current state.
|
|
198
|
+
*/
|
|
199
|
+
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
200
|
+
/**
|
|
201
|
+
* If set, called with the error of the promise to update the current state.
|
|
202
|
+
*/
|
|
203
|
+
errorEffects?: (ctx: ErrorEffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
204
|
+
/**
|
|
205
|
+
* Whether reject the promise instead of handling it.
|
|
206
|
+
*/
|
|
207
|
+
rejectPromiseOnError?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* When the error will not be managed by an errorEffect, errorSideEffect, getErrorMessage,
|
|
210
|
+
* the state decorator will not display an error message and will not return a failed promise
|
|
211
|
+
* (unless <code>rejectPromiseOnError</code>) is set.
|
|
212
|
+
*/
|
|
213
|
+
isErrorManaged?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Handle side effects when the request succeeded.
|
|
216
|
+
* @param result The result of the request
|
|
217
|
+
* @param newData The data after the reducer is applied
|
|
218
|
+
* @param args The argument during the call of the request function
|
|
219
|
+
* @param props The props passed to the state decorator
|
|
220
|
+
* @param actions The actions available
|
|
221
|
+
* @param notifyWarning If specified, a notify function to indicate that the action is a semi success (use successMessage / getSuccessMessage otherwise).
|
|
222
|
+
*/
|
|
223
|
+
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Handle side effects when the request failed.
|
|
226
|
+
* @param error The error of the request
|
|
227
|
+
* @param args The argument during the call of the request function
|
|
228
|
+
* @param props The props passed to the state decorator
|
|
229
|
+
* @param actions The actions available
|
|
230
|
+
* @param notifyWarning If specified, a notify function to indicate that the action is a semi failure (use errorMessage / getErrorMessage otherwise).
|
|
231
|
+
*/
|
|
232
|
+
errorSideEffects?: (ctx: ErrorSideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
233
|
+
/**
|
|
234
|
+
* Retrieve the state to set as current data before the promise is resolved.
|
|
235
|
+
* If the there's no reducer, this data will be used after the promise is done.
|
|
236
|
+
*/
|
|
237
|
+
preEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
238
|
+
/**
|
|
239
|
+
* Retrieve the state to set as current data before the promise is resolved.
|
|
240
|
+
* If the there's no reducer, this data will be used after the promise is done.
|
|
241
|
+
*/
|
|
242
|
+
optimisticEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
243
|
+
/**
|
|
244
|
+
* Policy to apply when a call to an asynchronous action is done but a previous call is still not resolved.
|
|
245
|
+
*/
|
|
246
|
+
conflictPolicy?: ConflictPolicy;
|
|
247
|
+
/**
|
|
248
|
+
* Get an identifier for an action call. Used only when conflictPolicy is ConflictPolicy.PARALLEL.
|
|
249
|
+
* This information will be available in loadingMap. loadingMap[actionName] will be an array of promise identifiers.
|
|
250
|
+
*/
|
|
251
|
+
getPromiseId?: (...args: Parameters<F>) => string;
|
|
252
|
+
/**
|
|
253
|
+
* Number of retries in case of error (failed to fetch).
|
|
254
|
+
* Do not use this if you are creating objects...
|
|
255
|
+
* Default value is 0 (no retry).
|
|
256
|
+
*/
|
|
257
|
+
retryCount?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Seed of delay between each retry in milliseconds.
|
|
260
|
+
* The applied delay is retryDelaySeed * retry count.
|
|
261
|
+
* Default value is 1000 (1 second).
|
|
262
|
+
*/
|
|
263
|
+
retryDelaySeed?: number;
|
|
264
|
+
/**
|
|
265
|
+
* Function to test if the error will trigger an action retry or will fail directly.
|
|
266
|
+
*/
|
|
267
|
+
isTriggerRetryError?: (e: Error) => boolean;
|
|
268
|
+
};
|
|
269
|
+
export type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
270
|
+
/**
|
|
271
|
+
* The request, returns a promise
|
|
272
|
+
*/
|
|
273
|
+
getPromise: PromiseProvider<S, DS, F, A, P>;
|
|
274
|
+
};
|
|
275
|
+
export type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
276
|
+
/**
|
|
277
|
+
* The request, returns a promise that is a GET request.
|
|
278
|
+
* A shortcut to set:
|
|
279
|
+
* - retryCount: 3
|
|
280
|
+
* - conflictPolicy: ConflictPolicy.REUSE
|
|
281
|
+
*/
|
|
282
|
+
getGetPromise: PromiseProvider<S, DS, F, A, P>;
|
|
283
|
+
};
|
|
284
|
+
export type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionPromise<S, F, A, P, DS, FxRes> | AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
|
|
285
|
+
export type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
|
|
286
|
+
/**
|
|
287
|
+
* S: The type of the state
|
|
288
|
+
* A: The type of the actions to pass to the children (used to check keys only).
|
|
289
|
+
*/
|
|
290
|
+
export type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
291
|
+
[Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
|
|
292
|
+
};
|
|
293
|
+
export type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
|
|
294
|
+
indices: number[];
|
|
295
|
+
index: number;
|
|
296
|
+
isInit: boolean;
|
|
297
|
+
getInitialState: (p: P) => S;
|
|
298
|
+
};
|
|
299
|
+
export type OnPropsChangeSideEffectsContext<S, P, A, DS = {}> = OnPropsChangeEffectsContext<S, DS, P> & {
|
|
300
|
+
actions: A;
|
|
301
|
+
a: A;
|
|
302
|
+
};
|
|
303
|
+
type DerivedStateOption<S, P, DS> = {
|
|
304
|
+
[k in keyof DS]: {
|
|
305
|
+
getDeps?: (ctx: ContextBase<S, P>) => any[];
|
|
306
|
+
get: (ctx: ContextBase<S, P> & ContextDerivedStateState<DS>) => DS[k];
|
|
307
|
+
derivedDeps?: (keyof DS)[];
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
export type OnPropsChangeOptions<S, DS, A, P, FxRes = Partial<S>> = {
|
|
311
|
+
onMount?: boolean;
|
|
312
|
+
onMountDeferred?: boolean;
|
|
313
|
+
getDeps: (p: P) => any[];
|
|
314
|
+
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => FxRes;
|
|
315
|
+
sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A, DS>) => void;
|
|
316
|
+
};
|
|
317
|
+
export type StoreOptions<S, A, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
318
|
+
/**
|
|
319
|
+
* The state decorator name. Use in debug traces to identify the useStateDecorator instance.
|
|
320
|
+
*/
|
|
321
|
+
name?: string;
|
|
322
|
+
/**
|
|
323
|
+
* In development only (NODE_ENV="development"), activates state changes traces on the console.
|
|
324
|
+
*/
|
|
325
|
+
logEnabled?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Indicates that all asynchronous actions errors are managed externally.
|
|
328
|
+
* Same as setting isErrorManaged to true for all actions.
|
|
329
|
+
*/
|
|
330
|
+
isErrorManaged?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* List of action names that are marked as loading at initial time.
|
|
333
|
+
* If you must start your initial actions in a useSideEffect, a render is done before
|
|
334
|
+
* first actions can be trigerred, some actions can be marked as loading at initial time.
|
|
335
|
+
*/
|
|
336
|
+
initialActionsMarkedLoading?: (keyof A)[];
|
|
337
|
+
/**
|
|
338
|
+
* One or several configurations of inbound properties change managements.
|
|
339
|
+
*/
|
|
340
|
+
onPropsChange?: OnPropsChangeOptions<S, DS, A, P, FxRes> | OnPropsChangeOptions<S, DS, A, P, FxRes>[];
|
|
341
|
+
/**
|
|
342
|
+
* The callback function called if an asynchronous function succeeded and a success messsage is defined.
|
|
343
|
+
*/
|
|
344
|
+
notifySuccess?: NotifyFunc;
|
|
345
|
+
/**
|
|
346
|
+
* The callback function called if an asynchronous function fails and an error messsage is defined.
|
|
347
|
+
*/
|
|
348
|
+
notifyError?: NotifyFunc;
|
|
349
|
+
/**
|
|
350
|
+
* The callback function injected in onDone and onFail of asynchronous functions to notify a semi success / failed request.
|
|
351
|
+
*/
|
|
352
|
+
notifyWarning?: NotifyFunc;
|
|
353
|
+
/**
|
|
354
|
+
* Initial actions.
|
|
355
|
+
*/
|
|
356
|
+
onMount?: (ctx: OnMountInvocationContext<S, A, P>) => void;
|
|
357
|
+
/**
|
|
358
|
+
* Initial actions executed after initial render.
|
|
359
|
+
*
|
|
360
|
+
*/
|
|
361
|
+
onMountDeferred?: (ctx: OnMountInvocationContext<S, A, P>) => void;
|
|
362
|
+
/**
|
|
363
|
+
* Callback on store destruction.
|
|
364
|
+
*/
|
|
365
|
+
onUnmount?: (ctx: OnUnMountInvocationContext<S, A, P>) => Promise<any> | void;
|
|
366
|
+
/**
|
|
367
|
+
* Compute derived state
|
|
368
|
+
*/
|
|
369
|
+
derivedState?: DerivedStateOption<S, P, DS>;
|
|
370
|
+
/**
|
|
371
|
+
* Disable auto spread of state on effects (v6 behavior).
|
|
372
|
+
*/
|
|
373
|
+
fullStateEffects?: boolean;
|
|
374
|
+
};
|
|
375
|
+
type StoreConfigBase<S, A extends DecoratedActions, P = {}, DS = {}> = {
|
|
376
|
+
actions: StoreActions<S, A, P, DS>;
|
|
377
|
+
middlewares?: MiddlewareFactory<S, A, P>[];
|
|
378
|
+
} & StoreOptions<S, A, P, DS>;
|
|
379
|
+
export type StoreConfigObj<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
380
|
+
initialState: S;
|
|
381
|
+
};
|
|
382
|
+
export type StoreConfigFunc<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
383
|
+
getInitialState: (p: P) => S;
|
|
384
|
+
};
|
|
385
|
+
export type StoreConfig<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigObj<S, A, P, DS> | StoreConfigFunc<S, A, P, DS>;
|
|
386
|
+
export {};
|