state-decorator 6.14.0-beta.1 → 6.14.0-dev.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.
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./impl"),t=function(){return(t=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},n=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var l=i[r];if(!e(t[l],n[l]))return!1}return!0}return t!=t&&n!=n};exports.devtools=function(){return function(){var e,n,o;try{e=window.__REDUX_DEVTOOLS_EXTENSION__||window.top.__REDUX_DEVTOOLS_EXTENSION__}catch(e){}return e?{init:function(t){var r,i;(n=e.connect({name:null!==(i=null===(r=t.options)||void 0===r?void 0:r.name)&&void 0!==i?i:"StateDecorator"})).init(t.state);var l=null,s=t.state;o=n.subscribe((function(e){var n,o,r,i;if("DISPATCH"===e.type&&e.state&&"ROLLBACK"!==(null===(n=e.payload)||void 0===n?void 0:n.type)){var f=JSON.parse(e.state);t.setState(f)}else"COMMIT"===(null===(o=e.payload)||void 0===o?void 0:o.type)?l=t.state:"ROLLBACK"===(null===(r=e.payload)||void 0===r?void 0:r.type)?null!=l&&t.setState(l):"RESET"===(null===(i=e.payload)||void 0===i?void 0:i.type)&&t.setState(s)}))},effects:function(e,o,r){if(null!=r){var i=t({},e.context);delete i.a,delete i.s,delete i.p,delete i.res,delete i.err,delete i.ds,n.send({type:e.name+" "+e.type,args:i.args,context:i},r)}return null},destroy:function(){o(),n=null}}:{init:function(){},destroy:null,effects:function(){return null}}}},exports.logDetailedEffects=function(e){return void 0===e&&(e=console),function(){var t="",o=e;if("development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV){var r=function(e,t){var o;if(t!==e){var r=null!=e?typeof e:typeof t;if("number"===r||"string"===r||"boolean"===r)o=e+" => "+(""===t?'""':t);else if(e&&e.length||t&&t.length)if(null==e)o="was "+e+", now contains "+t.length+" element(s)";else if(null==t)o="contained "+e.length+" element(s), now is "+t;else if(0===e.length)o="was empty, now contains "+t.length+" elements";else if(0===t.length)o="contained "+e.length+" elements, now is empty";else{var i=t.filter((function(t){return!e.find((function(e){return n(t,e)}))})),l=e.filter((function(e){return!t.find((function(t){return n(e,t)}))}));i.length>10&&(i=i.length+" element(s) added"),l.length>10&&(l=l.length+" element(s) removed"),o={added:i,removed:l}}else o=t}return o},i=function(e){return"string"==typeof e?'"'+e+'"':e};return{init:function(n){var r,l;t=(null===(r=n.options)||void 0===r?void 0:r.name)?"["+(null===(l=n.options)||void 0===l?void 0:l.name)+"]":"";var s=n.state;e.group(t,"initialState"),Object.keys(s).forEach((function(e){o.log(e,":",i(s[e]))})),e.groupEnd()},destroy:null,effects:function(e,n,l,s){var f,c=null===(f=e.context)||void 0===f?void 0:f.args,u=[t,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?u.push(s?"START":"CANCELLED"):"effects"===e.type?u.push("DONE"):u.push("FAILED")),null!=l||c&&0!==Object.keys(c).length?o.group.apply(o,u):o.log.apply(o,u),c&&Object.keys(c).length>0&&(o.group("Arguments"),c.forEach((function(e){o.log(e,":",i(e))})),o.groupEnd()),null!=l){if(o.groupCollapsed("Before"),null==n)o.log("was null");else Object.keys(n).forEach((function(e){o.log(e,":",i(n[e]))}));if(o.groupEnd(),o.groupCollapsed("After"),null==l)o.log("was null");else Object.keys(l).forEach((function(e){o.log(e,":",i(l[e]))}));if(o.groupEnd(),null!=l){o.group("Diff");var a=function(e,t){var n={};"development"===process.env.NODE_ENV&&(e&&Object.keys(e).forEach((function(o){if(t.hasOwnProperty(o)){var i=e[o],l=t[o],s=r(i,l);s&&(n[o]=s)}else n[o]="was deleted"})),Object.keys(t).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var i=t[o];n[o]=r(void 0,i)}})));return n}(n,l);Object.keys(a).forEach((function(e){return o.log(e,":",a[e])})),o.groupEnd()}}return o.groupEnd(),null}}}return{init:function(){},destroy:null,effects:function(){return null}}}},exports.logEffects=function(e){return void 0===e&&(e=console.log),function(){var t=e,n="";return{init:function(e){var o,r;if("development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV){n=(null===(o=e.options)||void 0===o?void 0:o.name)?"["+(null===(r=e.options)||void 0===r?void 0:r.name)+"]":"";var i=e.state;t(n,"initialState",i)}},destroy:null,effects:function(e,o,r,i){return"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||t(n,e.name,e.type,null===r?"no effect":r,e.isAsync?"preEffects"!==e.type||i?"loading: "+i:"Promise cancelled":""),null}}}},exports.optimisticActions=function(n){return function(){var o=null,r={history:null,optimisticActions:{},shouldRecordHistory:!1},i=function(t){return(n||e.globalConfig.clone)(t)},l=function(e,t){return e+"_"+t};function s(e,t,n,o){void 0===o&&(o=null);var l=r.shouldRecordHistory,s=r.history;if(l){null===s&&(r.history=[]);var f=i(n);delete f.state,delete f.s,delete f.abortSignal,f.error=n.err,f.err=n.err;var c={effectType:t,actionName:e,promiseId:n.promiseId,ctx:f,beforeEffectState:o?i(o):null};r.history.push(c)}}function f(e,t,n){void 0===n&&(n=void 0);var o=r.optimisticActions,i=r.history,s=l(e,t);if(delete o[s],0===Object.keys(o).length)r.history=null,r.shouldRecordHistory=!1;else{var f=void 0===n?i.findIndex((function(e){return l(e.actionName,e.promiseId)===s})):n;if(0===f){var c=i.slice(1).findIndex((function(e){return null!=e.beforeEffectState}))+1;i.splice(0,c)}else void 0===n&&(i[f].beforeEffectState=null)}}return{init:function(e){o=e},destroy:function(){o=null,r.history=null,r.optimisticActions={},r.shouldRecordHistory=!1},effects:function(n,i,c,u){var a=n.name,p=n.type,d=n.context,v=n.isAsync;if((null!=c&&e.isSimpleSyncAction(o.actions[a])||"onPropsChange"===a||null!=o.actions[a][p])&&s(a,p,d,null),v){var y,g=o.actions[a];if(u&&null!=g.optimisticEffects&&"preEffects"===p)return r.shouldRecordHistory=!0,r.optimisticActions[l(a,d.promiseId)]=!0,s(a,"optimisticEffects",d,y=c||i),{loading:!1,state:g.optimisticEffects(t(t({},d),{state:y,s:y}))};if(null!=g.optimisticEffects&&"effects"===p)return f(a,d.promiseId),{loading:u,state:c};if(null!=g.optimisticEffects&&"errorEffects"===p)return{state:y=function(n,i){for(var l=r.history,s=l.findIndex((function(e){return"optimisticEffects"===e.effectType&&e.actionName===n&&e.promiseId===i})),c=l[s].beforeEffectState,u=s+1;u<l.length;u++){var a=l[u];a.beforeEffectState&&(a.beforeEffectState=c);var p=t(t({},a.ctx),{state:c,s:c});c="onPropsChange"===a.actionName?(Array.isArray(o.options.onPropsChange)?o.options.onPropsChange:[o.options.onPropsChange])[p.index].effects(p):e.isSimpleSyncAction(o.actions[a.actionName])?o.actions[a.actionName](p):o.actions[a.actionName][a.effectType](p)}return f(n,i,s),c}(a,d.promiseId),loading:u}}return null}}}};
2
- //# sourceMappingURL=middlewares.js.map
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/test.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"test.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__assign","assign","t","s","i","n","arguments","length","apply","this","TypeError","String","__","constructor","create"],"mappings":"4FAgBIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB,CAAEC,UAAW,cAAgBC,OAAS,SAAUL,EAAGC,GAAKD,EAAEI,UAAYH,IACvE,SAAUD,EAAGC,GAAK,IAAK,IAAIK,KAAKL,EAAOC,OAAOK,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,MAC3EN,EAAGC,IAWrB,IAAIS,EAAW,WAQlB,OAPAA,EAAWR,OAAOS,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAIR,KADTO,EAAIG,UAAUF,GACOZ,OAAOK,UAAUC,eAAeC,KAAKI,EAAGP,KAAIM,EAAEN,GAAKO,EAAEP,IAE9E,OAAOM,IAEKM,MAAMC,KAAMH,usEAhBzB,SAAmBhB,EAAGC,GACzB,GAAiB,mBAANA,GAA0B,OAANA,EAC3B,MAAM,IAAImB,UAAU,uBAAyBC,OAAOpB,GAAK,iCAE7D,SAASqB,IAAOH,KAAKI,YAAcvB,EADnCD,EAAcC,EAAGC,GAEjBD,EAAEO,UAAkB,OAANN,EAAaC,OAAOsB,OAAOvB,IAAMqB,EAAGf,UAAYN,EAAEM,UAAW,IAAIe"}
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":""}