state-decorator 6.9.0 → 6.10.1
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/README.md +3 -1
- package/dist/impl.d.ts +195 -0
- package/dist/impl.js +2 -0
- package/dist/impl.js.map +1 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares.d.ts +26 -0
- package/dist/middlewares.js +2 -0
- package/dist/middlewares.js.map +1 -0
- package/dist/shallow.d.ts +15 -0
- package/dist/test.d.ts +134 -0
- package/dist/test.js +2 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +352 -0
- package/dist/v5.d.ts +58 -0
- package/dist/v5.js +2 -0
- package/dist/v5.js.map +1 -0
- package/dist/v5_test.d.ts +70 -0
- package/dist/v5_test.js +2 -0
- package/dist/v5_test.js.map +1 -0
- package/dist/v5_types.d.ts +227 -0
- package/es/impl.d.ts +195 -0
- package/es/impl.js +2 -0
- package/es/impl.js.map +1 -0
- package/es/index.d.ts +168 -0
- package/es/index.js +2 -0
- package/es/index.js.map +1 -0
- package/es/middlewares.d.ts +26 -0
- package/es/middlewares.js +2 -0
- package/es/middlewares.js.map +1 -0
- package/es/shallow.d.ts +15 -0
- package/es/test.d.ts +134 -0
- package/es/test.js +2 -0
- package/es/test.js.map +1 -0
- package/es/types.d.ts +352 -0
- package/es/v5.d.ts +58 -0
- package/es/v5.js +2 -0
- package/es/v5.js.map +1 -0
- package/es/v5_test.d.ts +70 -0
- package/es/v5_test.js +2 -0
- package/es/v5_test.js.map +1 -0
- package/es/v5_types.d.ts +227 -0
- package/impl.d.ts +107 -3
- package/impl.js +1 -1
- package/impl.js.map +1 -1
- package/index.d.ts +14 -0
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/middlewares.d.ts +14 -0
- package/middlewares.js +1 -1
- package/middlewares.js.map +1 -1
- package/package.json +4 -6
- package/shallow.d.ts +14 -0
- package/test.d.ts +17 -0
- package/test.js +1 -1
- package/test.js.map +1 -1
- package/types.d.ts +14 -0
- package/v5.d.ts +14 -0
- package/v5.js +1 -1
- package/v5.js.map +1 -1
- package/v5_test.d.ts +14 -0
- package/v5_test.js +1 -1
- package/v5_test.js.map +1 -1
- package/v5_types.d.ts +14 -0
- package/impl.es.js +0 -2
- package/impl.es.js.map +0 -1
- package/index.es.js +0 -2
- package/index.es.js.map +0 -1
- package/middlewares.es.js +0 -2
- package/middlewares.es.js.map +0 -1
- package/test.es.js +0 -2
- package/test.es.js.map +0 -1
- package/v5.es.js +0 -2
- package/v5.es.js.map +0 -1
- package/v5_test.es.js +0 -2
- package/v5_test.es.js.map +0 -1
package/es/v5_types.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) GlobalSport SAS.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
import { ConflictPolicy, DecoratedActions, NotifyFunc, PromiseResult } from './types';
|
|
16
|
+
export declare type PromiseProvider<S, F extends (...args: any[]) => any, A, P> = (args: Parameters<F>, state: S, props: P, actions: A, abortSignal: AbortSignal) => ReturnType<F> | null;
|
|
17
|
+
/**
|
|
18
|
+
* Simple form of a synchronous action.
|
|
19
|
+
*/
|
|
20
|
+
export declare type SynchAction<S, F extends (...args: any[]) => any, P> = (state: S, args: Parameters<F>, props: P) => S | null;
|
|
21
|
+
/**
|
|
22
|
+
* Advanced synchronous action.
|
|
23
|
+
* Allows to set advanced properties to a synchronous action.
|
|
24
|
+
*/
|
|
25
|
+
export declare type AdvancedSynchAction<S, F extends (...args: any[]) => any, A, P> = {
|
|
26
|
+
/**
|
|
27
|
+
* The action to execute.
|
|
28
|
+
*/
|
|
29
|
+
action: (state: S, args: Parameters<F>, props: P) => S | null;
|
|
30
|
+
/**
|
|
31
|
+
* Debounces the side effects if this parameter is defined.
|
|
32
|
+
*/
|
|
33
|
+
debounceSideEffectsTimeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Debounces the action if this parameter is defined.
|
|
36
|
+
*/
|
|
37
|
+
debounceTimeout?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Action to call when the action is done. Used to trigger other actions (even asynchronous),
|
|
40
|
+
*/
|
|
41
|
+
onActionDone?: (state: S, args: Parameters<F>, props: P, actions: A, notifyWarning: NotifyFunc) => void;
|
|
42
|
+
};
|
|
43
|
+
export declare type PromiseIdMap = {
|
|
44
|
+
[promiseId: string]: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare type InternalLoadingMap<A> = {
|
|
47
|
+
[name: string]: undefined | boolean | PromiseIdMap;
|
|
48
|
+
};
|
|
49
|
+
export declare type LoadingMap<A> = {
|
|
50
|
+
[P in keyof A]?: undefined | boolean;
|
|
51
|
+
};
|
|
52
|
+
export declare type LoadingMapParallelActions<A> = {
|
|
53
|
+
[P in keyof A]?: PromiseIdMap;
|
|
54
|
+
};
|
|
55
|
+
export declare type LoadingProps<A> = {
|
|
56
|
+
loading: boolean;
|
|
57
|
+
loadingMap: LoadingMap<A>;
|
|
58
|
+
loadingParallelMap: LoadingMapParallelActions<A>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Try to abort an action, if the action is <code>abortable</code>.
|
|
62
|
+
* @param actionName The action name
|
|
63
|
+
* @param promiseId If the action conflict type is <code>ConflictType.PARALLEL</code>, the identifier of the promise.
|
|
64
|
+
* @returns <code>true</code> if the action is abortable and an action is ongoing, <code>false</code> otherwise.
|
|
65
|
+
*/
|
|
66
|
+
export declare type AbortActionCallback<A> = (actionName: keyof A, promiseId?: string) => boolean;
|
|
67
|
+
export declare type GetErrorMessage<F extends (...args: any[]) => any, P> = (e: any, args: Parameters<F>, props: P) => string;
|
|
68
|
+
export interface AsynchActionBase<S, F extends (...args: any[]) => any, A, P> {
|
|
69
|
+
/**
|
|
70
|
+
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
71
|
+
*/
|
|
72
|
+
abortable?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The success message to pass to the notifySuccess function passed as property to the StateDecorator.
|
|
75
|
+
*/
|
|
76
|
+
successMessage?: string;
|
|
77
|
+
/**
|
|
78
|
+
* A function that provides the success message to pass to the notifySuccess function passed as property to the StateDecorator.
|
|
79
|
+
*/
|
|
80
|
+
getSuccessMessage?: (result: PromiseResult<ReturnType<F>>, args: Parameters<F>, props: P) => string;
|
|
81
|
+
/**
|
|
82
|
+
* The error message to pass to the notifyError function passed as property to the StateDecorator.
|
|
83
|
+
*/
|
|
84
|
+
errorMessage?: string;
|
|
85
|
+
/**
|
|
86
|
+
* A function that provides the error message to pass to the notifyError function passed as property to the StateDecorator.
|
|
87
|
+
*/
|
|
88
|
+
getErrorMessage?: GetErrorMessage<F, P>;
|
|
89
|
+
/**
|
|
90
|
+
* If set, called with the result of the promise to update the current state.
|
|
91
|
+
*/
|
|
92
|
+
reducer?: (state: S, result: PromiseResult<ReturnType<F>>, args: Parameters<F>, props: P) => S | null;
|
|
93
|
+
/**
|
|
94
|
+
* If set, called with the error of the promise to update the current state.
|
|
95
|
+
*/
|
|
96
|
+
errorReducer?: (state: S, error: any, args: Parameters<F>, props: P) => S | null;
|
|
97
|
+
/**
|
|
98
|
+
* Whether reject the promise instead of handling it.
|
|
99
|
+
*/
|
|
100
|
+
rejectPromiseOnError?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Handle side effects when the request succeeded.
|
|
103
|
+
* @param result The result of the request
|
|
104
|
+
* @param newData The data after the reducer is applied
|
|
105
|
+
* @param args The argument during the call of the request function
|
|
106
|
+
* @param props The props passed to the state decorator
|
|
107
|
+
* @param actions The actions available
|
|
108
|
+
* @param notifyWarning If specified, a notify function to indicate that the action is a semi success (use successMessage / getSuccessMessage otherwise).
|
|
109
|
+
*/
|
|
110
|
+
onDone?: (state: S, result: PromiseResult<ReturnType<F>>, args: Parameters<F>, props: P, actions: A, notifyWarning: NotifyFunc) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Handle side effects when the request failed.
|
|
113
|
+
* @param error The error of the request
|
|
114
|
+
* @param args The argument during the call of the request function
|
|
115
|
+
* @param props The props passed to the state decorator
|
|
116
|
+
* @param actions The actions available
|
|
117
|
+
* @param notifyWarning If specified, a notify function to indicate that the action is a semi failure (use errorMessage / getErrorMessage otherwise).
|
|
118
|
+
*/
|
|
119
|
+
onFail?: (state: S, error: Error, args: Parameters<F>, props: P, actions: A, notifyWarning: NotifyFunc) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Retrieve the state to set as current data before the promise is resolved.
|
|
122
|
+
* If the there's no reducer, this data will be used after the promise is done.
|
|
123
|
+
*/
|
|
124
|
+
preReducer?: (state: S, args: Parameters<F>, props: P) => S | null;
|
|
125
|
+
/**
|
|
126
|
+
* Retrieve the state to set as current data before the promise is resolved.
|
|
127
|
+
* If the there's no reducer, this data will be used after the promise is done.
|
|
128
|
+
*/
|
|
129
|
+
optimisticReducer?: (state: S, args: Parameters<F>, props: P) => S | null;
|
|
130
|
+
/**
|
|
131
|
+
* Policy to apply when a call to an asynchronous action is done but a previous call is still not resolved.
|
|
132
|
+
*/
|
|
133
|
+
conflictPolicy?: ConflictPolicy;
|
|
134
|
+
/**
|
|
135
|
+
* Get an identifier for an action call. Used only when conflictPolicy is ConflictPolicy.PARALLEL.
|
|
136
|
+
* This information will be available in loadingMap. loadingMap[actionName] will be an array of promise identifiers.
|
|
137
|
+
*/
|
|
138
|
+
getPromiseId?: (...args: Parameters<F>) => string;
|
|
139
|
+
/**
|
|
140
|
+
* Number of retries in case of error (failed to fetch).
|
|
141
|
+
* Do not use this if you are creating objects...
|
|
142
|
+
* Default value is 0 (no retry).
|
|
143
|
+
*/
|
|
144
|
+
retryCount?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Seed of delay between each retry in milliseconds.
|
|
147
|
+
* The applied delay is retryDelaySeed * retry count.
|
|
148
|
+
* Default value is 1000 (1 second).
|
|
149
|
+
*/
|
|
150
|
+
retryDelaySeed?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Function to test if the error will trigger an action retry or will fail directly.
|
|
153
|
+
*/
|
|
154
|
+
isTriggerRetryError?: (e: Error) => boolean;
|
|
155
|
+
}
|
|
156
|
+
export interface AsynchActionPromise<S, F extends (...args: any[]) => any, A, P> extends AsynchActionBase<S, F, A, P> {
|
|
157
|
+
/**
|
|
158
|
+
* The request, returns a promise
|
|
159
|
+
*/
|
|
160
|
+
promise: PromiseProvider<S, F, A, P>;
|
|
161
|
+
}
|
|
162
|
+
export interface AsynchActionPromiseGet<S, F extends (...args: any[]) => any, A, P> extends AsynchActionBase<S, F, A, P> {
|
|
163
|
+
/**
|
|
164
|
+
* The request, returns a promise that is a GET request.
|
|
165
|
+
* A shortcut to set:
|
|
166
|
+
* - retryCount: 3
|
|
167
|
+
* - conflictPolicy: ConflictPolicy.REUSE
|
|
168
|
+
*/
|
|
169
|
+
promiseGet: PromiseProvider<S, F, A, P>;
|
|
170
|
+
}
|
|
171
|
+
export declare type AsynchAction<S, F extends (...args: any[]) => any, A, P> = AsynchActionPromise<S, F, A, P> | AsynchActionPromiseGet<S, F, A, P>;
|
|
172
|
+
export declare type StateDecoratorAction<S, F extends (...args: any[]) => any, A, P> = AsynchAction<S, F, A, P> | SynchAction<S, F, P> | AdvancedSynchAction<S, F, A, P>;
|
|
173
|
+
/**
|
|
174
|
+
* S: The type of the state
|
|
175
|
+
* A: The type of the actions to pass to the children (used to check keys only).
|
|
176
|
+
*/
|
|
177
|
+
export declare type StateDecoratorActions<S, A extends DecoratedActions, P = {}> = {
|
|
178
|
+
[Prop in keyof A]: StateDecoratorAction<S, A[Prop], A, P>;
|
|
179
|
+
};
|
|
180
|
+
declare type OnPropsChangeReducer<S, P> = (s: S, newProps: P, updatedIndices: number[]) => S;
|
|
181
|
+
export declare type StateDecoratorOptions<S, A, P = {}> = {
|
|
182
|
+
/**
|
|
183
|
+
* The state decorator name. Use in debug traces to identify the useStateDecorator instance.
|
|
184
|
+
*/
|
|
185
|
+
name?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Show logs in the console in development mode.
|
|
188
|
+
*/
|
|
189
|
+
logEnabled?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* List of action names that are marked as loading at initial time.
|
|
192
|
+
* As a render is done before first actions can be trigerred, some actions can be marked as loading at
|
|
193
|
+
* initial time.
|
|
194
|
+
*/
|
|
195
|
+
initialActionsMarkedLoading?: (keyof A)[];
|
|
196
|
+
/**
|
|
197
|
+
* Get a list of values that will be use as reference values.
|
|
198
|
+
* If they are different (shallow compare), onPropsChangeReducer then onPropsChange will be called.
|
|
199
|
+
*/
|
|
200
|
+
getPropsRefValues?: (props: P) => any[];
|
|
201
|
+
/**
|
|
202
|
+
* Triggered when values of reference from props have changed. Allow to call actions after a prop change.
|
|
203
|
+
*/
|
|
204
|
+
onPropsChange?: (s: S, newProps: any, actions: A, updatedIndices: number[]) => void;
|
|
205
|
+
/**
|
|
206
|
+
* Triggered when values of reference from props have changed. Allow to update state after a prop change.
|
|
207
|
+
* <b>null</b> means no change.
|
|
208
|
+
*/
|
|
209
|
+
onPropsChangeReducer?: OnPropsChangeReducer<S, P>;
|
|
210
|
+
/**
|
|
211
|
+
* The callback function called if an asynchronous function succeeded and a success messsage is defined.
|
|
212
|
+
*/
|
|
213
|
+
notifySuccess?: NotifyFunc;
|
|
214
|
+
/**
|
|
215
|
+
* The callback function called if an asynchronous function fails and an error messsage is defined.
|
|
216
|
+
*/
|
|
217
|
+
notifyError?: NotifyFunc;
|
|
218
|
+
/**
|
|
219
|
+
* The callback function injected in onDone and onFail of asynchronous functions to notify a semi success / failed request.
|
|
220
|
+
*/
|
|
221
|
+
notifyWarning?: NotifyFunc;
|
|
222
|
+
/**
|
|
223
|
+
* Initial actions. They are executed outside of a side effect to trigger asynchronous actions.
|
|
224
|
+
*/
|
|
225
|
+
onMount?: (actions: A, props: P, state: S) => void;
|
|
226
|
+
};
|
|
227
|
+
export {};
|
package/impl.d.ts
CHANGED
|
@@ -1,12 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) GlobalSport SAS.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
import { AsyncAction, SimpleSyncAction, SyncAction, StoreAction, AsyncActionPromise, AsyncActionPromiseGet, PromiseProvider, DecoratedActions, InternalLoadingMap, StoreOptions, InvocationContextActions, OnMountInvocationContext, OnPropsChangeEffectsContext, ContextState, Middleware, MiddlewareFactory, ContextWithDerived, PromiseIdErrorMap, ErrorMap, ErrorParallelMap } from './types';
|
|
16
|
+
export declare type SetStateFunc<S, A> = (newState: S, newLoadingMap: InternalLoadingMap<A>, actionName: keyof A | 'onPropsChange', actionType: 'preEffects' | 'effects' | 'errorEffects' | null, // FIXME
|
|
4
17
|
isAsync: boolean, actionCtx: any, propsChanged: boolean, isInit?: boolean) => void;
|
|
18
|
+
/** @internal */
|
|
19
|
+
export declare type PromiseMap<A> = {
|
|
20
|
+
[name in keyof A]?: {
|
|
21
|
+
[promiseId: string]: {
|
|
22
|
+
promise: Promise<any>;
|
|
23
|
+
refArgs: any[];
|
|
24
|
+
abortController: AbortController;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/** @internal */
|
|
29
|
+
export declare type FutureActions = {
|
|
30
|
+
args: any[];
|
|
31
|
+
resolve: (...args: any[]) => void;
|
|
32
|
+
reject: (...args: any[]) => void;
|
|
33
|
+
timestamp?: number;
|
|
34
|
+
};
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare type ConflictActionsMap<A> = {
|
|
37
|
+
[name in keyof A]?: FutureActions[];
|
|
38
|
+
};
|
|
39
|
+
/** @internal */
|
|
40
|
+
export declare type AsyncActionExecContext<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P> = {
|
|
41
|
+
actionName: keyof A;
|
|
42
|
+
action: AsyncActionPromise<S, F, A, P, DS>;
|
|
43
|
+
stateRef: Ref<S>;
|
|
44
|
+
derivedStateRef: Ref<DerivedState<DS>>;
|
|
45
|
+
propsRef: Ref<P>;
|
|
46
|
+
loadingMapRef: Ref<InternalLoadingMap<A>>;
|
|
47
|
+
errorMapRef: Ref<ErrorParallelMap<A>>;
|
|
48
|
+
promisesRef: Ref<PromiseMap<A>>;
|
|
49
|
+
conflictActionsRef: Ref<ConflictActionsMap<A>>;
|
|
50
|
+
actionsRef: Ref<A>;
|
|
51
|
+
initializedRef: Ref<boolean>;
|
|
52
|
+
options: StoreOptions<S, A, P, any>;
|
|
53
|
+
setState: SetStateFunc<S, A>;
|
|
54
|
+
};
|
|
55
|
+
/** @internal */
|
|
56
|
+
export declare type TimeoutMap<A> = {
|
|
57
|
+
[name in keyof A]?: any;
|
|
58
|
+
};
|
|
5
59
|
export declare type NotifyFunc = (msg: string) => void;
|
|
6
60
|
export declare type CloneFunction = <C>(obj: C) => C;
|
|
7
61
|
export declare type ComparatorFunction = <C>(obj1: C, Obj2: C) => boolean;
|
|
8
62
|
export declare type RetryOnErrorFunction = (error: any) => boolean;
|
|
9
63
|
export declare type AsyncErrorHandler = (error: any, isHandled: boolean, state: any, props: any, actionName: string, args: any[]) => void;
|
|
64
|
+
declare type DerivedStateMap<DS> = {
|
|
65
|
+
[name in keyof DS]?: any[];
|
|
66
|
+
};
|
|
67
|
+
/** @internal */
|
|
68
|
+
export declare type DerivedState<DS> = {
|
|
69
|
+
state: DS;
|
|
70
|
+
deps: DerivedStateMap<DS>;
|
|
71
|
+
};
|
|
10
72
|
/**
|
|
11
73
|
* Global configuration, shared with all stores.
|
|
12
74
|
*/
|
|
@@ -65,6 +127,8 @@ export declare type GlobalConfig = {
|
|
|
65
127
|
*/
|
|
66
128
|
defaultMiddlewares: MiddlewareFactory<any, any, any>[];
|
|
67
129
|
};
|
|
130
|
+
/** @internal */
|
|
131
|
+
export declare const globalConfig: GlobalConfig;
|
|
68
132
|
export declare function setGlobalConfig(overrideConfig: Partial<GlobalConfig>): void;
|
|
69
133
|
/**
|
|
70
134
|
* Type guard function to test if an action is a asynchronous action.
|
|
@@ -80,12 +144,52 @@ export declare function isSimpleSyncAction<S, F extends (...args: any[]) => any,
|
|
|
80
144
|
export declare function isSyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is SyncAction<S, F, A, P, DS, FxRes>;
|
|
81
145
|
export declare function isAsyncGetPromiseAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromise<S, F, A, P, DS, FxRes>;
|
|
82
146
|
export declare function isAsyncGetPromiseGetAction<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: StoreAction<S, F, A, P, DS, FxRes>): action is AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
|
|
147
|
+
/** @internal */
|
|
148
|
+
export declare function computeAsyncActionInput<S, DS, F extends (...args: any[]) => any, A, P, FxRes = S>(action: AsyncAction<S, F, A, P, DS, FxRes>): AsyncActionPromise<S, F, A, P, DS, FxRes>;
|
|
149
|
+
/** @internal */
|
|
150
|
+
export declare function buildLoadingMap<A>(source: InternalLoadingMap<A>, actionName: keyof A, promiseId: string, loading: boolean): InternalLoadingMap<A>;
|
|
151
|
+
/** @internal */
|
|
152
|
+
export declare function updateErrorMap<A>(source: ErrorParallelMap<A>, actionName: keyof A, promiseId: string, error: Error): ErrorParallelMap<A>;
|
|
83
153
|
export declare class ParallelActionError extends Error {
|
|
84
154
|
promiseIds: PromiseIdErrorMap;
|
|
85
155
|
constructor(promiseIds: PromiseIdErrorMap);
|
|
86
156
|
}
|
|
87
157
|
export declare function buildErrorMap<A>(map: ErrorParallelMap<A>): ErrorMap<A>;
|
|
158
|
+
/** @internal */
|
|
159
|
+
export declare function retryPromiseDecorator<S, DS, F extends (...args: any[]) => Promise<any>, A, P>(promiseProvider: PromiseProvider<S, DS, F, A, P>, maxCalls?: number, delay?: number, isRetryError?: (e: Error) => boolean): PromiseProvider<S, DS, F, A, P>;
|
|
88
160
|
export declare type Ref<P> = {
|
|
89
161
|
current: P;
|
|
90
162
|
};
|
|
163
|
+
/** @internal */
|
|
164
|
+
export declare function createRef<U>(init?: U): Ref<U>;
|
|
165
|
+
/** @internal */
|
|
166
|
+
export declare function buildInvocationContextBase<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>): ContextWithDerived<S, DS, P>;
|
|
167
|
+
/** @internal */
|
|
168
|
+
export declare function buildOnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>): OnMountInvocationContext<S, A, P>;
|
|
169
|
+
/** @internal */
|
|
170
|
+
export declare function buildOnPropChangeEffects<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, indices: number[], index: number, isInit: boolean): OnPropsChangeEffectsContext<S, DS, P>;
|
|
171
|
+
/** @internal */
|
|
172
|
+
export declare function addStateToContext<T, S>(ctx: T, stateRef: Ref<S>): T & ContextState<S>;
|
|
173
|
+
/** @internal */
|
|
174
|
+
export declare function addContextActions<T, A>(ctx: T, actionsRef: Ref<A>): T & InvocationContextActions<A>;
|
|
175
|
+
/** @internal */
|
|
176
|
+
export declare function decorateSimpleSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SimpleSyncAction<S, F, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, initializedRef: Ref<boolean>, setState: SetStateFunc<S, A>): (...args: Parameters<F>) => void;
|
|
177
|
+
/** @internal */
|
|
178
|
+
export declare function decorateSyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(actionName: keyof A, action: SyncAction<S, F, A, P, DS>, stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>, initializedRef: Ref<boolean>, timeoutMap: Ref<TimeoutMap<A>>, options: StoreOptions<S, A, P, any>, setState: SetStateFunc<S, A>): (...args: Parameters<F>) => void;
|
|
179
|
+
/** @internal */
|
|
180
|
+
export declare function decorateAsyncAction<S, DS, F extends (...args: any[]) => any, A extends DecoratedActions, P>(context: AsyncActionExecContext<S, DS, F, A, P>): (...args: Parameters<F>) => Promise<any>;
|
|
181
|
+
/** @internal */
|
|
182
|
+
export declare function isLoadingImpl<A, K extends keyof A>(loadingMap: InternalLoadingMap<A>, ...props: (K | [K, string])[]): boolean;
|
|
91
183
|
export declare const DEFAULT_PROMISE_ID = "__def__";
|
|
184
|
+
/** @internal */
|
|
185
|
+
export declare function areSameArgs(args1: any[], args2: any[]): boolean;
|
|
186
|
+
/** @internal */
|
|
187
|
+
export declare function computeDerivedValues<S, A, P, DS>(s: Ref<S>, p: Ref<P>, derivedStateRef: Ref<DerivedState<DS>>, options: StoreOptions<S, A, P, DS>): boolean;
|
|
188
|
+
/** @internal */
|
|
189
|
+
export declare function onPropChange<S, P, A, DS>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, oldProps: P, actionsRef: Ref<A>, options: StoreOptions<S, A, P, DS>, setState: SetStateFunc<S, A>, isInit: boolean): void;
|
|
190
|
+
/** @internal */
|
|
191
|
+
export declare function runMiddlewares<S, A extends DecoratedActions, P>(middlewares: Middleware<S, A, P>[], oldState: S, newState: S, loading: boolean, actionName: keyof A, actionType: 'preEffects' | 'effects' | 'errorEffects' | null, isAsync: boolean, actionCtx: any): {
|
|
192
|
+
newState: S;
|
|
193
|
+
newLoading: boolean;
|
|
194
|
+
};
|
|
195
|
+
export {};
|
package/impl.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(e){var t={exports:{}};return e(t,t.exports),t.exports}Object.defineProperty(exports,"__esModule",{value:!0});var r,n=t((function(e){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.default=e.exports,e.exports.__esModule=!0})),o=t((function(e){e.exports=function(e){if(Array.isArray(e))return n(e)},e.exports.default=e.exports,e.exports.__esModule=!0})),i=t((function(e){e.exports=function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)},e.exports.default=e.exports,e.exports.__esModule=!0})),u=t((function(e){e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0})),c=t((function(e){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0})),a=e(t((function(e){e.exports=function(e){return o(e)||i(e)||u(e)||c()},e.exports.default=e.exports,e.exports.__esModule=!0}))),s=t((function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0})),f=t((function(e){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],n=!0,o=!1,i=void 0;try{for(var u,c=e[Symbol.iterator]();!(n=(u=c.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}},e.exports.default=e.exports,e.exports.__esModule=!0})),l=t((function(e){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0})),p=e(t((function(e){e.exports=function(e,t){return s(e)||f(e,t)||u(e,t)||l()},e.exports.default=e.exports,e.exports.__esModule=!0}))),d=e(t((function(e){function t(e,t,r,n,o,i,u){try{var c=e[i](u),a=c.value}catch(e){return void r(e)}c.done?t(a):Promise.resolve(a).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var u=e.apply(r,n);function c(e){t(u,o,i,c,a,"next",e)}function a(e){t(u,o,i,c,a,"throw",e)}c(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0}))),h=e(t((function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.default=e.exports,e.exports.__esModule=!0}))),y=t((function(e){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.default=e.exports,e.exports.__esModule=!0})),v=e(y),x=t((function(e){function t(r,n){return e.exports=t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},e.exports.default=e.exports,e.exports.__esModule=!0,t(r,n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0})),g=e(t((function(e){e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&x(e,t)},e.exports.default=e.exports,e.exports.__esModule=!0}))),m=t((function(e){function t(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=t=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=t=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),t(r)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0})),b=e(m),w=e(t((function(e){var t=m.default;e.exports=function(e,r){return!r||"object"!==t(r)&&"function"!=typeof r?y(e):r},e.exports.default=e.exports,e.exports.__esModule=!0}))),E=t((function(e){function t(r){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.default=e.exports,e.exports.__esModule=!0,t(r)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0})),_=e(E),P=t((function(e){e.exports=function(e){return-1!==Function.toString.call(e).indexOf("[native code]")},e.exports.default=e.exports,e.exports.__esModule=!0})),S=t((function(e){e.exports=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}},e.exports.default=e.exports,e.exports.__esModule=!0})),O=t((function(e){function t(r,n,o){return S()?(e.exports=t=Reflect.construct,e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=t=function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&x(o,r.prototype),o},e.exports.default=e.exports,e.exports.__esModule=!0),t.apply(null,arguments)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0})),A=e(t((function(e){function t(r){var n="function"==typeof Map?new Map:void 0;return e.exports=t=function(e){if(null===e||!P(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,t)}function t(){return O(e,arguments,E(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),x(t,e)},e.exports.default=e.exports,e.exports.__esModule=!0,t(r)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}))),j=e(t((function(e){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.default=e.exports,e.exports.__esModule=!0}))),L=t((function(e){var t=function(e){var t,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function a(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof v?t:v,i=Object.create(o.prototype),u=new j(n||[]);return i._invoke=function(e,t,r){var n=l;return function(o,i){if(n===d)throw new Error("Generator is already running");if(n===h){if("throw"===o)throw i;return M()}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var c=S(u,r);if(c){if(c===y)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=d;var a=f(e,t,r);if("normal"===a.type){if(n=r.done?h:p,a.arg===y)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n=h,r.method="throw",r.arg=a.arg)}}}(e,r,u),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var l="suspendedStart",p="suspendedYield",d="executing",h="completed",y={};function v(){}function x(){}function g(){}var m={};m[i]=function(){return this};var b=Object.getPrototypeOf,w=b&&b(b(L([])));w&&w!==r&&n.call(w,i)&&(m=w);var E=g.prototype=v.prototype=Object.create(m);function _(e){["next","throw","return"].forEach((function(t){a(e,t,(function(e){return this._invoke(t,e)}))}))}function P(e,t){function r(o,i,u,c){var a=f(e[o],e,i);if("throw"!==a.type){var s=a.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,u,c)}),(function(e){r("throw",e,u,c)})):t.resolve(l).then((function(e){s.value=e,u(s)}),(function(e){return r("throw",e,u,c)}))}c(a.arg)}var o;this._invoke=function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}}function S(e,r){var n=e.iterator[r.method];if(n===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(n,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var i=o.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function A(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function j(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function L(e){if(e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,u=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return u.next=u}}return{next:M}}function M(){return{value:t,done:!0}}return x.prototype=E.constructor=g,g.constructor=x,x.displayName=a(g,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===x||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,a(e,c,"GeneratorFunction")),e.prototype=Object.create(E),e},e.awrap=function(e){return{__await:e}},_(P.prototype),P.prototype[u]=function(){return this},e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var u=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?u:u.next().then((function(e){return e.done?e.value:u.next()}))},_(E),a(E,c,"Generator"),E[i]=function(){return this},E.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=L,j.prototype={constructor:j,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(A),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var u=this.tryEntries[i],c=u.completion;if("root"===u.tryLoc)return o("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(a&&s){if(this.prev<u.catchLoc)return o(u.catchLoc,!0);if(this.prev<u.finallyLoc)return o(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return o(u.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return o(u.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=e,u.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(u)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),A(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;A(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:L(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function M(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=_(e);if(t){var o=_(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return w(this,r)}}function R(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function C(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?R(Object(r),!0).forEach((function(t){j(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):R(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var T={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,t){if(Object.is(e,t))return!0;if("object"!==b(e)||null===e||"object"!==b(t)||null===t)return!1;if(e instanceof Set||t instanceof Set)return!1;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(t,r[o])||!Object.is(e[r[o]],t[r[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function k(e){try{return T.clone(e)}catch(e){var t="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(t),console.error(e.toString())),new Error(t)}}function I(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function G(e,t,r,n){return C(C({},e),{},j({},t,n?C(C({},e[t]||{}),{},j({},r,n)):C(C({},e[t]),{},j({},r,!1))))}function N(e,t,r,n){return C(C({},e),{},j({},t,n?C(C({},e[t]||{}),{},j({},r,n)):C(C({},e[t]),{},j({},r,void 0))))}var D=function(e){g(r,e);var t=M(r);function r(e){var n;return h(this,r),n=t.call(this,"Error"),j(v(n),"promiseIds",void 0),n.promiseIds=e,Object.setPrototypeOf(v(n),r.prototype),n}return r}(A(Error));function F(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){return!0};return 1===t?e:function(o){function i(e,t){return u.apply(this,arguments)}function u(){return(u=d(L.mark((function u(c,a){return L.wrap((function(u){for(;;)switch(u.prev=u.next){case 0:if(null!==a){u.next=2;break}return u.abrupt("return",null);case 2:return u.abrupt("return",a.catch((function(u){return n(u)?c===t?Promise.reject(u):new Promise((function(t,n){setTimeout((function(){var r=e(o);i(c+1,r).then(t).catch(n)}),r*c)})):Promise.reject(u)})));case 3:case"end":return u.stop()}}),u)})))).apply(this,arguments)}var c=e(o);return null===c?null:i(1,c)}}function U(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return{current:e}}function K(e,t,r){var n,o;return{state:e.current,s:e.current,ds:null==t||null===(n=t.current)||void 0===n?void 0:n.state,derived:null==t||null===(o=t.current)||void 0===o?void 0:o.state,props:r.current,p:r.current}}function W(e,t,r,n,o,i){var u=K(e,t,r);return u.indices=n,u.index=o,u.isInit=i,u}function B(e,t,r,n,o){var i=K(e,t,r);return i.args=n,o&&(i.promiseId=o),i}function z(e,t,r,n,o,i){var u=B(e,t,r,n,i);return u.result=o,u.res=o,u}function J(e,t,r,n,o,i,u){var c=H(B(e,t,r,n,u),o);return c.abortSignal=i,c}function V(e,t){var r=e;return r.state=t.current,r.s=t.current,r}function H(e,t){var r=e;return r.actions=t.current,r.a=t.current,r}function Y(e,t,r,n,o){var i,u=H(e,n);V(e,t);var c=null==r||null===(i=r.current)||void 0===i?void 0:i.state;return u.derived=c,u.ds=c,u.notifyWarning=o,u}function $(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function q(e,t,r,n,o,i,u,c,a,s){var f=z(r,n,o,s,void 0),l=!1;if(null!=t.effects){var p=t.effects(f);null===p?l=!0:a(p,void 0,e,"effects",!1,f,!1)}if(!l)if(t.debounceSideEffectsTimeout>0){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){var o;null===(o=t.sideEffects)||void 0===o||o.call(t,Y(f,r,n,i,c.notifyWarning)),delete u.current[e]}),t.debounceSideEffectsTimeout)}else{var h;null===(h=t.sideEffects)||void 0===h||h.call(t,Y(f,r,n,i,c.notifyWarning))}}function Q(e,t,r,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,c=e.propsRef,a=e.promisesRef,s=e.actionsRef,f=e.loadingMapRef,l=e.conflictActionsRef,p=e.actionName,d=e.options,h=e.setState;if(e.initializedRef.current){var y=null,v=z(i,u,c,n,r,t);o.effects&&(y=o.effects(v)),h(y,G(f.current,p,t,!1),p,"effects",!0,v,!1);var x,g=d.notifySuccess||T.notifySuccess;if(g)o.getSuccessMessage&&(x=o.getSuccessMessage(v)),x&&g(x);return delete a.current[p][t],o.sideEffects&&o.sideEffects(Y(v,i,u,s,T.notifyWarning)),re(p,s.current,l.current),r}}function X(e,t,r,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,c=e.propsRef,a=e.actionsRef,s=e.loadingMapRef,f=e.errorMapRef,l=e.promisesRef,p=e.conflictActionsRef,d=e.actionName,h=e.options,y=e.setState;if(e.initializedRef.current){var v=null,x=function(e,t,r,n,o,i){var u=B(e,t,r,n,i);return u.error=o,u.err=o,u}(i,u,c,n,r,t);o.errorEffects&&(v=o.errorEffects(x)),f.current=N(f.current,d,t,r),y(v,G(s.current,d,t,!1),d,"errorEffects",!0,x,!1);var g=!1;(null!=v||o.errorSideEffects||o.isErrorManaged)&&(g=!0);var m,b=h.notifyError||T.notifyError;if(b)o.getErrorMessage&&(m=o.getErrorMessage(x)),void 0===m&&!g&&T.getErrorMessage&&(m=T.getErrorMessage(r)),m&&(g=!0,b(m));return T.asyncErrorHandler(r,g||o.rejectPromiseOnError,i.current,c.current,d,n),delete l.current[d][t],o.errorSideEffects&&o.errorSideEffects(Y(x,i,u,a,T.notifyWarning)),re(d,a.current,p.current),!g||o.rejectPromiseOnError?Promise.reject(r):Promise.resolve()}}var Z="__def__";function ee(e,t){return e.length===t.length&&-1===e.findIndex((function(e,r){return t[r]!==e}))}function te(e,t,n,o,i){var u=o;if(u===r.REUSE){if(ee(e[n][Z].refArgs,i))return e[n][Z].promise;u=r.KEEP_ALL}return new Promise((function(e,o){var c={resolve:e,reject:o,args:k(i),timestamp:Date.now()};switch(u){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:t[n]=[c];break;case r.KEEP_ALL:var a=t[n];a||(t[n]=a=[]),a.push(c);break;case r.PARALLEL:case r.REUSE:}}))}function re(e,t,r){var n=r[e];if(n&&n.length>0){var o=r[e].shift();if(o){var i=t[e].apply(t,a(o.args));null==i?re(e,t,r):i.then((function(n){null===n&&re(e,t,r),o.resolve(n)})).catch((function(e){return o.reject(e)}))}}}exports.DEFAULT_PROMISE_ID=Z,exports.ParallelActionError=D,exports.addContextActions=H,exports.addStateToContext=V,exports.areSameArgs=ee,exports.buildErrorMap=function(e){return Object.keys(e).reduce((function(t,r){var n=e[r];if(null==n[Z]);else if(n[Z])t[r]=n[Z];else{var o=Object.keys(n).reduce((function(e,t){return null!=n[t]&&(e.hasErr=!0,e.map[t]=n[t]),e}),{hasErr:!1,map:{}});o.hasErr&&(t[r]=new D(o.map))}return t}),{})},exports.buildInvocationContextBase=K,exports.buildLoadingMap=G,exports.buildOnMountInvocationContext=function(e,t,r,n){return H(K(e,t,r),n)},exports.buildOnPropChangeEffects=W,exports.computeAsyncActionInput=function(e){return I(e)?C(C({},e),{},{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e},exports.computeDerivedValues=function(e,t,r,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=T.comparator,u=r.current.deps,c=K(e,null,t),a=Object.keys(n.derivedState);return r.current.state=a.reduce((function(e,t){var a=!1,s=u[t],f=n.derivedState[t].getDeps(c);return a=null==s||null!=f.find((function(e,t){return s.length<t||!i(s[t],e)})),o=o||a,u[t]=f,e[t]=a?n.derivedState[t].get(c):r.current.state[t],e}),{}),o},exports.createRef=U,exports.decorateAsyncAction=function(e){var t=e.action,n=e.stateRef,o=e.derivedStateRef,i=e.propsRef,u=e.actionsRef,c=e.promisesRef,a=e.loadingMapRef,s=e.errorMapRef,f=e.initializedRef,l=e.conflictActionsRef,p=e.actionName,d=e.setState;return function(){for(var h,y,v=arguments.length,x=new Array(v),g=0;g<v;g++)x[g]=arguments[g];if(!f.current)return $(p),null;var m=c.current,b=t.conflictPolicy,w=void 0===b?r.KEEP_ALL:b,E=w===r.PARALLEL,_=null;if(E){if(!t.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");_=t.getPromiseId.apply(t,x)}else _=Z;if(!E&&null!==(h=m[p])&&void 0!==h&&h[_])return te(m,l.current,p,w,x);var P=null,S=!1,O=B(n,o,i,x,_);t.preEffects&&(P=t.preEffects(O))&&(S=!0,n.current=P);var A=t.abortable,L=t.retryCount,M=t.retryDelaySeed,R=t.isTriggerRetryError,k=A&&window.AbortController?new AbortController:null,I=F(t.getPromise,L?1+L:1,M,R||T.retryOnErrorFunction),D=null===(y=I(J(n,o,i,x,u,null==k?void 0:k.signal)))||void 0===y?void 0:y.then((function(t){return Q(e,_,t,x)})).catch((function(t){return X(e,_,t,x)}));return null!=D&&(m[p]=C(C({},m[p]||{}),{},j({},_||Z,{abortController:k,promise:D,refArgs:w===r.REUSE&&x.length>0?[].concat(x):[]}))),s.current=N(s.current,p,_,null),d(null!=D||S?n.current:void 0,null==D?void 0:G(a.current,p,_,!0),p,"preEffects",!0,O,!1),D}},exports.decorateSimpleSyncAction=function(e,t,r,n,o,i,u){return function(){if(i.current){for(var c=arguments.length,a=new Array(c),s=0;s<c;s++)a[s]=arguments[s];var f=B(r,n,o,a),l=t(f);u(l,null,e,"effects",!1,f,!1)}else $(e)}},exports.decorateSyncAction=function(e,t,r,n,o,i,u,c,a,s){return function(){for(var f=arguments.length,l=new Array(f),p=0;p<f;p++)l[p]=arguments[p];if(u.current)if(t.debounceTimeout){var d=c.current[e];d&&clearTimeout(d),c.current[e]=setTimeout((function(){delete c.current[e],q(e,t,r,n,o,i,c,a,s,l)}),t.debounceTimeout)}else q(e,t,r,n,o,i,c,a,s,l);else $(e)}},exports.globalConfig=T,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))},exports.isAsyncGetPromiseAction=function(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.isAsyncGetPromiseGetAction=I,exports.isLoadingImpl=function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return r.some((function(t){var r=null,n=Z;if(Array.isArray(t)){var o=p(t,2);r=o[0];var i=o[1];n=void 0===i?Z:i}else r=t;var u=e[r];return null!=u&&(null!=u[n]&&u[n])}))},exports.isSimpleSyncAction=function(e){return"function"==typeof e},exports.isSyncAction=function(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.onPropChange=function(e,t,r,n,o,i,u,c){var a=null!=(null==i?void 0:i.derivedState);if(null!=i.onPropsChange){var s;s=Array.isArray(i.onPropsChange)?i.onPropsChange:[i.onPropsChange];var f=!1,l=U(e.current),p=[],d=T.comparator;s.forEach((function(e,o){var i=e.getDeps;if(i){var a=!1,s=[];if(c){if(!e.onMount)return;a=!0}else{var h=i(n),y=i(r.current);h.length!==y.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),a=!0):h.forEach((function(e,t){d(e,y[t])||(a=!0,s.push(t))}))}if(a){var v,x,g=W(l,t,r,s,o,c),m=null!==(v=null===(x=e.effects)||void 0===x?void 0:x.call(e,g))&&void 0!==v?v:null;null!=m&&(f=!0,l.current=m,u(l.current,void 0,"onPropsChange","effects",!1,g,!0,c)),e.sideEffects&&p.push({index:o,indices:s,ctx:g})}}})),!f&&a&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(e){s[e.index].sideEffects(C(C({},V(H(e.ctx,o),l)),{},{indices:e.indices}))}))}else null!=(null==i?void 0:i.derivedState)&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0)},exports.retryPromiseDecorator=F,exports.runMiddlewares=function(e,t,r,n,o,i,u,c){if("onPropsChange"===o&&void 0===r)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,t){var r=t.effects({isAsync:u,name:o,type:i,context:c},e.oldState,e.newState,n);return{newState:(null==r?void 0:r.state)||e.newState,oldState:null!=r&&r.state?e.newState:e.oldState,loading:null==(null==r?void 0:r.loading)?e.loading:r.loading}}),{oldState:t,newState:r,loading:n});return{newLoading:a.loading,newState:a.newState}}return{newState:r,newLoading:n}},exports.setGlobalConfig=function(e){Object.keys(e).forEach((function(t){null!=e[t]&&(T[t]=e[t])}))},exports.updateErrorMap=N;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(r,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(r,t)};var r,t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(c,u)}a((n=n.apply(e,r||[])).next())}))}function o(e,r){var t,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,n=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(var o=0;o<t.length;o++)if(!Object.prototype.hasOwnProperty.call(r,t[o])||!Object.is(e[t[o]],r[t[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function a(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function s(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=!1,a)),u))}function l(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=void 0,a)),u))}var f=function(r){function t(e){var n=r.call(this,"Error")||this;return n.promiseIds=e,Object.setPrototypeOf(n,t.prototype),n}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,r),t}(Error);function d(e,r,t,i){return void 0===r&&(r=1),void 0===t&&(t=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,s){return n(this,void 0,void 0,(function(){return o(this,(function(n){return null===s?[2,null]:[2,s.catch((function(n){return i(n)?a===r?Promise.reject(n):new Promise((function(r,n){setTimeout((function(){var t=e(c);u(a+1,t).then(r).catch(n)}),t*a)})):Promise.reject(n)}))]}))}))}(1,u)}}function p(e){return void 0===e&&(e=null),{current:e}}function v(e,r,t){var n,o;return{state:e.current,s:e.current,ds:null===(n=null==r?void 0:r.current)||void 0===n?void 0:n.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:t.current,p:t.current}}function g(e,r,t,n,o,i){var c=v(e,r,t);return c.indices=n,c.index=o,c.isInit=i,c}function y(e,r,t,n,o){var i=v(e,r,t);return i.args=n,o&&(i.promiseId=o),i}function h(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.result=o,c.res=o,c}function E(e,r,t,n,o,i,c){var u=P(y(e,r,t,n,c),o);return u.abortSignal=i,u}function m(e,r){var t=e;return t.state=r.current,t.s=r.current,t}function P(e,r){var t=e;return t.actions=r.current,t.a=r.current,t}function S(e,r,t,n,o){var i,c=P(e,n);m(e,r);var u=null===(i=null==t?void 0:t.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function b(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function w(e,r,t,n,o,i,c,u,a,s){var l,f=h(t,n,o,s,void 0),d=!1;if(null!=r.effects){var p=r.effects(f);null===p?d=!0:a(p,void 0,e,"effects",!1,f,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var v=c.current[e];v&&clearTimeout(v),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,S(f,t,n,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(l=r.sideEffects)||void 0===l||l.call(r,S(f,t,n,i,u.notifyWarning))}function A(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,d=e.loadingMapRef,p=e.conflictActionsRef,v=e.actionName,g=e.options,y=e.setState;if(e.initializedRef.current){var E=null,m=h(i,u,a,n,t,r);o.effects&&(E=o.effects(m)),y(E,s(d.current,v,r,!1),v,"effects",!0,m,!1);var P=g.notifySuccess||c.notifySuccess;if(P){var b=void 0;o.getSuccessMessage&&(b=o.getSuccessMessage(m)),b&&P(b)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(S(m,i,u,f,c.notifyWarning)),L(v,f.current,p.current),t}}function x(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,d=e.loadingMapRef,p=e.errorMapRef,v=e.promisesRef,g=e.conflictActionsRef,h=e.actionName,E=e.options,m=e.setState;if(e.initializedRef.current){var P=null,b=function(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.error=o,c.err=o,c}(i,u,a,n,t,r);o.errorEffects&&(P=o.errorEffects(b)),p.current=l(p.current,h,r,t),m(P,s(d.current,h,r,!1),h,"errorEffects",!0,b,!1);var w=!1;(null!=P||o.errorSideEffects||o.isErrorManaged)&&(w=!0);var A=E.notifyError||c.notifyError;if(A){var x=void 0;o.getErrorMessage&&(x=o.getErrorMessage(b)),void 0===x&&!w&&c.getErrorMessage&&(x=c.getErrorMessage(t)),x&&(w=!0,A(x))}return c.asyncErrorHandler(t,w||o.rejectPromiseOnError,i.current,a.current,h,n),delete v.current[h][r],o.errorSideEffects&&o.errorSideEffects(S(b,i,u,f,c.notifyWarning)),L(h,f.current,g.current),!w||o.rejectPromiseOnError?Promise.reject(t):Promise.resolve()}}var O="__def__";function R(e,r){return e.length===r.length&&-1===e.findIndex((function(e,t){return r[t]!==e}))}function C(e,t,n,o,i){var c=o;if(c===r.REUSE){if(R(e[n][O].refArgs,i))return e[n][O].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var a={resolve:e,reject:o,args:u(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:t[n]=[a];break;case r.KEEP_ALL:var s=t[n];s||(t[n]=s=[]),s.push(a);break;case r.PARALLEL:case r.REUSE:}}))}function L(e,r,t){var n=t[e];if(n&&n.length>0){var o=t[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?L(e,r,t):i.then((function(n){null===n&&L(e,r,t),o.resolve(n)})).catch((function(e){return o.reject(e)}))}}}exports.DEFAULT_PROMISE_ID=O,exports.ParallelActionError=f,exports.addContextActions=P,exports.addStateToContext=m,exports.areSameArgs=R,exports.buildErrorMap=function(e){return Object.keys(e).reduce((function(r,t){var n=e[t];if(null==n[O]);else if(n[O])r[t]=n[O];else{var o=Object.keys(n).reduce((function(e,r){return null!=n[r]&&(e.hasErr=!0,e.map[r]=n[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[t]=new f(o.map))}return r}),{})},exports.buildInvocationContextBase=v,exports.buildLoadingMap=s,exports.buildOnMountInvocationContext=function(e,r,t,n){return P(v(e,r,t),n)},exports.buildOnPropChangeEffects=g,exports.computeAsyncActionInput=function(e){return a(e)?t(t({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e},exports.computeDerivedValues=function(e,r,t,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=c.comparator,u=t.current.deps,a=v(e,null,r),s=Object.keys(n.derivedState);return t.current.state=s.reduce((function(e,r){var c=!1,s=u[r],l=n.derivedState[r].getDeps(a);return c=null==s||null!=l.find((function(e,r){return s.length<r||!i(s[r],e)})),o=o||c,u[r]=l,e[r]=c?n.derivedState[r].get(a):t.current.state[r],e}),{}),o},exports.createRef=p,exports.decorateAsyncAction=function(e){var n=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,p=e.promisesRef,v=e.loadingMapRef,g=e.errorMapRef,h=e.initializedRef,m=e.conflictActionsRef,P=e.actionName,S=e.setState;return function(){for(var w,R,L,j=[],_=0;_<arguments.length;_++)j[_]=arguments[_];if(!h.current)return b(P),null;var M=p.current,T=n.conflictPolicy,k=void 0===T?r.KEEP_ALL:T,I=k===r.PARALLEL,D=null;if(I){if(!n.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");D=n.getPromiseId.apply(n,j)}else D=O;if(!I&&(null===(R=M[P])||void 0===R?void 0:R[D]))return C(M,m.current,P,k,j);var G=null,N=!1,K=y(o,u,a,j,D);n.preEffects&&(G=n.preEffects(K))&&(N=!0,o.current=G);var U=n.abortable,W=n.retryCount,F=n.retryDelaySeed,z=n.isTriggerRetryError,J=U&&window.AbortController?new AbortController:null,V=d(n.getPromise,W?1+W:1,F,z||c.retryOnErrorFunction),H=null===(L=V(E(o,u,a,j,f,null==J?void 0:J.signal)))||void 0===L?void 0:L.then((function(r){return A(e,D,r,j)})).catch((function(r){return x(e,D,r,j)}));return null!=H&&(M[P]=t(t({},M[P]||{}),((w={})[D||O]={abortController:J,promise:H,refArgs:k===r.REUSE&&j.length>0?i([],j,!0):[]},w))),g.current=l(g.current,P,D,null),S(null!=H||N?o.current:void 0,null==H?void 0:s(v.current,P,D,!0),P,"preEffects",!0,K,!1),H}},exports.decorateSimpleSyncAction=function(e,r,t,n,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var s=y(t,n,o,u),l=r(s);c(l,null,e,"effects",!1,s,!1)}else b(e)}},exports.decorateSyncAction=function(e,r,t,n,o,i,c,u,a,s){return function(){for(var l=[],f=0;f<arguments.length;f++)l[f]=arguments[f];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],w(e,r,t,n,o,i,u,a,s,l)}),r.debounceTimeout)}else w(e,r,t,n,o,i,u,a,s,l);else b(e)}},exports.globalConfig=c,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))},exports.isAsyncGetPromiseAction=function(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.isAsyncGetPromiseGetAction=a,exports.isLoadingImpl=function(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];return r.some((function(r){var t,n=null,o=O;Array.isArray(r)?(n=r[0],o=void 0===(t=r[1])?O:t):n=r;var i=e[n];return null!=i&&(null!=i[o]&&i[o])}))},exports.isSimpleSyncAction=function(e){return"function"==typeof e},exports.isSyncAction=function(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.onPropChange=function(e,r,n,o,i,u,a,s){var l=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var f;f=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=p(e.current),y=[],h=c.comparator;f.forEach((function(e,t){var i,c,u=e.getDeps;if(u){var l=!1,f=[];if(s){if(!e.onMount)return;l=!0}else{var p=u(o),E=u(n.current);p.length!==E.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),l=!0):p.forEach((function(e,r){h(e,E[r])||(l=!0,f.push(r))}))}if(l){var m=g(v,r,n,f,t,s),P=null!==(c=null===(i=e.effects)||void 0===i?void 0:i.call(e,m))&&void 0!==c?c:null;null!=P&&(d=!0,v.current=P,a(v.current,void 0,"onPropsChange","effects",!1,m,!0,s)),e.sideEffects&&y.push({index:t,indices:f,ctx:m})}}})),!d&&l&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),y.length>0&&y.forEach((function(e){f[e.index].sideEffects(t(t({},m(P(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)},exports.retryPromiseDecorator=d,exports.runMiddlewares=function(e,r,t,n,o,i,c,u){if("onPropsChange"===o&&void 0===t)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var t=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,n);return{newState:(null==t?void 0:t.state)||e.newState,oldState:(null==t?void 0:t.state)?e.newState:e.oldState,loading:null==(null==t?void 0:t.loading)?e.loading:t.loading}}),{oldState:r,newState:t,loading:n});return{newLoading:a.loading,newState:a.newState}}return{newState:t,newLoading:n}},exports.setGlobalConfig=function(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))},exports.updateErrorMap=l;
|
|
2
2
|
//# sourceMappingURL=impl.js.map
|