state-decorator 7.0.0-beta.0 → 7.0.0-beta.10-dev
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 +384 -192
- package/es/helpers.d.ts +66 -0
- package/es/helpers.js +163 -0
- package/{dist/v5_test.js.map → es/helpers.js.map} +1 -1
- package/es/impl.d.ts +19 -5
- package/es/impl.js +963 -1
- package/es/impl.js.map +1 -1
- package/es/index.d.ts +34 -36
- package/es/index.js +1013 -1
- package/es/index.js.map +1 -1
- package/es/middlewares.js +519 -1
- package/es/middlewares.js.map +1 -1
- package/es/test.d.ts +6 -4
- package/es/test.js +349 -1
- package/es/test.js.map +1 -1
- package/es/types.d.ts +32 -3
- package/es/v5.js +301 -1
- package/es/v5.js.map +1 -1
- package/es/v5_test.js +392 -1
- package/es/v5_test.js.map +1 -1
- package/es/v6.d.ts +18 -0
- package/es/v6.js +98 -0
- package/es/v6.js.map +1 -0
- package/helpers.d.ts +66 -0
- package/helpers.js +175 -0
- package/{dist/test.js.map → helpers.js.map} +1 -1
- package/impl.d.ts +19 -5
- package/impl.js +996 -1
- package/impl.js.map +1 -1
- package/index.d.ts +34 -36
- package/index.js +1044 -1
- package/index.js.map +1 -1
- package/middlewares.js +526 -1
- package/middlewares.js.map +1 -1
- package/package.json +5 -4
- package/test.d.ts +6 -4
- package/test.js +358 -1
- package/test.js.map +1 -1
- package/types.d.ts +32 -3
- package/v5.js +322 -1
- package/v5.js.map +1 -1
- package/v5_test.js +416 -1
- package/v5_test.js.map +1 -1
- package/v6.d.ts +18 -0
- package/v6.js +123 -0
- package/v6.js.map +1 -0
- package/dist/impl.d.ts +0 -195
- package/dist/impl.js +0 -2
- package/dist/impl.js.map +0 -1
- package/dist/index.d.ts +0 -168
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/middlewares.d.ts +0 -26
- package/dist/middlewares.js +0 -2
- package/dist/middlewares.js.map +0 -1
- package/dist/shallow.d.ts +0 -15
- package/dist/test.d.ts +0 -134
- package/dist/test.js +0 -2
- package/dist/types.d.ts +0 -352
- package/dist/v5.d.ts +0 -58
- package/dist/v5.js +0 -2
- package/dist/v5.js.map +0 -1
- package/dist/v5_test.d.ts +0 -70
- package/dist/v5_test.js +0 -2
- package/dist/v5_types.d.ts +0 -227
package/dist/shallow.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
export default function shallow<T extends any, U extends any>(objA: T, objB: U): boolean;
|
package/dist/test.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
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 { ErrorMap, StoreActions, StoreApi, StoreOptions } from '.';
|
|
16
|
-
import { DerivedState, SetStateFunc, Ref } from './impl';
|
|
17
|
-
import { DecoratedActions } from './types';
|
|
18
|
-
declare type MockActions<A, MockAction> = {
|
|
19
|
-
[k in keyof A]: MockAction;
|
|
20
|
-
};
|
|
21
|
-
declare type MockResult<S, A extends DecoratedActions, P, DS> = {
|
|
22
|
-
readonly prevState: S & DS;
|
|
23
|
-
readonly state: S & DS;
|
|
24
|
-
readonly props: P;
|
|
25
|
-
readonly actions: MockActions<A, any>;
|
|
26
|
-
readonly errorMap: ErrorMap<A>;
|
|
27
|
-
};
|
|
28
|
-
declare type MockActionImpl<A> = Partial<Record<keyof A, (...args: any[]) => any>>;
|
|
29
|
-
declare type MockResultWithTest<S, A extends DecoratedActions, P, DS> = MockResult<S, A, P, DS> & {
|
|
30
|
-
/**
|
|
31
|
-
* Execute function passed as parameter to test state/props/actions called.
|
|
32
|
-
*/
|
|
33
|
-
test: (f: (res: MockResult<S, A, P, DS>) => void) => void;
|
|
34
|
-
};
|
|
35
|
-
declare type MockStoreAction<S, A extends DecoratedActions, F extends (...args: any[]) => any, P, DS> = {
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new store action with specified state.
|
|
38
|
-
*/
|
|
39
|
-
setState: (state: S) => MockStoreAction<S, A, F, P, DS>;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a new store action with specified props.
|
|
42
|
-
*/
|
|
43
|
-
setProps: (props: P) => MockStoreAction<S, A, F, P, DS>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a new store action using store state overriden by specified state.
|
|
46
|
-
*/
|
|
47
|
-
setPartialState: (state: Partial<S>) => MockStoreAction<S, A, F, P, DS>;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a new store action using store props overriden by specified props.
|
|
50
|
-
*/
|
|
51
|
-
setPartialProps: (props: Partial<P>) => MockStoreAction<S, A, F, P, DS>;
|
|
52
|
-
/**
|
|
53
|
-
* Set implementations to some actions to test side effects.
|
|
54
|
-
*/
|
|
55
|
-
setMockActions: (implementation: MockActionImpl<A>) => MockStoreAction<S, A, F, P, DS>;
|
|
56
|
-
/**
|
|
57
|
-
* If action is asynchronous, mock the getPromise call to be resolved with specified object.
|
|
58
|
-
*/
|
|
59
|
-
promiseResolves: (res: any) => MockStoreAction<S, A, F, P, DS>;
|
|
60
|
-
/**
|
|
61
|
-
* If action is asynchronous, mock the getPromise call to be rejected with specified error.
|
|
62
|
-
*/
|
|
63
|
-
promiseRejects: (err: Error) => MockStoreAction<S, A, F, P, DS>;
|
|
64
|
-
/**
|
|
65
|
-
* Executes passed function to test state and/or props
|
|
66
|
-
*/
|
|
67
|
-
test: (f: (state: S & DS, props: P) => void) => MockStoreAction<S, A, F, P, DS>;
|
|
68
|
-
/**
|
|
69
|
-
* Calls the action with specified parameters.
|
|
70
|
-
* @returns a promise with state/props/actions to assert
|
|
71
|
-
*/
|
|
72
|
-
call: (...args: Parameters<F>) => Promise<MockResult<S, A, P, DS>>;
|
|
73
|
-
};
|
|
74
|
-
declare type MockStore<S, A extends DecoratedActions, P, DS> = {
|
|
75
|
-
/**
|
|
76
|
-
* Creates a new store with specified state.
|
|
77
|
-
*/
|
|
78
|
-
setState: (state: S) => MockStore<S, A, P, DS>;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a new store with specified props.
|
|
81
|
-
*/
|
|
82
|
-
setProps: (props: P) => MockStore<S, A, P, DS>;
|
|
83
|
-
/**
|
|
84
|
-
* Creates a new store using store state overriden by specified state.
|
|
85
|
-
*/
|
|
86
|
-
setPartialState: (state: Partial<S>) => MockStore<S, A, P, DS>;
|
|
87
|
-
/**
|
|
88
|
-
* Creates a new store using store props overriden by specified props.
|
|
89
|
-
*/
|
|
90
|
-
setPartialProps: (props: Partial<P>) => MockStore<S, A, P, DS>;
|
|
91
|
-
/**
|
|
92
|
-
* Set implementations to some actions to test side effects.
|
|
93
|
-
*/
|
|
94
|
-
setMockActions: (implementation: MockActionImpl<A>) => MockStore<S, A, P, DS>;
|
|
95
|
-
/**
|
|
96
|
-
* Executes passed function to test state and/or props
|
|
97
|
-
*/
|
|
98
|
-
test: (f: (state: S & DS, props: P) => void) => MockStore<S, A, P, DS>;
|
|
99
|
-
/**
|
|
100
|
-
* Test options.onMount
|
|
101
|
-
* @deprecated Use init() instead
|
|
102
|
-
*/
|
|
103
|
-
onMount: (props: Partial<P>) => MockResultWithTest<S, A, P, DS>;
|
|
104
|
-
/**
|
|
105
|
-
* Test state and side effect actions after inbound props have changed.
|
|
106
|
-
*/
|
|
107
|
-
onPropsChange: (props: Partial<P>, init?: boolean) => MockResultWithTest<S, A, P, DS>;
|
|
108
|
-
/**
|
|
109
|
-
* Test store at initialization time:
|
|
110
|
-
* - options.onPropsChange with onMount set to true
|
|
111
|
-
* - options.onMount
|
|
112
|
-
*/
|
|
113
|
-
onInit: (props?: Partial<P>) => MockResultWithTest<S, A, P, DS>;
|
|
114
|
-
/** @internal */
|
|
115
|
-
onPropsChangeImpl: (newStateRef: Ref<S>, newPropsRef: Ref<P>, newDerivedStateRef: Ref<DerivedState<DS>>, newActionsRef: Ref<StoreActions<S, A, P, DS, S>>, setState: SetStateFunc<S, A>, init?: boolean) => MockResult<S, A, P, DS>;
|
|
116
|
-
getAction: <K extends keyof A>(name: K) => MockStoreAction<S, A, A[K], P, DS>;
|
|
117
|
-
};
|
|
118
|
-
export declare function createMockFromStore<S, A extends DecoratedActions, P, DS>(store: StoreApi<S, A, P, DS>, props?: P): MockStore<S, A, P, DS>;
|
|
119
|
-
export declare function createMockStore<S, A extends DecoratedActions, P = {}, DS = {}>(initialState: S | ((p: P) => S), actions: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, mockActions?: MockActionImpl<A>): MockStore<S, A, P, DS>;
|
|
120
|
-
/**
|
|
121
|
-
* Set the mock factory. Each mock action will be created using this factory.
|
|
122
|
-
* @param factory the mock factory
|
|
123
|
-
*/
|
|
124
|
-
export declare function setMockFactory(factory: (impl?: (...args: any[]) => any) => any): void;
|
|
125
|
-
export declare class ActionError<S = any, P = any, A = any> extends Error {
|
|
126
|
-
sourceError: Error;
|
|
127
|
-
prevState: S;
|
|
128
|
-
state: S;
|
|
129
|
-
props: P;
|
|
130
|
-
actions: MockActions<A, any>;
|
|
131
|
-
constructor(sourceError: Error, prevState: S, state: S, props: P, actions: MockActions<A, any>);
|
|
132
|
-
}
|
|
133
|
-
export declare function createMockStoreAction<S, A extends DecoratedActions, F extends (...args: any[]) => any, P, DS>(state: S, actionName: keyof A, actions: StoreActions<S, A, P, DS, S>, props: P, promiseRes: Promise<F> | Error, options: StoreOptions<S, A, P, DS>, mockActions: Partial<Record<keyof A, (...args: any[]) => any>>): MockStoreAction<S, A, F, P, DS>;
|
|
134
|
-
export {};
|
package/dist/test.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./impl"),e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};var r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function n(e,c,i,a,s){void 0===i&&(i={}),void 0===a&&(a={});var f=t.createRef(),l=t.createRef(i);function p(t,e,r){return n(null!=t?t:f.current,c,null!=e?e:l.current,a,null!=r?r:s)}function v(e,n){void 0===e&&(e=void 0),void 0===n&&(n=void 0);var o=t.createRef({state:null,deps:{}});return t.computeDerivedValues(e||f,n||l,o,a),r(r({},(null==e?void 0:e.current)||f.current),o.current.state||{})}return f.current="function"==typeof e?e(i):e,{test:function(t){return t(v(),l.current),this},setMockActions:function(t){return p(void 0,void 0,t)},onMount:function(t){return void 0===t&&(t={}),this.onInit(t)},setState:function(t){return p(t,void 0)},setProps:function(t){return p(void 0,t)},setPartialState:function(t){return p(r(r({},f.current),t),void 0)},setPartialProps:function(t){return p(void 0,r(r({},l.current),t))},onPropsChange:function(e,n){void 0===n&&(n=!1);var i=t.createRef(f.current),u=t.createRef(r(r({},l.current),e)),a=t.createRef({state:null,deps:{}}),p=o(c,s),v=this.onPropsChangeImpl(i,u,a,p,(function(t,e,r,n,o){null!=t&&(i.current=t)}),n);return r(r({},v),{test:function(t){t(v)}})},onPropsChangeImpl:function(e,r,n,o,c,i){return t.computeDerivedValues(f,l,n,a),t.onPropChange(e,n,r,l.current,o,a,c,i),{prevState:v(f,l),state:v(e,r),props:r.current,actions:o.current,errorMap:{}}},onInit:function(n){void 0===n&&(n={});var u="function"==typeof e?e(i):e,f=t.createRef(u),p=t.createRef(r(r({},l.current),n)),d=t.createRef({state:null,deps:{}}),R=o(c,s);this.onPropsChangeImpl(f,p,d,R,(function(t,e,r,n,o){null!=t&&(f.current=t)}),!0),(null==a?void 0:a.onMount)&&a.onMount(t.buildOnMountInvocationContext(f,d,p,R));var m={prevState:null,state:v(f,p),props:p.current,actions:R.current,errorMap:{}};return r(r({},m),{test:function(t){t(m)}})},getAction:function(t){return u(f.current,t,c,l.current,null,a,void 0)}}}function o(e,r){var n=Object.keys(e);return t.createRef(n.reduce((function(t,e){return t[e]=c(null==r?void 0:r[e]),t}),{}))}var c=function(t){return jest.fn(t)};var i=function(t){function r(e,n,o,c,i){var u=t.call(this,e.message)||this;return Object.setPrototypeOf(u,r.prototype),u.sourceError=e,u.prevState=n,u.props=c,u.state=o,u.actions=i,Error.captureStackTrace&&Error.captureStackTrace(u,r),u}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,t),r}(Error);function u(e,n,c,a,s,f,l){var p=t.createRef(e),v=t.createRef(a),d=s;function R(t,e,r,o){return void 0===o&&(o=l),u(null!=t?t:p.current,n,c,null!=e?e:v.current,null!=r?r:d,f,o)}function m(e,n){void 0===e&&(e=void 0),void 0===n&&(n=void 0);var o=t.createRef({state:null,deps:{}});return t.computeDerivedValues(null!=e?e:p,null!=n?n:v,o,f),r(r({},(null==e?void 0:e.current)||p.current),o.current.state||{})}return{setMockActions:function(t){return R(void 0,void 0,void 0,t)},setState:function(t){return R(t,void 0,void 0)},setProps:function(t){return R(void 0,t,void 0)},setPartialState:function(t){return R(r(r({},p.current),t),void 0,void 0)},setPartialProps:function(t){return R(void 0,r(r({},v.current),t),void 0)},promiseResolves:function(t){return R(void 0,void 0,Promise.resolve(t))},promiseRejects:function(t){return R(void 0,void 0,Promise.reject(t))},test:function(t){return t(m(),v.current),this},call:function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];var a=t.createRef(r({},p.current)),s=t.createRef({state:null,deps:{}});t.computeDerivedValues(a,v,s,f);var R=o(c,l),y=t.createRef({}),P=t.createRef({}),S=function(t){null!=t&&(a.current=t)},h=c[n],A=null;if(t.isSimpleSyncAction(h))t.decorateSimpleSyncAction(n,h,a,s,v,t.createRef(!0),S).apply(void 0,e),A=Promise.resolve();else if(t.isSyncAction(h))t.decorateSyncAction(n,r(r({},h),{debounceSideEffectsTimeout:0,debounceTimeout:0}),a,s,v,R,t.createRef(!0),null,f,S).apply(void 0,e),A=Promise.resolve();else if(t.isAsyncAction(h)){var M=t.createRef({}),g=t.createRef({}),O=t.createRef(!0),b=r({},t.computeAsyncActionInput(h));d&&(b.getPromise=function(){return d}),b.optimisticEffects&&(b.effects=b.optimisticEffects,delete b.optimisticEffects),A=t.decorateAsyncAction({actionName:n,derivedStateRef:s,propsRef:v,loadingMapRef:y,errorMapRef:P,promisesRef:M,conflictActionsRef:g,initializedRef:O,options:f,setState:S,stateRef:a,actionsRef:R,action:b}).apply(void 0,e)}return(null!=A?A:Promise.resolve()).then((function(){return y.current={},{prevState:m(p),state:m(a),props:v.current,errorMap:t.buildErrorMap(P.current),actions:R.current}})).catch((function(t){return Promise.reject(new i(t,m(p),m(a),v.current,R.current))}))}}}exports.ActionError=i,exports.createMockFromStore=function(t,e){void 0===e&&(e={});var r=t.getConfig();return n(r.getInitialState,r.actions,e,r.options)},exports.createMockStore=n,exports.createMockStoreAction=u,exports.setMockFactory=function(t){c=t};
|
|
2
|
-
//# sourceMappingURL=test.js.map
|
package/dist/types.d.ts
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
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
|
-
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 = {
|
|
18
|
-
[promiseId: string]: boolean;
|
|
19
|
-
};
|
|
20
|
-
export declare type LoadingMap<A> = {
|
|
21
|
-
[pId in keyof A]?: boolean;
|
|
22
|
-
};
|
|
23
|
-
export declare type LoadingParallelMap<A> = {
|
|
24
|
-
[P in keyof A]?: PromiseIdMap;
|
|
25
|
-
};
|
|
26
|
-
export declare type InternalLoadingMap<A> = LoadingParallelMap<A>;
|
|
27
|
-
export declare type LoadingProps<A> = {
|
|
28
|
-
loading: boolean;
|
|
29
|
-
loadingMap: LoadingMap<A>;
|
|
30
|
-
loadingParallelMap: LoadingParallelMap<A>;
|
|
31
|
-
};
|
|
32
|
-
export declare type PromiseIdErrorMap = {
|
|
33
|
-
[promiseId: string]: Error;
|
|
34
|
-
};
|
|
35
|
-
export declare type ErrorMap<A> = {
|
|
36
|
-
[pId in keyof A]?: Error;
|
|
37
|
-
};
|
|
38
|
-
export declare type ErrorParallelMap<A> = {
|
|
39
|
-
[P in keyof A]?: PromiseIdErrorMap;
|
|
40
|
-
};
|
|
41
|
-
export interface DecoratedActions {
|
|
42
|
-
[name: string]: (...args: any[]) => Promise<any> | void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* The State decorator can manage only one asynchronous action of same name at a time.
|
|
46
|
-
* This enum is enumertaing all the policies in such case.
|
|
47
|
-
*/
|
|
48
|
-
export declare enum ConflictPolicy {
|
|
49
|
-
/**
|
|
50
|
-
* Reject the promise.
|
|
51
|
-
*/
|
|
52
|
-
REJECT = "reject",
|
|
53
|
-
/**
|
|
54
|
-
* Return a resolved promise with no result.
|
|
55
|
-
*/
|
|
56
|
-
IGNORE = "ignore",
|
|
57
|
-
/**
|
|
58
|
-
* Execute only the last call that conflicts after the one ongoing.
|
|
59
|
-
*/
|
|
60
|
-
KEEP_LAST = "keepLast",
|
|
61
|
-
/**
|
|
62
|
-
* Execute all calls one after another.
|
|
63
|
-
*/
|
|
64
|
-
KEEP_ALL = "keepAll",
|
|
65
|
-
/**
|
|
66
|
-
* Execute all calls one after another.
|
|
67
|
-
* @see getPromiseId
|
|
68
|
-
*/
|
|
69
|
-
PARALLEL = "parallel",
|
|
70
|
-
/**
|
|
71
|
-
* Reuse the ongoing promise if any and if possible (same arguments). Only for GET requests!
|
|
72
|
-
*/
|
|
73
|
-
REUSE = "reuse"
|
|
74
|
-
}
|
|
75
|
-
export declare type PromiseProvider<S, DS, F extends (...args: any[]) => any, A, P> = (ctx: GetPromiseInvocationContext<S, DS, F, P, A>) => ReturnType<F> | null;
|
|
76
|
-
/**
|
|
77
|
-
* Simple form of a synchronous action.
|
|
78
|
-
*/
|
|
79
|
-
export declare type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = S> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
80
|
-
export declare type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S> = {
|
|
81
|
-
/**
|
|
82
|
-
* Function that update the state when the action is called.
|
|
83
|
-
*/
|
|
84
|
-
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
85
|
-
/**
|
|
86
|
-
* Debounces the action if this parameter is defined.
|
|
87
|
-
*/
|
|
88
|
-
debounceTimeout?: number;
|
|
89
|
-
/**
|
|
90
|
-
* Debounces the action side effects if this parameter is defined.
|
|
91
|
-
*/
|
|
92
|
-
debounceSideEffectsTimeout?: number;
|
|
93
|
-
/**
|
|
94
|
-
* Function that calls side effects, ie. effects that are not changing the state directly.
|
|
95
|
-
*/
|
|
96
|
-
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Try to abort an action, if the action is <code>abortable</code>.
|
|
100
|
-
* @param actionName The action name
|
|
101
|
-
* @param promiseId If the action conflict type is <code>ConflictType.PARALLEL</code>, the identifier of the promise.
|
|
102
|
-
* @returns <code>true</code> if the action is abortable and an action is ongoing, <code>false</code> otherwise.
|
|
103
|
-
*/
|
|
104
|
-
export declare type AbortActionCallback<A> = (actionName: keyof A, promiseId?: string) => boolean;
|
|
105
|
-
export declare type GetErrorMessage<S, DS, F extends (...args: any[]) => any, P> = (ctx: ErrorMessageInvocationContext<S, DS, F, P>) => string;
|
|
106
|
-
export declare type ContextState<S> = {
|
|
107
|
-
state: S;
|
|
108
|
-
s: S;
|
|
109
|
-
};
|
|
110
|
-
export declare type ContextDerivedStateState<DS> = {
|
|
111
|
-
derived: DS;
|
|
112
|
-
ds: DS;
|
|
113
|
-
};
|
|
114
|
-
export declare type ContextBase<S, P> = ContextState<S> & {
|
|
115
|
-
props: P;
|
|
116
|
-
p: P;
|
|
117
|
-
};
|
|
118
|
-
export declare type ContextWithDerived<S, DS, P> = ContextBase<S, P> & ContextDerivedStateState<DS>;
|
|
119
|
-
export declare type InvocationContextActions<A> = {
|
|
120
|
-
actions: A;
|
|
121
|
-
a: A;
|
|
122
|
-
};
|
|
123
|
-
export declare type WarningNotifyFunc = {
|
|
124
|
-
notifyWarning?: NotifyFunc;
|
|
125
|
-
};
|
|
126
|
-
export declare type InvocationContext<S, DS, F extends (...args: any[]) => any, P> = ContextWithDerived<S, DS, P> & {
|
|
127
|
-
args: Parameters<F>;
|
|
128
|
-
promiseId: string;
|
|
129
|
-
};
|
|
130
|
-
export declare type EffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
131
|
-
result: PromiseResult<ReturnType<F>>;
|
|
132
|
-
res: PromiseResult<ReturnType<F>>;
|
|
133
|
-
};
|
|
134
|
-
export declare type GetPromiseInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = InvocationContextActions<A> & InvocationContext<S, DS, F, P> & {
|
|
135
|
-
abortSignal: AbortSignal;
|
|
136
|
-
};
|
|
137
|
-
export declare type ErrorEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P> = InvocationContext<S, DS, F, P> & {
|
|
138
|
-
error: Error;
|
|
139
|
-
err: Error;
|
|
140
|
-
};
|
|
141
|
-
export declare type SuccessMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = EffectsInvocationContext<S, DS, F, P>;
|
|
142
|
-
export declare type ErrorMessageInvocationContext<S, DS, F extends (...args: any[]) => any, P> = ErrorEffectsInvocationContext<S, DS, F, P>;
|
|
143
|
-
export declare type SideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = EffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc;
|
|
144
|
-
export declare type ErrorSideEffectsInvocationContext<S, DS, F extends (...args: any[]) => any, P, A> = ErrorEffectsInvocationContext<S, DS, F, P> & InvocationContextActions<A> & WarningNotifyFunc;
|
|
145
|
-
export declare type OnMountInvocationContext<S, A, P> = ContextBase<S, P> & InvocationContextActions<A>;
|
|
146
|
-
export declare type EffectsType = 'preEffects' | 'effects' | 'errorEffects' | 'optimisticEffects' | null;
|
|
147
|
-
export declare type MiddlewareActionContext<S, A, P> = {
|
|
148
|
-
name: keyof A;
|
|
149
|
-
type: EffectsType;
|
|
150
|
-
isAsync: boolean;
|
|
151
|
-
context: InvocationContext<S, any, any, P>;
|
|
152
|
-
};
|
|
153
|
-
export declare type MiddlewareStoreContext<S, A extends DecoratedActions, P> = {
|
|
154
|
-
actions: StoreActions<S, A, P, any, any>;
|
|
155
|
-
state: S;
|
|
156
|
-
setState: (s: S) => void;
|
|
157
|
-
options: StoreOptions<S, A, P, any>;
|
|
158
|
-
};
|
|
159
|
-
export declare type MiddlewareFactory<S, A extends DecoratedActions, P> = () => Middleware<S, A, P>;
|
|
160
|
-
/**
|
|
161
|
-
* A state change middleware.
|
|
162
|
-
* Allow to listen and change a state change on the fly.
|
|
163
|
-
*/
|
|
164
|
-
export declare type Middleware<S, A extends DecoratedActions, P> = {
|
|
165
|
-
/**
|
|
166
|
-
* Initializes the middleware. Called when the store is initializing.
|
|
167
|
-
*/
|
|
168
|
-
init: (storeContext: MiddlewareStoreContext<S, A, P>) => void;
|
|
169
|
-
/**
|
|
170
|
-
* Invoked on a state change has occurred and returns a new state or <code>null</code> if unchanged.
|
|
171
|
-
*/
|
|
172
|
-
effects: (actionContext: MiddlewareActionContext<S, A, P>, oldState: S, newState: S, loading: boolean) => null | {
|
|
173
|
-
state: S;
|
|
174
|
-
loading: boolean;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* Destroys the middleware. Called when the store is being destroyed.
|
|
178
|
-
*/
|
|
179
|
-
destroy: () => void;
|
|
180
|
-
};
|
|
181
|
-
export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S> = {
|
|
182
|
-
/**
|
|
183
|
-
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
184
|
-
*/
|
|
185
|
-
abortable?: boolean;
|
|
186
|
-
/**
|
|
187
|
-
* A function that provides the success message to pass to the notifySuccess function passed as property to the StateDecorator.
|
|
188
|
-
*/
|
|
189
|
-
getSuccessMessage?: (ctx: SuccessMessageInvocationContext<S, DS, F, P>) => string;
|
|
190
|
-
/**
|
|
191
|
-
* A function that provides the error message to pass to the notifyError function passed as property to the StateDecorator.
|
|
192
|
-
*/
|
|
193
|
-
getErrorMessage?: GetErrorMessage<S, DS, F, P>;
|
|
194
|
-
/**
|
|
195
|
-
* If set, called with the result of the promise to update the current state.
|
|
196
|
-
*/
|
|
197
|
-
effects?: (ctx: EffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
198
|
-
/**
|
|
199
|
-
* If set, called with the error of the promise to update the current state.
|
|
200
|
-
*/
|
|
201
|
-
errorEffects?: (ctx: ErrorEffectsInvocationContext<S, DS, F, P>) => FxRes | null;
|
|
202
|
-
/**
|
|
203
|
-
* Whether reject the promise instead of handling it.
|
|
204
|
-
*/
|
|
205
|
-
rejectPromiseOnError?: boolean;
|
|
206
|
-
/**
|
|
207
|
-
* When the error will not be managed by an errorEffect, errorSideEffect, getErrorMessage,
|
|
208
|
-
* the state decorator will not display an error message and will not return a failed promise
|
|
209
|
-
* (unless <code>rejectPromiseOnError</code>) is set.
|
|
210
|
-
*/
|
|
211
|
-
isErrorManaged?: boolean;
|
|
212
|
-
/**
|
|
213
|
-
* Handle side effects when the request succeeded.
|
|
214
|
-
* @param result The result of the request
|
|
215
|
-
* @param newData The data after the reducer is applied
|
|
216
|
-
* @param args The argument during the call of the request function
|
|
217
|
-
* @param props The props passed to the state decorator
|
|
218
|
-
* @param actions The actions available
|
|
219
|
-
* @param notifyWarning If specified, a notify function to indicate that the action is a semi success (use successMessage / getSuccessMessage otherwise).
|
|
220
|
-
*/
|
|
221
|
-
sideEffects?: (ctx: SideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
222
|
-
/**
|
|
223
|
-
* Handle side effects when the request failed.
|
|
224
|
-
* @param error The error of the request
|
|
225
|
-
* @param args The argument during the call of the request function
|
|
226
|
-
* @param props The props passed to the state decorator
|
|
227
|
-
* @param actions The actions available
|
|
228
|
-
* @param notifyWarning If specified, a notify function to indicate that the action is a semi failure (use errorMessage / getErrorMessage otherwise).
|
|
229
|
-
*/
|
|
230
|
-
errorSideEffects?: (ctx: ErrorSideEffectsInvocationContext<S, DS, F, P, A>) => void;
|
|
231
|
-
/**
|
|
232
|
-
* Retrieve the state to set as current data before the promise is resolved.
|
|
233
|
-
* If the there's no reducer, this data will be used after the promise is done.
|
|
234
|
-
*/
|
|
235
|
-
preEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
236
|
-
/**
|
|
237
|
-
* Retrieve the state to set as current data before the promise is resolved.
|
|
238
|
-
* If the there's no reducer, this data will be used after the promise is done.
|
|
239
|
-
*/
|
|
240
|
-
optimisticEffects?: (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
241
|
-
/**
|
|
242
|
-
* Policy to apply when a call to an asynchronous action is done but a previous call is still not resolved.
|
|
243
|
-
*/
|
|
244
|
-
conflictPolicy?: ConflictPolicy;
|
|
245
|
-
/**
|
|
246
|
-
* Get an identifier for an action call. Used only when conflictPolicy is ConflictPolicy.PARALLEL.
|
|
247
|
-
* This information will be available in loadingMap. loadingMap[actionName] will be an array of promise identifiers.
|
|
248
|
-
*/
|
|
249
|
-
getPromiseId?: (...args: Parameters<F>) => string;
|
|
250
|
-
/**
|
|
251
|
-
* Number of retries in case of error (failed to fetch).
|
|
252
|
-
* Do not use this if you are creating objects...
|
|
253
|
-
* Default value is 0 (no retry).
|
|
254
|
-
*/
|
|
255
|
-
retryCount?: number;
|
|
256
|
-
/**
|
|
257
|
-
* Seed of delay between each retry in milliseconds.
|
|
258
|
-
* The applied delay is retryDelaySeed * retry count.
|
|
259
|
-
* Default value is 1000 (1 second).
|
|
260
|
-
*/
|
|
261
|
-
retryDelaySeed?: number;
|
|
262
|
-
/**
|
|
263
|
-
* Function to test if the error will trigger an action retry or will fail directly.
|
|
264
|
-
*/
|
|
265
|
-
isTriggerRetryError?: (e: Error) => boolean;
|
|
266
|
-
};
|
|
267
|
-
export declare type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
268
|
-
/**
|
|
269
|
-
* The request, returns a promise
|
|
270
|
-
*/
|
|
271
|
-
getPromise: PromiseProvider<S, DS, F, A, P>;
|
|
272
|
-
};
|
|
273
|
-
export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
274
|
-
/**
|
|
275
|
-
* The request, returns a promise that is a GET request.
|
|
276
|
-
* A shortcut to set:
|
|
277
|
-
* - retryCount: 3
|
|
278
|
-
* - conflictPolicy: ConflictPolicy.REUSE
|
|
279
|
-
*/
|
|
280
|
-
getGetPromise: PromiseProvider<S, DS, F, A, P>;
|
|
281
|
-
};
|
|
282
|
-
export declare type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncActionPromise<S, F, A, P, DS, FxRes> | AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
|
|
283
|
-
export declare type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
|
|
284
|
-
/**
|
|
285
|
-
* S: The type of the state
|
|
286
|
-
* A: The type of the actions to pass to the children (used to check keys only).
|
|
287
|
-
*/
|
|
288
|
-
export declare type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = S> = {
|
|
289
|
-
[Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
|
|
290
|
-
};
|
|
291
|
-
export declare type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
|
|
292
|
-
indices: number[];
|
|
293
|
-
index: number;
|
|
294
|
-
isInit: boolean;
|
|
295
|
-
};
|
|
296
|
-
export declare type OnPropsChangeSideEffectsContext<S, P, A, DS = {}> = OnPropsChangeEffectsContext<S, DS, P> & {
|
|
297
|
-
actions: A;
|
|
298
|
-
a: A;
|
|
299
|
-
};
|
|
300
|
-
declare type DerivedStateOption<S, P, DS> = {
|
|
301
|
-
[k in keyof DS]: {
|
|
302
|
-
getDeps: (ctx: ContextBase<S, P>) => any[];
|
|
303
|
-
get: (ctx: ContextBase<S, P>) => DS[k];
|
|
304
|
-
};
|
|
305
|
-
};
|
|
306
|
-
export declare type OnPropsChangeOptions<S, DS, A, P> = {
|
|
307
|
-
onMount?: boolean;
|
|
308
|
-
getDeps: (p: P) => any[];
|
|
309
|
-
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => S;
|
|
310
|
-
sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A>) => void;
|
|
311
|
-
};
|
|
312
|
-
export declare type StoreOptions<S, A, P = {}, DS = {}> = {
|
|
313
|
-
/**
|
|
314
|
-
* The state decorator name. Use in debug traces to identify the useStateDecorator instance.
|
|
315
|
-
*/
|
|
316
|
-
name?: string;
|
|
317
|
-
/**
|
|
318
|
-
* List of action names that are marked as loading at initial time.
|
|
319
|
-
* If you must start your initial actions in a useSideEffect, a render is done before
|
|
320
|
-
* first actions can be trigerred, some actions can be marked as loading at initial time.
|
|
321
|
-
*/
|
|
322
|
-
initialActionsMarkedLoading?: (keyof A)[];
|
|
323
|
-
/**
|
|
324
|
-
* One or several configurations of inbound properties change managements.
|
|
325
|
-
*/
|
|
326
|
-
onPropsChange?: OnPropsChangeOptions<S, DS, A, P> | OnPropsChangeOptions<S, DS, A, P>[];
|
|
327
|
-
/**
|
|
328
|
-
* The callback function called if an asynchronous function succeeded and a success messsage is defined.
|
|
329
|
-
*/
|
|
330
|
-
notifySuccess?: NotifyFunc;
|
|
331
|
-
/**
|
|
332
|
-
* The callback function called if an asynchronous function fails and an error messsage is defined.
|
|
333
|
-
*/
|
|
334
|
-
notifyError?: NotifyFunc;
|
|
335
|
-
/**
|
|
336
|
-
* The callback function injected in onDone and onFail of asynchronous functions to notify a semi success / failed request.
|
|
337
|
-
*/
|
|
338
|
-
notifyWarning?: NotifyFunc;
|
|
339
|
-
/**
|
|
340
|
-
* Initial actions.
|
|
341
|
-
*/
|
|
342
|
-
onMount?: (ctx: OnMountInvocationContext<S, A, P>) => void;
|
|
343
|
-
/**
|
|
344
|
-
* Callback on store destruction.
|
|
345
|
-
*/
|
|
346
|
-
onUnmount?: (ctx: OnMountInvocationContext<S, A, P>) => Promise<any> | void;
|
|
347
|
-
/**
|
|
348
|
-
* Compute derived state
|
|
349
|
-
*/
|
|
350
|
-
derivedState?: DerivedStateOption<S, P, DS>;
|
|
351
|
-
};
|
|
352
|
-
export {};
|
package/dist/v5.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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 { 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, };
|
|
19
|
-
/**
|
|
20
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
21
|
-
*/
|
|
22
|
-
export declare function isAsyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AsynchAction<S, F, A, P>;
|
|
23
|
-
/**
|
|
24
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isAsyncPromiseGetAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AsynchActionPromiseGet<S, F, A, P>;
|
|
27
|
-
/**
|
|
28
|
-
* Type guard function to test if an action is a synchronous action.
|
|
29
|
-
*/
|
|
30
|
-
export declare function isSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is SynchAction<S, F, P>;
|
|
31
|
-
/**
|
|
32
|
-
* Type guard function to test if an action is a synchronous action.
|
|
33
|
-
*/
|
|
34
|
-
export declare function isAdvancedSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AdvancedSynchAction<S, F, A, P>;
|
|
35
|
-
declare function useStateDecorator<S, A extends DecoratedActions, P>(getInitialState: (props: P) => S, actions: StateDecoratorActions<S, A, P>, props: P, options?: StateDecoratorOptions<S, A, P>, middlewares?: MiddlewareFactory<S, A, P>[]): {
|
|
36
|
-
state: S & {};
|
|
37
|
-
actions: A;
|
|
38
|
-
loading: boolean;
|
|
39
|
-
loadingMap: import("./types").LoadingMap<A>;
|
|
40
|
-
loadingParallelMap: import("./types").LoadingParallelMap<A>;
|
|
41
|
-
abortAction: (actionName: keyof A, promiseId?: string) => boolean;
|
|
42
|
-
};
|
|
43
|
-
export default useStateDecorator;
|
|
44
|
-
/**
|
|
45
|
-
* Hook to execute a function when hook is mounted.
|
|
46
|
-
* @param onMount function to execute on the hook nount
|
|
47
|
-
*/
|
|
48
|
-
export declare function useOnMount(onMount: () => any): void;
|
|
49
|
-
/**
|
|
50
|
-
* Hook to execute a function when hook is unmounted.
|
|
51
|
-
* @param onUnMount function to execute on the hook nount
|
|
52
|
-
*/
|
|
53
|
-
export declare function useOnUnmount(onUnmount: () => void, propList?: any[]): void;
|
|
54
|
-
/**
|
|
55
|
-
* Hook to execute a function when hook is unmounted.
|
|
56
|
-
* @param onUnMount function to execute on the hook nount
|
|
57
|
-
*/
|
|
58
|
-
export declare function useOnUnload(onUnload: () => void): void;
|
package/dist/v5.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./index"),r=require("react"),n=require("./middlewares");function t(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function o(e){return e instanceof Function}function s(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function i(r){return Object.keys(r).reduce((function(n,i){var c=r[i];if(o(c))n[i]=function(e){return c(e.s,e.args,e.p)};else if(s(c)){var u={effects:function(e){return c.action(e.s,e.args,e.p)}};c.onActionDone&&(u.sideEffects=function(e){var r=e.s,n=e.p,t=e.args,o=e.a,s=e.notifyWarning;c.onActionDone(r,t,n,o,s)}),n[i]=u}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(c)||t(c)){var a;a=t(c)?{getPromise:function(e){var r=e.s,n=e.p,t=e.a,o=e.args,s=e.abortSignal;return c.promiseGet(o,r,n,t,s)},retryCount:3,conflictPolicy:e.ConflictPolicy.REUSE}:{getPromise:function(e){var r=e.s,n=e.p,t=e.a,o=e.args,s=e.abortSignal;return c.promise(o,r,n,t,s)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=c[e]&&(a[e]=c[e])})),c.successMessage&&(a.getSuccessMessage=function(){return c.successMessage}),c.errorMessage&&(a.getSuccessMessage=function(){return c.errorMessage}),c.getSuccessMessage&&(a.getSuccessMessage=function(e){var r=e.res,n=e.args,t=e.p;return c.getSuccessMessage(r,n,t)}),c.getErrorMessage&&(a.getErrorMessage=function(e){var r=e.err,n=e.args,t=e.p;return c.getErrorMessage(r,n,t)}),c.preReducer&&(a.preEffects=function(e){var r=e.s,n=e.p,t=e.args;return c.preReducer(r,t,n)}),c.optimisticReducer&&(a.optimisticEffects=function(e){var r=e.s,n=e.p,t=e.args;return c.optimisticReducer(r,t,n)}),c.reducer&&(a.effects=function(e){var r=e.s,n=e.res,t=e.p,o=e.args;return c.reducer(r,n,o,t)}),c.errorReducer&&(a.errorEffects=function(e){var r=e.s,n=e.err,t=e.p,o=e.args;return c.errorReducer(r,n,o,t)}),c.onDone&&(a.sideEffects=function(e){var r=e.s,n=e.res,t=e.p,o=e.args,s=e.a,i=e.notifyWarning;return c.onDone(r,n,o,t,s,i)}),c.onFail&&(a.errorSideEffects=function(e){var r=e.s,n=e.err,t=e.p,o=e.args,s=e.a,i=e.notifyWarning;return c.onFail(r,n,o,t,s,i)}),n[i]=a}return n}),{})}Object.defineProperty(exports,"ConflictPolicy",{enumerable:!0,get:function(){return e.ConflictPolicy}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return e.setGlobalConfig}}),exports.default=function(t,o,s,c,u){void 0===c&&(c={});var a,f,p,g,l=r.useReducer((function(e){return e>100?0:e+1}),0)[1],d=r.useRef(),P=r.useRef();null==d.current&&(d.current=i(o)),null==P.current&&(P.current=(a=c,f={},p=Object.keys(a),g=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],p.forEach((function(e){g.includes(e)||(f[e]=a[e])})),a.onMount&&(f.onMount=function(e){var r=e.s,n=e.p,t=e.a;return a.onMount(t,n,r)}),a.getPropsRefValues&&(f.onPropsChange={getDeps:a.getPropsRefValues,effects:function(e){var r=e.s,n=e.p,t=e.indices;return a.onPropsChangeReducer?a.onPropsChangeReducer(r,n,t):null},sideEffects:function(e){var r=e.s,n=e.p,t=e.a,o=e.indices;return null==a.onPropsChange?null:a.onPropsChange(r,n,t,o)}}),a.initialActionsMarkedLoading&&(f.initialActionsMarkedLoading=a.initialActionsMarkedLoading),f));var y=r.useRef();if(null==y.current){var v=u;c.logEnabled&&v.push(n.logDetailedEffects()),y.current=e.createStore(t,d.current,P.current,v)}y.current.setProps(s),r.useLayoutEffect((function(){return y.current.addStateListener((function(){l()}))}),[]);var m=y.current;return{state:m.state,actions:m.actions,loading:m.loading,loadingMap:m.loadingMap,loadingParallelMap:m.loadingParallelMap,abortAction:m.abortAction}},exports.isAdvancedSyncAction=s,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))},exports.isAsyncPromiseGetAction=function(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))},exports.isSyncAction=o,exports.useOnMount=function(e){r.useEffect((function(){var r=e();return"function"==typeof r?r:void 0}),[])},exports.useOnUnload=function(e){r.useEffect((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[])},exports.useOnUnmount=function(e,n){void 0===n&&(n=[]),r.useEffect((function(){return e}),n)};
|
|
2
|
-
//# sourceMappingURL=v5.js.map
|
package/dist/v5.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v5.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/v5_test.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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 type { StoreAction } 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, };
|
|
19
|
-
/**
|
|
20
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
21
|
-
*/
|
|
22
|
-
export declare function isAsyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AsynchAction<S, F, A, P>;
|
|
23
|
-
/**
|
|
24
|
-
* Type guard function to test if an action is a asynchronous action.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isAsyncPromiseGetAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AsynchActionPromiseGet<S, F, A, P>;
|
|
27
|
-
/**
|
|
28
|
-
* Type guard function to test if an action is a synchronous action.
|
|
29
|
-
*/
|
|
30
|
-
export declare function isSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is SynchAction<S, F, P>;
|
|
31
|
-
/**
|
|
32
|
-
* Type guard function to test if an action is a synchronous action.
|
|
33
|
-
*/
|
|
34
|
-
export declare function isAdvancedSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>): action is AdvancedSynchAction<S, F, A, P>;
|
|
35
|
-
/**
|
|
36
|
-
* Utility to test an asynchronous action.
|
|
37
|
-
* @param action The action to test
|
|
38
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
39
|
-
*/
|
|
40
|
-
export declare function testAsyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>, test: (action: AsynchActionPromise<S, F, A, P>) => any | Promise<any>): any;
|
|
41
|
-
/**
|
|
42
|
-
* Utility to test an synchronous action.
|
|
43
|
-
* @param action The action to test
|
|
44
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
45
|
-
*/
|
|
46
|
-
export declare function testSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>, test: (action: SynchAction<S, F, P>) => any | Promise<any>): any;
|
|
47
|
-
/**
|
|
48
|
-
* Utility to test an advanced synchronous action.
|
|
49
|
-
* @param action The action to test
|
|
50
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
51
|
-
*/
|
|
52
|
-
export declare function testAdvancedSyncAction<S, F extends (...args: any[]) => any, A, P>(action: StateDecoratorAction<S, F, A, P>, test: (action: AdvancedSynchAction<S, F, A, P>) => any | Promise<any>): any;
|
|
53
|
-
/**
|
|
54
|
-
* Utility to test a V6 synchronous action using v5 test.
|
|
55
|
-
* @param action The action to test
|
|
56
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
57
|
-
*/
|
|
58
|
-
export declare function testV6SyncAction<S, F extends (...args: any[]) => any, A, P>(action: StoreAction<S, F, A, P>, test: (action: SynchAction<S, F, P>) => any | Promise<any>): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Utility to test a V6 synchronous action using v5 test.
|
|
61
|
-
* @param actionIn The action to test
|
|
62
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
63
|
-
*/
|
|
64
|
-
export declare function testV6AdvancedSyncAction<S, F extends (...args: any[]) => any, A, P>(actionIn: StoreAction<S, F, A, P>, test: (action: AdvancedSynchAction<S, F, A, P>) => any | Promise<any>): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* Utility to test a V6 synchronous action using v5 test.
|
|
67
|
-
* @param actionIn The action to test
|
|
68
|
-
* @param test The test function that takes the discrimined action type and cam return a promise
|
|
69
|
-
*/
|
|
70
|
-
export declare function testV6AsyncAction<S, F extends (...args: any[]) => any, A, P>(actionIn: StoreAction<S, F, A, P>, test: (action: AsynchAction<S, F, A, P>) => any | Promise<any>): any;
|