state-decorator 7.0.0-beta.9-dev → 7.0.0-rc10
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 +71 -93
- package/development.d.ts +10 -0
- package/development.js +2 -0
- package/development.js.map +1 -0
- package/es/development.d.ts +10 -0
- package/es/development.js +2 -0
- package/es/development.js.map +1 -0
- package/es/graph.d.ts +8 -0
- package/es/helpers.d.ts +10 -9
- package/es/helpers.js +1 -162
- package/es/helpers.js.map +1 -1
- package/es/impl.d.ts +20 -32
- package/es/impl.js +1 -963
- package/es/impl.js.map +1 -1
- package/es/index.d.ts +19 -24
- package/es/index.js +1 -1013
- package/es/index.js.map +1 -1
- package/es/middlewares.d.ts +0 -23
- package/es/middlewares.js +1 -519
- package/es/middlewares.js.map +1 -1
- package/es/shallow.d.ts +0 -14
- package/es/test.d.ts +7 -21
- package/es/test.js +1 -349
- package/es/test.js.map +1 -1
- package/es/types.d.ts +73 -72
- package/es/v5.d.ts +5 -18
- package/es/v5.js +1 -301
- package/es/v5.js.map +1 -1
- package/es/v5_test.d.ts +4 -17
- package/es/v5_test.js +1 -392
- package/es/v5_test.js.map +1 -1
- package/es/v5_types.d.ts +15 -29
- package/es/v6.d.ts +7 -3
- package/es/v6.js +1 -96
- package/es/v6.js.map +1 -1
- package/graph.d.ts +8 -0
- package/helpers.d.ts +10 -9
- package/helpers.js +1 -174
- package/helpers.js.map +1 -1
- package/impl.d.ts +20 -32
- package/impl.js +1 -996
- package/impl.js.map +1 -1
- package/index.d.ts +19 -24
- package/index.js +1 -1044
- package/index.js.map +1 -1
- package/middlewares.d.ts +0 -23
- package/middlewares.js +1 -526
- package/middlewares.js.map +1 -1
- package/package.json +1 -1
- package/shallow.d.ts +0 -14
- package/test.d.ts +7 -21
- package/test.js +1 -358
- package/test.js.map +1 -1
- package/types.d.ts +73 -72
- package/v5.d.ts +5 -18
- package/v5.js +1 -322
- package/v5.js.map +1 -1
- package/v5_test.d.ts +4 -17
- package/v5_test.js +1 -416
- package/v5_test.js.map +1 -1
- package/v5_types.d.ts +15 -29
- package/v6.d.ts +7 -3
- package/v6.js +1 -120
- package/v6.js.map +1 -1
package/es/types.d.ts
CHANGED
|
@@ -1,45 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
export declare type PromiseResult<Type> = Type extends Promise<infer X> ? X : null;
|
|
16
|
-
export declare type NotifyFunc = (msg: string) => void;
|
|
17
|
-
export declare type PromiseIdMap = {
|
|
1
|
+
export type PromiseResult<Type> = Type extends Promise<infer X> ? X : null;
|
|
2
|
+
export type NotifyFunc = (msg: string) => void;
|
|
3
|
+
export type PromiseIdMap = {
|
|
18
4
|
[promiseId: string]: boolean;
|
|
19
5
|
};
|
|
20
|
-
export
|
|
6
|
+
export type LoadingMap<A> = {
|
|
21
7
|
[pId in keyof A]?: boolean;
|
|
22
8
|
};
|
|
23
|
-
export
|
|
9
|
+
export type LoadingParallelMap<A> = {
|
|
24
10
|
[P in keyof A]?: PromiseIdMap;
|
|
25
11
|
};
|
|
26
|
-
export
|
|
27
|
-
export
|
|
12
|
+
export type InternalLoadingMap<A> = LoadingParallelMap<A>;
|
|
13
|
+
export type LoadingProps<A> = {
|
|
28
14
|
loading: boolean;
|
|
29
15
|
loadingMap: LoadingMap<A>;
|
|
30
16
|
loadingParallelMap: LoadingParallelMap<A>;
|
|
31
17
|
};
|
|
32
|
-
export
|
|
33
|
-
export
|
|
18
|
+
export type LoadingMapProps<A> = Pick<LoadingProps<A>, 'loadingMap'>;
|
|
19
|
+
export type PromiseIdErrorMap = {
|
|
34
20
|
[promiseId: string]: Error;
|
|
35
21
|
};
|
|
36
|
-
export
|
|
22
|
+
export type ErrorMap<A> = {
|
|
37
23
|
[pId in keyof A]?: Error;
|
|
38
24
|
};
|
|
39
|
-
export
|
|
25
|
+
export type ErrorParallelMap<A> = {
|
|
40
26
|
[P in keyof A]?: PromiseIdErrorMap;
|
|
41
27
|
};
|
|
42
|
-
export
|
|
28
|
+
export type ErrorProps<A> = {
|
|
43
29
|
errorMap: ErrorMap<A>;
|
|
44
30
|
};
|
|
45
31
|
export interface DecoratedActions {
|
|
@@ -76,12 +62,12 @@ export declare enum ConflictPolicy {
|
|
|
76
62
|
*/
|
|
77
63
|
REUSE = "reuse"
|
|
78
64
|
}
|
|
79
|
-
export
|
|
65
|
+
export type PromiseProvider<S, DS, F extends (...args: any[]) => any, A, P> = (ctx: GetPromiseInvocationContext<S, DS, F, P, A>) => ReturnType<F> | null;
|
|
80
66
|
/**
|
|
81
67
|
* Simple form of a synchronous action.
|
|
82
68
|
*/
|
|
83
|
-
export
|
|
84
|
-
export
|
|
69
|
+
export type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = Partial<S>> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
70
|
+
export type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
85
71
|
/**
|
|
86
72
|
* Function that update the state when the action is called.
|
|
87
73
|
*/
|
|
@@ -105,75 +91,75 @@ export declare type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, F
|
|
|
105
91
|
* @param promiseId If the action conflict type is <code>ConflictType.PARALLEL</code>, the identifier of the promise.
|
|
106
92
|
* @returns <code>true</code> if the action is abortable and an action is ongoing, <code>false</code> otherwise.
|
|
107
93
|
*/
|
|
108
|
-
export
|
|
109
|
-
export
|
|
110
|
-
export
|
|
94
|
+
export type AbortActionCallback<A> = (actionName: keyof A, promiseId?: string) => boolean;
|
|
95
|
+
export type GetErrorMessage<S, DS, F extends (...args: any[]) => any, P> = (ctx: ErrorMessageInvocationContext<S, DS, F, P>) => string | null;
|
|
96
|
+
export type ContextState<S> = {
|
|
111
97
|
state: S;
|
|
112
98
|
s: S;
|
|
113
99
|
};
|
|
114
|
-
export
|
|
100
|
+
export type ContextDerivedStateState<DS> = {
|
|
115
101
|
derived: DS;
|
|
116
102
|
ds: DS;
|
|
117
103
|
};
|
|
118
|
-
export
|
|
104
|
+
export type ContextBase<S, P> = ContextState<S> & {
|
|
119
105
|
props: P;
|
|
120
106
|
p: P;
|
|
121
107
|
};
|
|
122
|
-
export
|
|
123
|
-
export
|
|
108
|
+
export type ContextWithDerived<S, DS, P> = ContextBase<S, P> & ContextDerivedStateState<DS>;
|
|
109
|
+
export type InvocationContextActions<A> = {
|
|
124
110
|
actions: A;
|
|
125
111
|
a: A;
|
|
126
112
|
};
|
|
127
|
-
export
|
|
113
|
+
export type WarningNotifyFunc = {
|
|
128
114
|
notifyWarning?: NotifyFunc;
|
|
129
115
|
};
|
|
130
|
-
export
|
|
116
|
+
export type InvocationContext<S, DS, F extends (...args: any[]) => any, P> = ContextWithDerived<S, DS, P> & {
|
|
131
117
|
args: Parameters<F>;
|
|
132
118
|
promiseId: string;
|
|
133
119
|
};
|
|
134
|
-
export
|
|
120
|
+
export type EffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
135
121
|
result: PromiseResult<ReturnType<F>>;
|
|
136
122
|
res: PromiseResult<ReturnType<F>>;
|
|
137
123
|
};
|
|
138
|
-
export
|
|
124
|
+
export type GetPromiseInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = InvocationContextActions<A> & InvocationContext<S, DS, F, P> & {
|
|
139
125
|
abortSignal: AbortSignal;
|
|
140
126
|
};
|
|
141
|
-
export
|
|
127
|
+
export type ErrorEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
142
128
|
error: Error;
|
|
143
129
|
err: Error;
|
|
144
130
|
};
|
|
145
|
-
export
|
|
146
|
-
export
|
|
147
|
-
export
|
|
148
|
-
export
|
|
131
|
+
export type SuccessMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = EffectsInvocationContext<S, DS, F, P>;
|
|
132
|
+
export type ErrorMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = ErrorEffectsInvocationContext<S, DS, F, P>;
|
|
133
|
+
export type ClearErrorFunc<A> = (actionName: keyof A, promiseId?: string) => void;
|
|
134
|
+
export type ClearError<A> = {
|
|
149
135
|
clearError: ClearErrorFunc<A>;
|
|
150
136
|
};
|
|
151
|
-
export
|
|
152
|
-
export
|
|
153
|
-
export
|
|
154
|
-
export
|
|
155
|
-
export
|
|
137
|
+
export type SideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = EffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc & ClearError<A>;
|
|
138
|
+
export type ErrorSideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = ErrorEffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc;
|
|
139
|
+
export type OnMountInvocationContext<S, A, P> = ContextBase<S, P> & InvocationContextActions<A>;
|
|
140
|
+
export type AbortedActions<A> = Partial<Record<keyof A, string[]>>;
|
|
141
|
+
export type OnUnMountInvocationContext<S, A, P> = ContextBase<S, P> & {
|
|
156
142
|
abortedActions: AbortedActions<A>;
|
|
157
143
|
};
|
|
158
|
-
export
|
|
159
|
-
export
|
|
144
|
+
export type EffectsType = 'preEffects' | 'effects' | 'errorEffects' | 'optimisticEffects' | null;
|
|
145
|
+
export type MiddlewareActionContext<S, A, P> = {
|
|
160
146
|
name: keyof A;
|
|
161
147
|
type: EffectsType;
|
|
162
148
|
isAsync: boolean;
|
|
163
149
|
context: InvocationContext<S, any, any, P>;
|
|
164
150
|
};
|
|
165
|
-
export
|
|
151
|
+
export type MiddlewareStoreContext<S, A extends DecoratedActions, P> = {
|
|
166
152
|
actions: StoreActions<S, A, P, any, any>;
|
|
167
153
|
state: S;
|
|
168
154
|
setState: (s: S) => void;
|
|
169
155
|
options: StoreOptions<S, A, P, any>;
|
|
170
156
|
};
|
|
171
|
-
export
|
|
157
|
+
export type MiddlewareFactory<S, A extends DecoratedActions, P> = () => Middleware<S, A, P>;
|
|
172
158
|
/**
|
|
173
159
|
* A state change middleware.
|
|
174
160
|
* Allow to listen and change a state change on the fly.
|
|
175
161
|
*/
|
|
176
|
-
export
|
|
162
|
+
export type Middleware<S, A extends DecoratedActions, P> = {
|
|
177
163
|
/**
|
|
178
164
|
* Initializes the middleware. Called when the store is initializing.
|
|
179
165
|
*/
|
|
@@ -190,7 +176,7 @@ export declare type Middleware<S, A extends DecoratedActions, P> = {
|
|
|
190
176
|
*/
|
|
191
177
|
destroy: () => void;
|
|
192
178
|
};
|
|
193
|
-
export
|
|
179
|
+
export type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
194
180
|
/**
|
|
195
181
|
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
196
182
|
*/
|
|
@@ -276,13 +262,13 @@ export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P,
|
|
|
276
262
|
*/
|
|
277
263
|
isTriggerRetryError?: (e: Error) => boolean;
|
|
278
264
|
};
|
|
279
|
-
export
|
|
265
|
+
export type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
280
266
|
/**
|
|
281
267
|
* The request, returns a promise
|
|
282
268
|
*/
|
|
283
269
|
getPromise: PromiseProvider<S, DS, F, A, P>;
|
|
284
270
|
};
|
|
285
|
-
export
|
|
271
|
+
export type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
286
272
|
/**
|
|
287
273
|
* The request, returns a promise that is a GET request.
|
|
288
274
|
* A shortcut to set:
|
|
@@ -291,43 +277,48 @@ export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any,
|
|
|
291
277
|
*/
|
|
292
278
|
getGetPromise: PromiseProvider<S, DS, F, A, P>;
|
|
293
279
|
};
|
|
294
|
-
export
|
|
295
|
-
export
|
|
280
|
+
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>;
|
|
281
|
+
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>;
|
|
296
282
|
/**
|
|
297
283
|
* S: The type of the state
|
|
298
284
|
* A: The type of the actions to pass to the children (used to check keys only).
|
|
299
285
|
*/
|
|
300
|
-
export
|
|
286
|
+
export type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
301
287
|
[Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
|
|
302
288
|
};
|
|
303
|
-
export
|
|
289
|
+
export type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
|
|
304
290
|
indices: number[];
|
|
305
291
|
index: number;
|
|
306
292
|
isInit: boolean;
|
|
307
293
|
getInitialState: (p: P) => S;
|
|
308
294
|
};
|
|
309
|
-
export
|
|
295
|
+
export type OnPropsChangeSideEffectsContext<S, P, A, DS = {}> = OnPropsChangeEffectsContext<S, DS, P> & {
|
|
310
296
|
actions: A;
|
|
311
297
|
a: A;
|
|
312
298
|
};
|
|
313
|
-
|
|
299
|
+
type DerivedStateOption<S, P, DS> = {
|
|
314
300
|
[k in keyof DS]: {
|
|
315
|
-
getDeps
|
|
316
|
-
get: (ctx: ContextBase<S, P>) => DS[k];
|
|
301
|
+
getDeps?: (ctx: ContextBase<S, P>) => any[];
|
|
302
|
+
get: (ctx: ContextBase<S, P> & ContextDerivedStateState<DS>) => DS[k];
|
|
303
|
+
derivedDeps?: (keyof DS)[];
|
|
317
304
|
};
|
|
318
305
|
};
|
|
319
|
-
export
|
|
306
|
+
export type OnPropsChangeOptions<S, DS, A, P, FxRes = Partial<S>> = {
|
|
320
307
|
onMount?: boolean;
|
|
321
308
|
onMountDeferred?: boolean;
|
|
322
309
|
getDeps: (p: P) => any[];
|
|
323
|
-
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) =>
|
|
310
|
+
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => FxRes;
|
|
324
311
|
sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A>) => void;
|
|
325
312
|
};
|
|
326
|
-
export
|
|
313
|
+
export type StoreOptions<S, A, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
327
314
|
/**
|
|
328
315
|
* The state decorator name. Use in debug traces to identify the useStateDecorator instance.
|
|
329
316
|
*/
|
|
330
317
|
name?: string;
|
|
318
|
+
/**
|
|
319
|
+
* In development only (NODE_ENV="development"), activates state changes traces on the console.
|
|
320
|
+
*/
|
|
321
|
+
logEnabled?: boolean;
|
|
331
322
|
/**
|
|
332
323
|
* Indicates that all asynchronous actions errors are managed externally.
|
|
333
324
|
* Same as setting isErrorManaged to true for all actions.
|
|
@@ -342,7 +333,7 @@ export declare type StoreOptions<S, A, P = {}, DS = {}> = {
|
|
|
342
333
|
/**
|
|
343
334
|
* One or several configurations of inbound properties change managements.
|
|
344
335
|
*/
|
|
345
|
-
onPropsChange?: OnPropsChangeOptions<S, DS, A, P> | OnPropsChangeOptions<S, DS, A, P>[];
|
|
336
|
+
onPropsChange?: OnPropsChangeOptions<S, DS, A, P, FxRes> | OnPropsChangeOptions<S, DS, A, P, FxRes>[];
|
|
346
337
|
/**
|
|
347
338
|
* The callback function called if an asynchronous function succeeded and a success messsage is defined.
|
|
348
339
|
*/
|
|
@@ -372,10 +363,20 @@ export declare type StoreOptions<S, A, P = {}, DS = {}> = {
|
|
|
372
363
|
* Compute derived state
|
|
373
364
|
*/
|
|
374
365
|
derivedState?: DerivedStateOption<S, P, DS>;
|
|
366
|
+
/**
|
|
367
|
+
* Disable auto spread of state on effects (v6 behavior).
|
|
368
|
+
*/
|
|
369
|
+
fullStateEffects?: boolean;
|
|
375
370
|
};
|
|
376
|
-
|
|
377
|
-
getInitialState: S | ((p: P) => S);
|
|
371
|
+
type StoreConfigBase<S, A extends DecoratedActions, P = {}, DS = {}> = {
|
|
378
372
|
actions: StoreActions<S, A, P, DS>;
|
|
379
373
|
middlewares?: MiddlewareFactory<S, A, P>[];
|
|
380
374
|
} & StoreOptions<S, A, P, DS>;
|
|
375
|
+
type StoreConfigObj<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
376
|
+
initialState: S;
|
|
377
|
+
};
|
|
378
|
+
type StoreConfigFunc<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigBase<S, A, P, DS> & {
|
|
379
|
+
getInitialState: (p: P) => S;
|
|
380
|
+
};
|
|
381
|
+
export type StoreConfig<S, A extends DecoratedActions, P = {}, DS = {}> = StoreConfigObj<S, A, P, DS> | StoreConfigFunc<S, A, P, DS>;
|
|
381
382
|
export {};
|
package/es/v5.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 { DecoratedActions, MiddlewareFactory } from './types';
|
|
16
|
-
import { setGlobalConfig, ConflictPolicy } from './index';
|
|
17
|
-
import { AdvancedSynchAction, AsynchActionPromiseGet, StateDecoratorAction, StateDecoratorActions, StateDecoratorOptions, AsynchActionPromise, SynchAction, LoadingMap, LoadingProps, LoadingMapParallelActions, AsynchAction } from './v5_types';
|
|
18
|
-
export { AdvancedSynchAction, AsynchActionPromiseGet, StateDecoratorAction, StateDecoratorActions, StateDecoratorOptions, AsynchActionPromise, SynchAction, LoadingMap, LoadingMapParallelActions, LoadingProps, ConflictPolicy, setGlobalConfig, };
|
|
1
|
+
import type { DecoratedActions, MiddlewareFactory } from './types';
|
|
2
|
+
import { ConflictPolicy } from './types';
|
|
3
|
+
import { setGlobalConfig } from './index';
|
|
4
|
+
import type { AdvancedSynchAction, AsynchActionPromiseGet, StateDecoratorAction, StateDecoratorActions, StateDecoratorOptions, AsynchActionPromise, SynchAction, LoadingMap, LoadingProps, LoadingMapParallelActions, AsynchAction } from './v5_types';
|
|
5
|
+
export type { AdvancedSynchAction, AsynchActionPromiseGet, StateDecoratorAction, StateDecoratorActions, StateDecoratorOptions, AsynchActionPromise, SynchAction, LoadingMap, LoadingMapParallelActions, LoadingProps, ConflictPolicy, setGlobalConfig, };
|
|
19
6
|
/**
|
|
20
7
|
* Type guard function to test if an action is a asynchronous action.
|
|
21
8
|
*/
|
package/es/v5.js
CHANGED
|
@@ -1,302 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ConflictPolicy, setGlobalConfig } from './index';
|
|
3
|
-
import { useReducer, useRef, useLayoutEffect, useEffect } from 'react';
|
|
4
|
-
import { logDetailedEffects } from './middlewares';
|
|
5
|
-
|
|
6
|
-
/*! *****************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
|
|
21
|
-
var __assign = function() {
|
|
22
|
-
__assign = Object.assign || function __assign(t) {
|
|
23
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
24
|
-
s = arguments[i];
|
|
25
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
};
|
|
29
|
-
return __assign.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/*! *****************************************************************************
|
|
33
|
-
Copyright (c) GlobalSport SAS.
|
|
34
|
-
|
|
35
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
36
|
-
purpose with or without fee is hereby granted.
|
|
37
|
-
|
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
39
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
40
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
41
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
42
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
43
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
44
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
45
|
-
***************************************************************************** */
|
|
46
|
-
function isAsyncActionPromise(action) {
|
|
47
|
-
return !(action instanceof Function) && action.hasOwnProperty('promise');
|
|
48
|
-
}
|
|
49
|
-
function isAsyncActionPromiseGet(action) {
|
|
50
|
-
return !(action instanceof Function) && action.hasOwnProperty('promiseGet');
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
54
|
-
*/
|
|
55
|
-
function isAsyncAction(action) {
|
|
56
|
-
return !(action instanceof Function) && (action.hasOwnProperty('promise') || action.hasOwnProperty('promiseGet'));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
60
|
-
*/
|
|
61
|
-
function isAsyncPromiseGetAction(action) {
|
|
62
|
-
return !(action instanceof Function) && !(action.hasOwnProperty('promise') && action.hasOwnProperty('promiseGet'));
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Type guard function to test if an action is a synchronous action.
|
|
66
|
-
*/
|
|
67
|
-
function isSyncAction(action) {
|
|
68
|
-
return action instanceof Function;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Type guard function to test if an action is a synchronous action.
|
|
72
|
-
*/
|
|
73
|
-
function isAdvancedSyncAction(action) {
|
|
74
|
-
return !(action instanceof Function) && !action.hasOwnProperty('promise') && !action.hasOwnProperty('promiseGet');
|
|
75
|
-
}
|
|
76
|
-
function convertV5Actions(sourceActions) {
|
|
77
|
-
var actionNames = Object.keys(sourceActions);
|
|
78
|
-
return actionNames.reduce(function (acc, actionName) {
|
|
79
|
-
var sourceAction = sourceActions[actionName];
|
|
80
|
-
if (isSyncAction(sourceAction)) {
|
|
81
|
-
acc[actionName] = function (ctx) {
|
|
82
|
-
return sourceAction(ctx.s, ctx.args, ctx.p);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
else if (isAdvancedSyncAction(sourceAction)) {
|
|
86
|
-
var action = {
|
|
87
|
-
effects: function (ctx) {
|
|
88
|
-
return sourceAction.action(ctx.s, ctx.args, ctx.p);
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
if (sourceAction.onActionDone) {
|
|
92
|
-
action.sideEffects = function (_a) {
|
|
93
|
-
var s = _a.s, p = _a.p, args = _a.args, a = _a.a, notifyWarning = _a.notifyWarning;
|
|
94
|
-
sourceAction.onActionDone(s, args, p, a, notifyWarning);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
acc[actionName] = action;
|
|
98
|
-
}
|
|
99
|
-
else if (isAsyncActionPromise(sourceAction) || isAsyncActionPromiseGet(sourceAction)) {
|
|
100
|
-
var asyncAction_1;
|
|
101
|
-
if (isAsyncActionPromiseGet(sourceAction)) {
|
|
102
|
-
asyncAction_1 = {
|
|
103
|
-
getPromise: function (_a) {
|
|
104
|
-
var s = _a.s, p = _a.p, a = _a.a, args = _a.args, abortSignal = _a.abortSignal;
|
|
105
|
-
return sourceAction.promiseGet(args, s, p, a, abortSignal);
|
|
106
|
-
},
|
|
107
|
-
retryCount: 3,
|
|
108
|
-
conflictPolicy: ConflictPolicy.REUSE,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
asyncAction_1 = {
|
|
113
|
-
getPromise: function (_a) {
|
|
114
|
-
var s = _a.s, p = _a.p, a = _a.a, args = _a.args, abortSignal = _a.abortSignal;
|
|
115
|
-
return sourceAction.promise(args, s, p, a, abortSignal);
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
[
|
|
120
|
-
'abortable',
|
|
121
|
-
'conflictPolicy',
|
|
122
|
-
'getPromiseId',
|
|
123
|
-
'isTriggerRetryError',
|
|
124
|
-
'rejectPromiseOnError',
|
|
125
|
-
'retryCount',
|
|
126
|
-
'debounceTimeout',
|
|
127
|
-
'debounceSideEffectsTimeout',
|
|
128
|
-
'retryDelaySeed',
|
|
129
|
-
].forEach(function (prop) {
|
|
130
|
-
if (sourceAction[prop] != null) {
|
|
131
|
-
asyncAction_1[prop] = sourceAction[prop];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
if (sourceAction.successMessage) {
|
|
135
|
-
asyncAction_1.getSuccessMessage = function () { return sourceAction.successMessage; };
|
|
136
|
-
}
|
|
137
|
-
if (sourceAction.errorMessage) {
|
|
138
|
-
asyncAction_1.getSuccessMessage = function () { return sourceAction.errorMessage; };
|
|
139
|
-
}
|
|
140
|
-
if (sourceAction.getSuccessMessage) {
|
|
141
|
-
asyncAction_1.getSuccessMessage = function (_a) {
|
|
142
|
-
var res = _a.res, args = _a.args, p = _a.p;
|
|
143
|
-
return sourceAction.getSuccessMessage(res, args, p);
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
if (sourceAction.getErrorMessage) {
|
|
147
|
-
asyncAction_1.getErrorMessage = function (_a) {
|
|
148
|
-
var err = _a.err, args = _a.args, p = _a.p;
|
|
149
|
-
return sourceAction.getErrorMessage(err, args, p);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (sourceAction.preReducer) {
|
|
153
|
-
asyncAction_1.preEffects = function (_a) {
|
|
154
|
-
var s = _a.s, p = _a.p, args = _a.args;
|
|
155
|
-
return sourceAction.preReducer(s, args, p);
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (sourceAction.optimisticReducer) {
|
|
159
|
-
asyncAction_1.optimisticEffects = function (_a) {
|
|
160
|
-
var s = _a.s, p = _a.p, args = _a.args;
|
|
161
|
-
return sourceAction.optimisticReducer(s, args, p);
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (sourceAction.reducer) {
|
|
165
|
-
asyncAction_1.effects = function (_a) {
|
|
166
|
-
var s = _a.s, res = _a.res, p = _a.p, args = _a.args;
|
|
167
|
-
return sourceAction.reducer(s, res, args, p);
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
if (sourceAction.errorReducer) {
|
|
171
|
-
asyncAction_1.errorEffects = function (_a) {
|
|
172
|
-
var s = _a.s, err = _a.err, p = _a.p, args = _a.args;
|
|
173
|
-
return sourceAction.errorReducer(s, err, args, p);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (sourceAction.onDone) {
|
|
177
|
-
asyncAction_1.sideEffects = function (_a) {
|
|
178
|
-
var s = _a.s, res = _a.res, p = _a.p, args = _a.args, a = _a.a, notifyWarning = _a.notifyWarning;
|
|
179
|
-
return sourceAction.onDone(s, res, args, p, a, notifyWarning);
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
if (sourceAction.onFail) {
|
|
183
|
-
asyncAction_1.errorSideEffects = function (_a) {
|
|
184
|
-
var s = _a.s, err = _a.err, p = _a.p, args = _a.args, a = _a.a, notifyWarning = _a.notifyWarning;
|
|
185
|
-
return sourceAction.onFail(s, err, args, p, a, notifyWarning);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
acc[actionName] = asyncAction_1;
|
|
189
|
-
}
|
|
190
|
-
return acc;
|
|
191
|
-
}, {});
|
|
192
|
-
}
|
|
193
|
-
function convertV5Options(sourceOptions) {
|
|
194
|
-
var opts = {};
|
|
195
|
-
var keys = Object.keys(sourceOptions);
|
|
196
|
-
var doNotCopyProps = [
|
|
197
|
-
'onPropsChange',
|
|
198
|
-
'onPropsChangeReducer',
|
|
199
|
-
'getPropsRefValues',
|
|
200
|
-
'onMount',
|
|
201
|
-
'initialActionsMarkedLoading',
|
|
202
|
-
];
|
|
203
|
-
keys.forEach(function (prop) {
|
|
204
|
-
if (!doNotCopyProps.includes(prop)) {
|
|
205
|
-
opts[prop] = sourceOptions[prop];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
if (sourceOptions.onMount) {
|
|
209
|
-
opts.onMount = function (_a) {
|
|
210
|
-
var s = _a.s, p = _a.p, a = _a.a;
|
|
211
|
-
return sourceOptions.onMount(a, p, s);
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
if (sourceOptions.getPropsRefValues) {
|
|
215
|
-
opts.onPropsChange = {
|
|
216
|
-
getDeps: sourceOptions.getPropsRefValues,
|
|
217
|
-
effects: function (_a) {
|
|
218
|
-
var s = _a.s, p = _a.p, indices = _a.indices;
|
|
219
|
-
return sourceOptions.onPropsChangeReducer ? sourceOptions.onPropsChangeReducer(s, p, indices) : null;
|
|
220
|
-
},
|
|
221
|
-
sideEffects: function (_a) {
|
|
222
|
-
var s = _a.s, p = _a.p, a = _a.a, indices = _a.indices;
|
|
223
|
-
return sourceOptions.onPropsChange == null ? null : sourceOptions.onPropsChange(s, p, a, indices);
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (sourceOptions.initialActionsMarkedLoading) {
|
|
228
|
-
opts.initialActionsMarkedLoading = sourceOptions.initialActionsMarkedLoading;
|
|
229
|
-
}
|
|
230
|
-
return opts;
|
|
231
|
-
}
|
|
232
|
-
function useStateDecorator(getInitialState, actions, props, options, middlewares) {
|
|
233
|
-
if (options === void 0) { options = {}; }
|
|
234
|
-
var _a = useReducer(function (s) { return (s > 100 ? 0 : s + 1); }, 0), forceRefresh = _a[1];
|
|
235
|
-
var actionsRef = useRef();
|
|
236
|
-
var optionsRef = useRef();
|
|
237
|
-
if (actionsRef.current == null) {
|
|
238
|
-
actionsRef.current = convertV5Actions(actions);
|
|
239
|
-
}
|
|
240
|
-
if (optionsRef.current == null) {
|
|
241
|
-
optionsRef.current = convertV5Options(options);
|
|
242
|
-
}
|
|
243
|
-
var storeRef = useRef();
|
|
244
|
-
if (storeRef.current == null) {
|
|
245
|
-
var middlewareFactories = middlewares;
|
|
246
|
-
if (options.logEnabled) {
|
|
247
|
-
middlewareFactories.push(logDetailedEffects());
|
|
248
|
-
}
|
|
249
|
-
storeRef.current = createStore(__assign(__assign({ getInitialState: getInitialState, actions: actionsRef.current }, optionsRef.current), { middlewares: middlewareFactories }));
|
|
250
|
-
}
|
|
251
|
-
storeRef.current.setProps(props);
|
|
252
|
-
useLayoutEffect(function () {
|
|
253
|
-
return storeRef.current.addStateListener(function () {
|
|
254
|
-
forceRefresh();
|
|
255
|
-
});
|
|
256
|
-
}, []);
|
|
257
|
-
var store = storeRef.current;
|
|
258
|
-
return {
|
|
259
|
-
state: store.state,
|
|
260
|
-
actions: store.actions,
|
|
261
|
-
loading: store.loading,
|
|
262
|
-
loadingMap: store.loadingMap,
|
|
263
|
-
loadingParallelMap: store.loadingParallelMap,
|
|
264
|
-
abortAction: store.abortAction,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Hook to execute a function when hook is mounted.
|
|
269
|
-
* @param onMount function to execute on the hook nount
|
|
270
|
-
*/
|
|
271
|
-
function useOnMount(onMount) {
|
|
272
|
-
useEffect(function () {
|
|
273
|
-
var removeListener = onMount();
|
|
274
|
-
return typeof removeListener === 'function' ? removeListener : undefined;
|
|
275
|
-
}, []);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Hook to execute a function when hook is unmounted.
|
|
279
|
-
* @param onUnMount function to execute on the hook nount
|
|
280
|
-
*/
|
|
281
|
-
function useOnUnmount(onUnmount, propList) {
|
|
282
|
-
if (propList === void 0) { propList = []; }
|
|
283
|
-
useEffect(function () {
|
|
284
|
-
return onUnmount;
|
|
285
|
-
}, propList);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Hook to execute a function when hook is unmounted.
|
|
289
|
-
* @param onUnMount function to execute on the hook nount
|
|
290
|
-
*/
|
|
291
|
-
function useOnUnload(onUnload) {
|
|
292
|
-
useEffect(function () {
|
|
293
|
-
document.addEventListener('beforeunload', onUnload);
|
|
294
|
-
return function () {
|
|
295
|
-
document.removeEventListener('beforeunload', onUnload);
|
|
296
|
-
};
|
|
297
|
-
}, []);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export default useStateDecorator;
|
|
301
|
-
export { isAdvancedSyncAction, isAsyncAction, isAsyncPromiseGetAction, isSyncAction, useOnMount, useOnUnload, useOnUnmount };
|
|
1
|
+
import{createStore as e}from"./index";import{useReducer as n,useRef as r,useLayoutEffect as t,useEffect as o}from"react";var i,s=function(){return s=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},s.apply(this,arguments)};!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(i||(i={}));var c=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==typeof n&&"object"==typeof r){if(n.constructor!==r.constructor)return!1;var t,o,i;if(Array.isArray(n)){if((t=n.length)!=r.length)return!1;for(o=t;0!=o--;)if(!e(n[o],r[o]))return!1;return!0}if(n.constructor===RegExp)return n.source===r.source&&n.flags===r.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===r.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===r.toString();if((t=(i=Object.keys(n)).length)!==Object.keys(r).length)return!1;for(o=t;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=t;0!=o--;){var s=i[o];if(!e(n[s],r[s]))return!1}return!0}return n!=n&&r!=r},u=null;function a(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function f(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function l(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))}function g(e){return e instanceof Function}function p(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function d(e){return Object.keys(e).reduce((function(n,r){var t=e[r];if(g(t))n[r]=function(e){return t(e.s,e.args,e.p)};else if(p(t)){var o={effects:function(e){return t.action(e.s,e.args,e.p)}};t.onActionDone&&(o.sideEffects=function(e){var n=e.s,r=e.p,o=e.args,i=e.a,s=e.notifyWarning;t.onActionDone(n,o,r,i,s)}),n[r]=o}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(t)||a(t)){var s;s=a(t)?{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promiseGet(i,n,r,o,s)},retryCount:3,conflictPolicy:i.REUSE}:{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promise(i,n,r,o,s)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=t[e]&&(s[e]=t[e])})),t.successMessage&&(s.getSuccessMessage=function(){return t.successMessage}),t.errorMessage&&(s.getSuccessMessage=function(){return t.errorMessage}),t.getSuccessMessage&&(s.getSuccessMessage=function(e){var n=e.res,r=e.args,o=e.p;return t.getSuccessMessage(n,r,o)}),t.getErrorMessage&&(s.getErrorMessage=function(e){var n=e.err,r=e.args,o=e.p;return t.getErrorMessage(n,r,o)}),t.preReducer&&(s.preEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.preReducer(n,o,r)}),t.optimisticReducer&&(s.optimisticEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.optimisticReducer(n,o,r)}),t.reducer&&(s.effects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args;return t.reducer(n,r,i,o)}),t.errorReducer&&(s.errorEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args;return t.errorReducer(n,r,i,o)}),t.onDone&&(s.sideEffects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args,s=e.a,c=e.notifyWarning;return t.onDone(n,r,i,o,s,c)}),t.onFail&&(s.errorSideEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args,s=e.a,c=e.notifyWarning;return t.onFail(n,r,i,o,s,c)}),n[r]=s}return n}),{})}function v(o,i,c,a,f){void 0===a&&(a={});var l,g,p,v,y=n((function(e){return e>100?0:e+1}),0)[1],E=r(),h=r();null==E.current&&(E.current=d(i)),null==h.current&&(h.current=(l=a,g={},p=Object.keys(l),v=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],p.forEach((function(e){v.includes(e)||(g[e]=l[e])})),l.onMount&&(g.onMount=function(e){var n=e.s,r=e.p,t=e.a;return l.onMount(t,r,n)}),l.getPropsRefValues&&(g.onPropsChange={getDeps:l.getPropsRefValues,effects:function(e){var n=e.s,r=e.p,t=e.indices;return l.onPropsChangeReducer?l.onPropsChangeReducer(n,r,t):null},sideEffects:function(e){var n=e.s,r=e.p,t=e.a,o=e.indices;return null==l.onPropsChange?null:l.onPropsChange(n,r,t,o)}}),l.initialActionsMarkedLoading&&(g.initialActionsMarkedLoading=l.initialActionsMarkedLoading),g));var m=r();if(null==m.current){var O=f;a.logEnabled&&O.push(u()),m.current=e(s(s({getInitialState:o,actions:E.current},h.current),{middlewares:O}))}m.current.setProps(c),t((function(){return m.current.addStateListener((function(){y()}))}),[]);var P=m.current;return{state:P.state,actions:P.actions,loading:P.loading,loadingMap:P.loadingMap,loadingParallelMap:P.loadingParallelMap,abortAction:P.abortAction}}function y(e){o((function(){var n=e();return"function"==typeof n?n:void 0}),[e])}function E(e,n){void 0===n&&(n=[]),o((function(){return e}),[n,e])}function h(e){o((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[e])}"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||(u=function(e){return void 0===e&&(e=console),function(){var n="",r=e,t=function(e,n){var r;if(n!==e){var t=null!=e?typeof e:typeof n;if("number"===t||"string"===t||"boolean"===t)r="".concat(e," => ").concat(""===n?'""':n);else if(e&&e.length||n&&n.length)if(null==e)r="was ".concat(e,", now contains ").concat(n.length," element(s)");else if(null==n)r="contained ".concat(e.length," element(s), now is ").concat(n);else if(0===e.length)r="was empty, now contains ".concat(n.length," elements");else if(0===n.length)r="contained ".concat(e.length," elements, now is empty");else{var o=n.filter((function(n){return!e.find((function(e){return c(n,e)}))})),i=e.filter((function(e){return!n.find((function(n){return c(e,n)}))}));o.length>10&&(o="".concat(o.length," element(s) added")),i.length>10&&(i="".concat(i.length," element(s) removed")),r={added:o,removed:i}}else r=n}return r},o=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(t){var i,s;n=(null===(i=t.options)||void 0===i?void 0:i.name)?"[".concat(null===(s=t.options)||void 0===s?void 0:s.name,"]"):"";var c=t.state;e.group(n,"initialState"),Object.keys(c).forEach((function(e){r.log(e,":",o(c[e]))})),e.groupEnd()},destroy:null,effects:function(e,i,s,c){var u,a=null===(u=e.context)||void 0===u?void 0:u.args,f=[n,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?f.push(c?"START":"CANCELLED"):"effects"===e.type?f.push("DONE"):f.push("FAILED")),null!=s||a&&0!==Object.keys(a).length?r.group.apply(r,f):r.log.apply(r,f),a&&Object.keys(a).length>0&&(r.group("Arguments"),a.forEach((function(e){r.log(e,":",o(e))})),r.groupEnd()),null!=s){if(r.groupCollapsed("Before"),null==i)r.log("was null");else Object.keys(i).forEach((function(e){r.log(e,":",o(i[e]))}));if(r.groupEnd(),r.groupCollapsed("After"),null==s)r.log("was null");else Object.keys(s).forEach((function(e){r.log(e,":",o(s[e]))}));if(r.groupEnd(),null!=s){r.group("Diff");var l=function(e,n){var r={};return e&&Object.keys(e).forEach((function(o){if(n.hasOwnProperty(o)){var i=e[o],s=n[o],c=t(i,s);c&&(r[o]=c)}else r[o]="was deleted"})),Object.keys(n).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var i=n[o];r[o]=t(void 0,i)}})),r}(i,s);Object.keys(l).forEach((function(e){return r.log(e,":",l[e])})),r.groupEnd()}}return r.groupEnd(),null}}}});export default v;export{p as isAdvancedSyncAction,f as isAsyncAction,l as isAsyncPromiseGetAction,g as isSyncAction,y as useOnMount,h as useOnUnload,E as useOnUnmount};
|
|
302
2
|
//# sourceMappingURL=v5.js.map
|