state-decorator 6.10.0 → 7.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -12,6 +12,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
14
  ***************************************************************************** */
15
+ import { Context } from 'react';
15
16
  import { setGlobalConfig, GlobalConfig, ParallelActionError } from './impl';
16
17
  import { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, ConflictPolicy, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps } from './types';
17
18
  export { DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, ParallelActionError, StoreOptions, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, ConflictPolicy, GlobalConfig, Middleware, setGlobalConfig, LoadingProps, AbortActionCallback, };
@@ -90,66 +91,63 @@ export declare function createStore<S, A extends DecoratedActions, P, DS = {}>(g
90
91
  * A react hook to get a state slice. Will be refresh if, and only if, one property of the slice has changed
91
92
  * @param store The store to listen to.
92
93
  * @param slicerFunc A function that returns a state slice
93
- * @param comparator An optional function to compare if slice property has changed (shallow test by default)
94
94
  * @returns The state slice.
95
95
  */
96
96
  export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, SLICE>(store: StoreApi<S, A, P, DS>, slicerFunc: (ctx: StateListenerContext<S, DS, A>) => SLICE): SLICE;
97
- export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>>(store: StoreApi<S, A, P, DS>, properties: K[]): Pick<StateListenerContext<S, DS, A>, K>;
98
97
  /**
99
- * Binds the store to this component.
100
- * Store will be destroyed when component is unmouted.
101
- * Props passed to actions will come from this components.
102
- * If store is configured to react of props changes, it will used passed props.
103
- * A store must be bound to only one React component.
104
- * This component will be refreshed for every change in the store.
105
- *
98
+ * A react hook to get a state slice. Will be refresh if, and only if, one property of the slice has changed
106
99
  * @param store The store to listen to.
107
- * @param props The parent component props
108
- * @returns The state, actions and isLoading function.
100
+ * @param properties list of properties to extract from store
101
+ * @returns The state slice.
109
102
  */
110
- export declare function useStore<S, A extends DecoratedActions, P, DS = {}>(store: StoreApi<S, A, P, DS>, props?: P): {
111
- state: S & DS;
112
- actions: A;
113
- loading: boolean;
114
- isLoading: IsLoadingFunc<A>;
115
- abortAction: (actionName: keyof A, promiseId?: string) => boolean;
116
- loadingMap: LoadingMap<A>;
117
- errorMap: ErrorMap<A>;
118
- loadingParallelMap: LoadingParallelMap<A>;
119
- errorParallelMap: ErrorParallelMap<A>;
103
+ export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>, KL extends keyof A>(store: StoreApi<S, A, P, DS>, properties: K[], loadingProps?: KL[]): Pick<StateListenerContext<S, DS, A>, K> & {
104
+ loadingMap: LoadingMap<Pick<A, KL>>;
105
+ };
106
+ /**
107
+ * A react hook to get a state slice from a store context.
108
+ * The component be refreshed if, and only if, one property of the slice has changed.
109
+ * @param store The store to listen to.
110
+ * @param slicerFunc A function that returns a state slice
111
+ * @returns The state slice.
112
+ */
113
+ export declare function useStoreContextSlice<S, A extends DecoratedActions, P, DS, SLICE>(storeContext: Context<StoreApi<S, A, P, DS>>, slicerFunc: (ctx: StateListenerContext<S, DS, A>) => SLICE): SLICE;
114
+ /**
115
+ * A react hook to get a state slice from a store context.
116
+ * The component will be refreshed if, and only if, one property of the slice has changed.
117
+ * @param store The store to listen to.
118
+ * @param properties list of properties to extract from store
119
+ * @param loadingFlags list of action names to extract their loading state from store (available in loadingMap).
120
+ * @returns The state slice.
121
+ */
122
+ export declare function useStoreContextSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>, KL extends keyof A>(storeContext: Context<StoreApi<S, A, P, DS>>, properties: K[], loadingProps?: KL[]): Pick<StateListenerContext<S, DS, A>, K> & {
123
+ loadingMap: LoadingMap<Pick<A, KL>>;
120
124
  };
121
125
  /**
122
126
  * Binds the store to this component.
123
- * Store will be destroyed when component is unmouted.
127
+ * Store will NOT be destroyed when component is unmouted.
124
128
  * Props passed to actions will come from this components.
125
129
  * If store is configured to react of props changes, it will used passed props.
126
- * A store must be bound to only one React component.
127
- *
128
- * This component will NOT be refreshed for any change in the store.
130
+ * The component will be refreshed for every change in the store.
129
131
  *
130
132
  * @param store The store to listen to.
131
133
  * @param props The parent component props
134
+ * @param refreshOnUpdate Whether refresh the component if store state changes.
135
+ * @returns The store.
132
136
  */
133
- export declare function useBindStore<S, A extends DecoratedActions, P, DS = {}>(store: StoreApi<S, A, P, DS>, props?: P): StoreApi<S, A, P, DS>;
137
+ export declare function useStore<S, A extends DecoratedActions, P, DS = {}>(store: StoreApi<S, A, P, DS>, props?: P, refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
134
138
  /**
135
139
  * Creates and manages a local store.
140
+ * The component will be refreshed for every change in the store.
141
+ * Store will NOT be destroyed when component is unmouted.
142
+ *
136
143
  * @param getInitialState Function to compute initial state from props.
137
144
  * @param actionImpl Actions implementation.
138
145
  * @param props Owner component props to update state or react on prop changes
139
146
  * @param options The store options.
147
+ * @param refreshOnUpdate Whether refresh the component if store state changes.
140
148
  * @returns The state, actions and isLoading function.
141
149
  */
142
- export declare function useLocalStore<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[]): {
143
- state: S & DS;
144
- actions: A;
145
- loading: boolean;
146
- isLoading: IsLoadingFunc<A>;
147
- abortAction: (actionName: keyof A, promiseId?: string) => boolean;
148
- loadingMap: LoadingMap<A>;
149
- errorMap: ErrorMap<A>;
150
- loadingParallelMap: LoadingParallelMap<A>;
151
- errorParallelMap: ErrorParallelMap<A>;
152
- };
150
+ export declare function useLocalStore<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[], refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
153
151
  export default useLocalStore;
154
152
  /**
155
153
  * Creates a new object by picking properties to the object passed a first parameter
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,e=require("react"),n=require("./impl"),t=function(){return(t=Object.assign||function(r){for(var e,n=1,t=arguments.length;n<t;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(r[u]=e[u]);return r}).apply(this,arguments)};function u(r,e,n){if(n||2===arguments.length)for(var t,u=0,o=e.length;u<o;u++)!t&&u in e||(t||(t=Array.prototype.slice.call(e,0,u)),t[u]=e[u]);return r.concat(t||Array.prototype.slice.call(e))}function o(r,e,o,c){void 0===o&&(o={}),void 0===c&&(c=null);var i=n.createRef(),a=n.createRef(),l=n.createRef(),s=n.createRef(),f=n.createRef(),d=n.createRef(),p=n.createRef(),v=n.createRef(),g=n.createRef(),y=n.createRef(!1),M=n.createRef([]),b={},R=0;function A(r,e){var n=t(t({},r),e),u=t(t(t({},n),s.current),{isLoading:O,abortAction:m,loading:h(),loadingMap:j(),errorMap:x()});Object.keys(b).forEach((function(r){b[r](u)}))}function E(r){i.current=r,n.computeDerivedValues(i,l,a,o),A(i.current,a.current.state)}function L(t){var u;if(!y.current){l.current=t,y.current=!0,i.current=r(t);var b=new Set(null==o?void 0:o.initialActionsMarkedLoading);d.current=Object.keys(e).reduce((function(r,e){var t;return r[e]=b.has(e)?((t={})[n.DEFAULT_PROMISE_ID]=!0,t):{},r}),{}),p.current=Object.keys(e).reduce((function(r,e){return r[e]={},r}),{}),f.current={},v.current={},g.current={},a.current={state:null,deps:{}},M.current=[];var R={options:o,get state(){return i.current},actions:e,setState:E},L=function(r){var e,n=r();M.current.push(n),null===(e=n.init)||void 0===e||e.call(n,R)};null===(u=n.globalConfig.defaultMiddlewares)||void 0===u||u.forEach(L),null==c||c.forEach(L),n.computeDerivedValues(i,l,a,o),n.onPropChange(i,a,l,null,s,o,P,!0),(null==o?void 0:o.onMount)&&o.onMount(n.buildOnMountInvocationContext(i,a,l,s)),A(i.current,a.current.state)}}function P(r,e,t,u,c,s,f,p){void 0===f&&(f=!1),void 0===p&&(p=!1);var v=!1;if(y.current){var g=e,b=!!c&&n.isLoadingImpl(g||d.current,[t,null==s?void 0:s.promiseId]),R=n.runMiddlewares(M.current,i.current,r,b,t,u,c,s),E=R.newState,L=R.newLoading;if(null!=E&&(v=!0,i.current=E),b!==L&&(g=n.buildLoadingMap(g,t,(null==s?void 0:s.promiseId)||n.DEFAULT_PROMISE_ID,L),0===Object.keys(g).length&&(g=void 0)),null!=g&&(v=!0,d.current=g),v)n.computeDerivedValues(i,l,a,o),p||A(E||i.current,a.current.state);else if(f){n.computeDerivedValues(i,l,a,o)&&!p&&A(E||i.current,a.current.state)}}}var S=Object.keys(e);function O(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return n.isLoadingImpl.apply(void 0,u([d.current],r,!1))}function m(r,e){var t,u;void 0===e&&(e=n.DEFAULT_PROMISE_ID);var o=null===(u=null===(t=v.current[r])||void 0===t?void 0:t[e])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function h(){if(y.current){var r=d.current;return null!=Object.keys(r).find((function(e){var n=r[e];return Object.keys(n).find((function(r){return!!n[r]}))}))}return null}function j(){if(y.current){var r=d.current;return Object.keys(r).reduce((function(e,n){var t=r[n];return e[n]=null!=Object.keys(t).find((function(r){return!!t[r]})),e}),{})}return null}function x(){return y.current?n.buildErrorMap(p.current):null}return s.current=S.reduce((function(r,t){var u=e[t];return n.isSimpleSyncAction(u)?r[t]=n.decorateSimpleSyncAction(t,u,i,a,l,y,P):n.isAsyncAction(u)?r[t]=n.decorateAsyncAction({actionName:t,stateRef:i,derivedStateRef:a,propsRef:l,loadingMapRef:d,errorMapRef:p,actionsRef:s,promisesRef:v,conflictActionsRef:g,initializedRef:y,options:o,setState:P,action:n.computeAsyncActionInput(u)}):n.isSyncAction(u)&&(r[t]=n.decorateSyncAction(t,u,i,a,l,s,y,f,o,P)),r}),{}),{getConfig:function(){return{getInitialState:r,options:o,actions:e}},setProps:function(r){var e=l.current;l.current=r,y.current?n.onPropChange(i,a,l,e,s,o,P,!1):L(r)},addStateListener:function(r){var e="".concat(R++);return b[e]=r,function(){delete b[e]}},init:L,destroy:function(){var r;y.current&&(null===(r=null==o?void 0:o.onUnmount)||void 0===r||r.call(o,n.buildOnMountInvocationContext(i,a,l,s)),l.current=null,i.current=null,d.current=null,p.current=null,v.current=null,g.current=null,a.current=null,Object.keys(f.current).forEach((function(r){clearTimeout(f.current[r])})),f.current=null,b={},y.current=!1,M.current.forEach((function(r){var e;null===(e=r.destroy)||void 0===e||e.call(r)})),M.current=[])},isLoading:O,abortAction:m,get actions(){return s.current},get state(){return y.current?t(t({},i.current),a.current.state):null},get loading(){return h()},get loadingMap(){return j()},get errorMap(){return x()},get loadingParallelMap(){return y.current?d.current:null},get errorParallelMap(){return y.current?p.current:null}}}function c(r,n){void 0===n&&(n=null);var t=e.useReducer((function(r){return r>100?0:r+1}),0)[1],u=e.useRef(r);return r.setProps(n),e.useLayoutEffect((function(){return u.current.addStateListener((function(){t()}))}),[]),e.useEffect((function(){return function(){return r.destroy()}}),[]),{state:r.state,actions:r.actions,loading:r.loading,isLoading:r.isLoading,abortAction:r.abortAction,loadingMap:r.loadingMap,errorMap:r.errorMap,loadingParallelMap:r.loadingParallelMap,errorParallelMap:r.errorParallelMap}}function i(r,n,t,u,i){var a=e.useRef();return null==a.current&&(a.current=o(r,n,u,i)),c(a.current,t)}function a(r,e){return e.reduce((function(e,n){return r.hasOwnProperty(n)&&(e[n]=r[n]),e}),{})}exports.ConflictPolicy=void 0,(r=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse",Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return n.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return n.setGlobalConfig}}),exports.createStore=o,exports.default=i,exports.pick=a,exports.slice=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return function(e){return a(e,r)}},exports.useBindStore=function(r,n){return void 0===n&&(n=null),e.useRef(r),r.setProps(n),e.useEffect((function(){return function(){return r.destroy()}}),[]),r},exports.useLocalStore=i,exports.useStore=c,exports.useStoreSlice=function(r,u){var o=e.useReducer((function(r){return r>100?0:r+1}),0)[1],c=e.useMemo((function(){return u instanceof Function?u:function(r){return a(r,u)}}),[u]),i=e.useRef(null);if(null===i.current){var l=r.state;i.current=c(t(t(t({},l),r.actions),{actions:r.actions,loading:r.loading,isLoading:r.isLoading,abortAction:r.abortAction,loadingMap:r.loadingMap,errorMap:r.errorMap}))}return e.useLayoutEffect((function(){return r.addStateListener((function(r){var e,t=c(r),u=i.current,a=n.globalConfig.comparator;e=null==u||!a(t,u),i.current=t,e&&o()}))}),[]),i.current};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,e=require("react"),n=require("./impl"),t=function(){return(t=Object.assign||function(r){for(var e,n=1,t=arguments.length;n<t;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(r[u]=e[u]);return r}).apply(this,arguments)};function u(r,e,n){if(n||2===arguments.length)for(var t,u=0,o=e.length;u<o;u++)!t&&u in e||(t||(t=Array.prototype.slice.call(e,0,u)),t[u]=e[u]);return r.concat(t||Array.prototype.slice.call(e))}function o(r,e,o,c){void 0===o&&(o={}),void 0===c&&(c=null);var i=n.createRef(),l=n.createRef(),a=n.createRef(),f=n.createRef(),s=n.createRef(),d=n.createRef(),p=n.createRef(),v=n.createRef(),g=n.createRef(),y=n.createRef(!1),R=n.createRef([]),b={},A=0;function E(r,e){var n=t(t({},r),e),u=t(t(t({},n),f.current),{isLoading:P,abortAction:m,loading:h(),loadingMap:x(),errorMap:j()});Object.keys(b).forEach((function(r){b[r](u)}))}function M(r){i.current=r,n.computeDerivedValues(i,a,l,o),E(i.current,l.current.state)}function S(t){var u;if(!y.current){a.current=t,y.current=!0,i.current=r(t);var b=new Set(null==o?void 0:o.initialActionsMarkedLoading);d.current=Object.keys(e).reduce((function(r,e){var t;return r[e]=b.has(e)?((t={})[n.DEFAULT_PROMISE_ID]=!0,t):{},r}),{}),p.current=Object.keys(e).reduce((function(r,e){return r[e]={},r}),{}),s.current={},v.current={},g.current={},l.current={state:null,deps:{}},R.current=[];var A={options:o,get state(){return i.current},actions:e,setState:M},S=function(r){var e,n=r();R.current.push(n),null===(e=n.init)||void 0===e||e.call(n,A)};null===(u=n.globalConfig.defaultMiddlewares)||void 0===u||u.forEach(S),null==c||c.forEach(S),n.computeDerivedValues(i,a,l,o),n.onPropChange(i,l,a,null,f,o,L,!0),(null==o?void 0:o.onMount)&&o.onMount(n.buildOnMountInvocationContext(i,l,a,f)),E(i.current,l.current.state)}}function L(r,e,t,u,c,f,s,p){void 0===s&&(s=!1),void 0===p&&(p=!1);var v=!1;if(y.current){var g=e,b=!!c&&n.isLoadingImpl(g||d.current,[t,null==f?void 0:f.promiseId]),A=n.runMiddlewares(R.current,i.current,r,b,t,u,c,f),M=A.newState,S=A.newLoading;if(null!=M&&(v=!0,i.current=M),b!==S&&(g=n.buildLoadingMap(g,t,(null==f?void 0:f.promiseId)||n.DEFAULT_PROMISE_ID,S),0===Object.keys(g).length&&(g=void 0)),null!=g&&(v=!0,d.current=g),v)n.computeDerivedValues(i,a,l,o),p||E(M||i.current,l.current.state);else if(s){n.computeDerivedValues(i,a,l,o)&&!p&&E(M||i.current,l.current.state)}}}var O=Object.keys(e);function P(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return n.isLoadingImpl.apply(void 0,u([d.current],r,!1))}function m(r,e){var t,u;void 0===e&&(e=n.DEFAULT_PROMISE_ID);var o=null===(u=null===(t=v.current[r])||void 0===t?void 0:t[e])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function h(){if(y.current){var r=d.current;return null!=Object.keys(r).find((function(e){var n=r[e];return Object.keys(n).find((function(r){return!!n[r]}))}))}return null}function x(){if(y.current){var r=d.current;return Object.keys(r).reduce((function(e,n){var t=r[n];return e[n]=null!=Object.keys(t).find((function(r){return!!t[r]})),e}),{})}return null}function j(){return y.current?n.buildErrorMap(p.current):null}return f.current=O.reduce((function(r,t){var u=e[t];return n.isSimpleSyncAction(u)?r[t]=n.decorateSimpleSyncAction(t,u,i,l,a,y,L):n.isAsyncAction(u)?r[t]=n.decorateAsyncAction({actionName:t,stateRef:i,derivedStateRef:l,propsRef:a,loadingMapRef:d,errorMapRef:p,actionsRef:f,promisesRef:v,conflictActionsRef:g,initializedRef:y,options:o,setState:L,action:n.computeAsyncActionInput(u)}):n.isSyncAction(u)&&(r[t]=n.decorateSyncAction(t,u,i,l,a,f,y,s,o,L)),r}),{}),{getConfig:function(){return{getInitialState:r,options:o,actions:e}},setProps:function(r){var e=a.current;a.current=r,y.current?n.onPropChange(i,l,a,e,f,o,L,!1):S(r)},addStateListener:function(r){var e="".concat(A++);return b[e]=r,function(){delete b[e]}},init:S,destroy:function(){var r;y.current&&(null===(r=null==o?void 0:o.onUnmount)||void 0===r||r.call(o,n.buildOnMountInvocationContext(i,l,a,f)),a.current=null,i.current=null,d.current=null,p.current=null,v.current=null,g.current=null,l.current=null,Object.keys(s.current).forEach((function(r){clearTimeout(s.current[r])})),s.current=null,b={},y.current=!1,R.current.forEach((function(r){var e;null===(e=r.destroy)||void 0===e||e.call(r)})),R.current=[])},isLoading:P,abortAction:m,get actions(){return f.current},get state(){return y.current?t(t({},i.current),l.current.state):null},get loading(){return h()},get loadingMap(){return x()},get errorMap(){return j()},get loadingParallelMap(){return y.current?d.current:null},get errorParallelMap(){return y.current?p.current:null}}}function c(r,u,o){var c=e.useReducer((function(r){return r>100?0:r+1}),0)[1],i=e.useMemo((function(){return u instanceof Function?u:function(r){return a(r,u)}}),[u]),l=e.useMemo((function(){return function(r){return null!=o&&o.length>0?a(r.loadingMap,o):null}}),[o]),f=e.useRef(null),s=e.useRef(null);if(null===f.current){var d=t(t(t({},r.state),r.actions),a(r,["actions","loading","isLoading","abortAction","loadingMap","errorMap"]));f.current=i(d),s.current=l(d)}e.useLayoutEffect((function(){return r.addStateListener((function(r){var e,t=i(r),u=l(r),o=f.current,a=n.globalConfig.comparator;e=null==o||!a(t,o)||!a(u,s.current),f.current=t,s.current=u,e&&c()}))}),[]);var p=f.current,v=s.current;return null==v?p:t(t({},p),{loadingMap:v})}function i(r,n,t){void 0===n&&(n=null),void 0===t&&(t=!0);var u=e.useReducer((function(r){return r>100?0:r+1}),0)[1],o=e.useRef(r);return r.setProps(n),e.useLayoutEffect((function(){t&&o.current.addStateListener((function(){u()}))}),[t]),r}function l(r,n,t,u,c,l){void 0===l&&(l=!0);var a=e.useRef();return null==a.current&&(a.current=o(r,n,u,c)),e.useEffect((function(){return function(){var r;null===(r=a.current)||void 0===r||r.destroy()}}),[]),i(a.current,t,l)}function a(r,e){return e.reduce((function(e,n){return r.hasOwnProperty(n)&&(e[n]=r[n]),e}),{})}exports.ConflictPolicy=void 0,(r=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse",Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return n.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return n.setGlobalConfig}}),exports.createStore=o,exports.default=l,exports.pick=a,exports.slice=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return function(e){return a(e,r)}},exports.useLocalStore=l,exports.useStore=i,exports.useStoreContextSlice=function(r,n,t){return c(e.useContext(r),n,t)},exports.useStoreSlice=c;
2
2
  //# sourceMappingURL=index.js.map
package/middlewares.js CHANGED
@@ -1,2 +1,2 @@
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 c=i[r];if(!e(t[c],n[c]))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 c=null,l=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 s=JSON.parse(e.state);t.setState(s)}else"COMMIT"===(null===(o=e.payload)||void 0===o?void 0:o.type)?c=t.state:"ROLLBACK"===(null===(r=e.payload)||void 0===r?void 0:r.type)?null!=c&&t.setState(c):"RESET"===(null===(i=e.payload)||void 0===i?void 0:i.type)&&t.setState(l)}))},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:"".concat(e.name," ").concat(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="".concat(e," => ").concat(""===t?'""':t);else if(e&&e.length||t&&t.length)if(null==e)o="was ".concat(e,", now contains ").concat(t.length," element(s)");else if(null==t)o="contained ".concat(e.length," element(s), now is ").concat(t);else if(0===e.length)o="was empty, now contains ".concat(t.length," elements");else if(0===t.length)o="contained ".concat(e.length," elements, now is empty");else{var i=t.filter((function(t){return!e.find((function(e){return n(t,e)}))})),c=e.filter((function(e){return!t.find((function(t){return n(e,t)}))}));i.length>10&&(i="".concat(i.length," element(s) added")),c.length>10&&(c="".concat(c.length," element(s) removed")),o={added:i,removed:c}}else o=t}return o},i=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(n){var r,c;t=(null===(r=n.options)||void 0===r?void 0:r.name)?"[".concat(null===(c=n.options)||void 0===c?void 0:c.name,"]"):"";var l=n.state;e.group(t,"initialState"),Object.keys(l).forEach((function(e){o.log(e,":",i(l[e]))})),e.groupEnd()},destroy:null,effects:function(e,n,c,l){var s,f=null===(s=e.context)||void 0===s?void 0:s.args,u=[t,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?u.push(l?"START":"CANCELLED"):"effects"===e.type?u.push("DONE"):u.push("FAILED")),null!=c||f&&0!==Object.keys(f).length?o.group.apply(o,u):o.log.apply(o,u),f&&Object.keys(f).length>0&&(o.group("Arguments"),f.forEach((function(e){o.log(e,":",i(e))})),o.groupEnd()),null!=c){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==c)o.log("was null");else Object.keys(c).forEach((function(e){o.log(e,":",i(c[e]))}));if(o.groupEnd(),null!=c){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],c=t[o],l=r(i,c);l&&(n[o]=l)}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,c);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)?"[".concat(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: ".concat(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)},c=function(e,t){return"".concat(e,"_").concat(t)};function l(e,t,n,o){void 0===o&&(o=null);var c=r.shouldRecordHistory,l=r.history;if(c){null===l&&(r.history=[]);var s=i(n);delete s.state,delete s.s,delete s.abortSignal,s.error=n.err,s.err=n.err;var f={effectType:t,actionName:e,promiseId:n.promiseId,ctx:s,beforeEffectState:o?i(o):null};r.history.push(f)}}function s(e,t,n){void 0===n&&(n=void 0);var o=r.optimisticActions,i=r.history,l=c(e,t);if(delete o[l],0===Object.keys(o).length)r.history=null,r.shouldRecordHistory=!1;else{var s=void 0===n?i.findIndex((function(e){return c(e.actionName,e.promiseId)===l})):n;if(0===s){var f=i.slice(1).findIndex((function(e){return null!=e.beforeEffectState}))+1;i.splice(0,f)}else void 0===n&&(i[s].beforeEffectState=null)}}return{init:function(e){o=e},destroy:function(){o=null,r.history=null,r.optimisticActions={},r.shouldRecordHistory=!1},effects:function(n,i,f,u){var a=n.name,p=n.type,d=n.context,v=n.isAsync;if((null!=f&&e.isSimpleSyncAction(o.actions[a])||"onPropsChange"===a||null!=o.actions[a][p])&&l(a,p,d,null),v){var y,g=o.actions[a];if(u&&null!=g.optimisticEffects&&"preEffects"===p)return r.shouldRecordHistory=!0,r.optimisticActions[c(a,d.promiseId)]=!0,l(a,"optimisticEffects",d,y=f||i),{loading:!1,state:g.optimisticEffects(t(t({},d),{state:y,s:y}))};if(null!=g.optimisticEffects&&"effects"===p)return s(a,d.promiseId),{loading:u,state:f};if(null!=g.optimisticEffects&&"errorEffects"===p)return{state:y=function(n,i){for(var c=r.history,l=c.findIndex((function(e){return"optimisticEffects"===e.effectType&&e.actionName===n&&e.promiseId===i})),f=c[l].beforeEffectState,u=l+1;u<c.length;u++){var a=c[u];a.beforeEffectState&&(a.beforeEffectState=f);var p=t(t({},a.ctx),{state:f,s:f});f="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 s(n,i,l),f}(a,d.promiseId),loading:u}}return null}}}};
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,c=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 s=JSON.parse(e.state);t.setState(s)}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(c)}))},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:"".concat(e.name," ").concat(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="".concat(e," => ").concat(""===t?'""':t);else if(e&&e.length||t&&t.length)if(null==e)o="was ".concat(e,", now contains ").concat(t.length," element(s)");else if(null==t)o="contained ".concat(e.length," element(s), now is ").concat(t);else if(0===e.length)o="was empty, now contains ".concat(t.length," elements");else if(0===t.length)o="contained ".concat(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="".concat(i.length," element(s) added")),l.length>10&&(l="".concat(l.length," element(s) removed")),o={added:i,removed:l}}else o=t}return o},i=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(n){var r,l;t=(null===(r=n.options)||void 0===r?void 0:r.name)?"[".concat(null===(l=n.options)||void 0===l?void 0:l.name,"]"):"";var c=n.state;e.group(t,"initialState"),Object.keys(c).forEach((function(e){o.log(e,":",i(c[e]))})),e.groupEnd()},destroy:null,effects:function(e,n,l,c){var s,f=null===(s=e.context)||void 0===s?void 0:s.args,a=[t,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?a.push(c?"START":"CANCELLED"):"effects"===e.type?a.push("DONE"):a.push("FAILED")),null!=l||f&&0!==Object.keys(f).length?o.group.apply(o,a):o.log.apply(o,a),f&&Object.keys(f).length>0&&(o.group("Arguments"),f.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 u=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],c=r(i,l);c&&(n[o]=c)}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(u).forEach((function(e){return o.log(e,":",u[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)?"[".concat(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: ".concat(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"".concat(e,"_").concat(t)};function c(e,t,n,o){void 0===o&&(o=null);var l=r.shouldRecordHistory,c=r.history;if(l){null===c&&(r.history=[]);var s=i(n);delete s.state,delete s.s,delete s.abortSignal,s.error=n.err,s.err=n.err;var f={effectType:t,actionName:e,promiseId:n.promiseId,ctx:s,beforeEffectState:o?i(o):null};r.history.push(f)}}function s(e,t,n){void 0===n&&(n=void 0);var o=r.optimisticActions,i=r.history,c=l(e,t);if(delete o[c],0===Object.keys(o).length)r.history=null,r.shouldRecordHistory=!1;else{var s=void 0===n?i.findIndex((function(e){return l(e.actionName,e.promiseId)===c})):n;if(0===s){var f=i.slice(1).findIndex((function(e){return null!=e.beforeEffectState}))+1;i.splice(0,f)}else void 0===n&&(i[s].beforeEffectState=null)}}return{init:function(e){o=e},destroy:function(){o=null,r.history=null,r.optimisticActions={},r.shouldRecordHistory=!1},effects:function(n,i,f,a){var u=n.name,p=n.type,d=n.context,v=n.isAsync;if((null!=f&&e.isSimpleSyncAction(o.actions[u])||"onPropsChange"===u||null!=o.actions[u][p])&&c(u,p,d,null),v){var y,g=o.actions[u];if(a&&null!=g.optimisticEffects&&"preEffects"===p)return r.shouldRecordHistory=!0,r.optimisticActions[l(u,d.promiseId)]=!0,c(u,"optimisticEffects",d,y=f||i),{loading:!1,state:t(t({},y),g.optimisticEffects(t(t({},d),{state:y,s:y})))};if(null!=g.optimisticEffects&&"effects"===p)return s(u,d.promiseId),{loading:a,state:f};if(null!=g.optimisticEffects&&"errorEffects"===p)return{state:y=function(n,i){for(var l=r.history,c=l.findIndex((function(e){return"optimisticEffects"===e.effectType&&e.actionName===n&&e.promiseId===i})),f=l[c].beforeEffectState,a=c+1;a<l.length;a++){var u=l[a];u.beforeEffectState&&(u.beforeEffectState=f);var p=t(t({},u.ctx),{state:f,s:f});if("onPropsChange"===u.actionName){var d=Array.isArray(o.options.onPropsChange)?o.options.onPropsChange:[o.options.onPropsChange];f=t(t({},f),d[p.index].effects(p))}else f=e.isSimpleSyncAction(o.actions[u.actionName])?t(t({},f),o.actions[u.actionName](p)):t(t({},f),o.actions[u.actionName][u.effectType](p))}return s(n,i,c),f}(u,d.promiseId),loading:a}}return null}}}};
2
2
  //# sourceMappingURL=middlewares.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-decorator",
3
- "version": "6.10.0",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "React state management library",
5
5
  "main": "index.js",
6
6
  "module": "es/index.js",
package/types.d.ts CHANGED
@@ -76,8 +76,8 @@ export declare type PromiseProvider<S, DS, F extends (...args: any[]) => any, A,
76
76
  /**
77
77
  * Simple form of a synchronous action.
78
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> = {
79
+ export declare type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = Partial<S>> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
80
+ export declare type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
81
81
  /**
82
82
  * Function that update the state when the action is called.
83
83
  */
@@ -178,7 +178,7 @@ export declare type Middleware<S, A extends DecoratedActions, P> = {
178
178
  */
179
179
  destroy: () => void;
180
180
  };
181
- export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S> = {
181
+ export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
182
182
  /**
183
183
  * This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
184
184
  */
@@ -264,13 +264,13 @@ export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P,
264
264
  */
265
265
  isTriggerRetryError?: (e: Error) => boolean;
266
266
  };
267
- export declare type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
267
+ export declare type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
268
268
  /**
269
269
  * The request, returns a promise
270
270
  */
271
271
  getPromise: PromiseProvider<S, DS, F, A, P>;
272
272
  };
273
- export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
273
+ export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
274
274
  /**
275
275
  * The request, returns a promise that is a GET request.
276
276
  * A shortcut to set:
@@ -279,13 +279,13 @@ export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any,
279
279
  */
280
280
  getGetPromise: PromiseProvider<S, DS, F, A, P>;
281
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>;
282
+ export declare type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionPromise<S, F, A, P, DS, FxRes> | AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
283
+ export declare type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
284
284
  /**
285
285
  * S: The type of the state
286
286
  * A: The type of the actions to pass to the children (used to check keys only).
287
287
  */
288
- export declare type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = S> = {
288
+ export declare type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = Partial<S>> = {
289
289
  [Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
290
290
  };
291
291
  export declare type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
@@ -306,7 +306,7 @@ declare type DerivedStateOption<S, P, DS> = {
306
306
  export declare type OnPropsChangeOptions<S, DS, A, P> = {
307
307
  onMount?: boolean;
308
308
  getDeps: (p: P) => any[];
309
- effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => S;
309
+ effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => Partial<S>;
310
310
  sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A>) => void;
311
311
  };
312
312
  export declare type StoreOptions<S, A, P = {}, DS = {}> = {
package/v5_test.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("./index"),e=require("./impl"),n=function(){return(n=Object.assign||function(r){for(var e,n=1,t=arguments.length;n<t;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)};function t(r,e,n){if(n||2===arguments.length)for(var t,o=0,s=e.length;o<s;o++)!t&&o in e||(t||(t=Array.prototype.slice.call(e,0,o)),t[o]=e[o]);return r.concat(t||Array.prototype.slice.call(e))}function o(r){return!(r instanceof Function)&&(r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function s(r){return r instanceof Function}function i(r){return!(r instanceof Function||r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}Object.defineProperty(exports,"ConflictPolicy",{enumerable:!0,get:function(){return r.ConflictPolicy}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return r.setGlobalConfig}}),exports.isAdvancedSyncAction=i,exports.isAsyncAction=o,exports.isAsyncPromiseGetAction=function(r){return!(r instanceof Function||r.hasOwnProperty("promise")&&r.hasOwnProperty("promiseGet"))},exports.isSyncAction=s,exports.testAdvancedSyncAction=function(r,e){return i(r)?e(r):Promise.reject(new Error("This action is not a synchronous advanced action"))},exports.testAsyncAction=function(e,t){return o(e)?t(function(e){return"promiseGet"in e?n(n({},e),{promise:e.promiseGet,retryCount:3,conflictPolicy:r.ConflictPolicy.REUSE}):e}(e)):Promise.reject(new Error("This action is not an asynchronous action"))},exports.testSyncAction=function(r,e){return s(r)?e(r):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6AdvancedSyncAction=function(r,n){return e.isSyncAction(r)?(n({action:function(e,n,t){return r.effects({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,res:null,result:null,promiseId:null})},onActionDone:function(e,n,t,o,s){r.sideEffects({s:e,args:n,p:t,a:o,notifyWarning:s,ds:null,derived:null,state:e,props:t,actions:o,res:null,result:null,promiseId:null})}}),Promise.resolve()):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6AsyncAction=function(r,n){return e.isAsyncAction(r)?n({abortable:r.abortable,rejectPromiseOnError:r.rejectPromiseOnError,retryCount:r.retryCount,retryDelaySeed:r.retryDelaySeed,isTriggerRetryError:r.isTriggerRetryError,conflictPolicy:r.conflictPolicy,getPromiseId:r.getPromiseId,promise:function(n,t,o,s,i){return e.isAsyncGetPromiseAction(r)?r.getPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null}):r.getGetPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null})},promiseGet:function(n,t,o,s,i){return e.isAsyncGetPromiseGetAction(r)?r.getGetPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null}):null},reducer:function(e,n,t,o){return r.effects?r.effects({s:e,args:t,p:o,res:n,ds:null,derived:null,state:e,props:o,result:n,promiseId:null}):null},preReducer:function(e,n,t){return r.preEffects?r.preEffects({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,promiseId:null}):null},optimisticReducer:function(e,n,o){var s;return r.optimisticEffects?r.optimisticEffects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null===(s=r.getPromiseId)||void 0===s?void 0:s.call.apply(s,t([r],n,!1))}):null},errorReducer:function(e,n,o,s){var i;return r.errorEffects?r.errorEffects({s:e,args:o,p:s,err:n,ds:null,derived:null,state:e,props:s,error:n,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],o,!1))}):null},onDone:function(e,n,o,s,i,l){var c,u;null===(c=r.sideEffects)||void 0===c||c.call(r,{s:e,args:o,p:s,a:i,res:n,notifyWarning:l,ds:null,derived:null,state:e,props:s,actions:i,result:n,promiseId:null===(u=r.getPromiseId)||void 0===u?void 0:u.call.apply(u,t([r],o,!1))})},onFail:function(e,n,o,s,i,l){var c,u;null===(c=r.errorSideEffects)||void 0===c||c.call(r,{s:e,args:o,p:s,a:i,err:n,notifyWarning:l,ds:null,derived:null,state:e,props:s,actions:i,error:n,promiseId:null===(u=r.getPromiseId)||void 0===u?void 0:u.call.apply(u,t([r],o,!1))})},getErrorMessage:function(e,n,o){var s,i;return null===(s=r.getErrorMessage)||void 0===s?void 0:s.call(r,{err:e,p:o,args:n,ds:null,derived:null,state:null,s:null,error:e,props:o,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],n,!1))})},getSuccessMessage:function(e,n,o){var s,i;return null===(s=r.getSuccessMessage)||void 0===s?void 0:s.call(r,{res:e,args:n,p:o,ds:null,derived:null,state:null,s:null,result:e,props:o,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],n,!1))})}}):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6SyncAction=function(r,n){if(e.isSimpleSyncAction(r)){return n((function(e,n,t){return r({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,promiseId:null})})),Promise.resolve()}return Promise.reject(new Error("This action is not a synchronous action"))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("./index"),e=require("./impl"),n=function(){return(n=Object.assign||function(r){for(var e,n=1,t=arguments.length;n<t;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)};function t(r,e,n){if(n||2===arguments.length)for(var t,o=0,s=e.length;o<s;o++)!t&&o in e||(t||(t=Array.prototype.slice.call(e,0,o)),t[o]=e[o]);return r.concat(t||Array.prototype.slice.call(e))}function o(r){return!(r instanceof Function)&&(r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function s(r){return r instanceof Function}function i(r){return!(r instanceof Function||r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function l(r,e){return null==e?null:n(n({},r),e)}Object.defineProperty(exports,"ConflictPolicy",{enumerable:!0,get:function(){return r.ConflictPolicy}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return r.setGlobalConfig}}),exports.isAdvancedSyncAction=i,exports.isAsyncAction=o,exports.isAsyncPromiseGetAction=function(r){return!(r instanceof Function||r.hasOwnProperty("promise")&&r.hasOwnProperty("promiseGet"))},exports.isSyncAction=s,exports.testAdvancedSyncAction=function(r,e){return i(r)?e(r):Promise.reject(new Error("This action is not a synchronous advanced action"))},exports.testAsyncAction=function(e,t){return o(e)?t(function(e){return"promiseGet"in e?n(n({},e),{promise:e.promiseGet,retryCount:3,conflictPolicy:r.ConflictPolicy.REUSE}):e}(e)):Promise.reject(new Error("This action is not an asynchronous action"))},exports.testSyncAction=function(r,e){return s(r)?e(r):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6AdvancedSyncAction=function(r,n){return e.isSyncAction(r)?(n({action:function(e,n,t){return l(e,r.effects({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,res:null,result:null,promiseId:null}))},onActionDone:function(e,n,t,o,s){r.sideEffects({s:e,args:n,p:t,a:o,notifyWarning:s,ds:null,derived:null,state:e,props:t,actions:o,res:null,result:null,promiseId:null})}}),Promise.resolve()):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6AsyncAction=function(r,n){return e.isAsyncAction(r)?n({abortable:r.abortable,rejectPromiseOnError:r.rejectPromiseOnError,retryCount:r.retryCount,retryDelaySeed:r.retryDelaySeed,isTriggerRetryError:r.isTriggerRetryError,conflictPolicy:r.conflictPolicy,getPromiseId:r.getPromiseId,promise:function(n,t,o,s,i){return e.isAsyncGetPromiseAction(r)?r.getPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null}):r.getGetPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null})},promiseGet:function(n,t,o,s,i){return e.isAsyncGetPromiseGetAction(r)?r.getGetPromise({s:t,args:n,p:o,a:s,abortSignal:i,ds:null,derived:null,state:t,props:o,actions:s,promiseId:null}):null},reducer:function(e,n,t,o){return r.effects?l(e,r.effects({s:e,args:t,p:o,res:n,ds:null,derived:null,state:e,props:o,result:n,promiseId:null})):null},preReducer:function(e,n,t){return r.preEffects?l(e,r.preEffects({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,promiseId:null})):null},optimisticReducer:function(e,n,o){var s;return r.optimisticEffects?l(e,r.optimisticEffects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null===(s=r.getPromiseId)||void 0===s?void 0:s.call.apply(s,t([r],n,!1))})):null},errorReducer:function(e,n,o,s){var i;return r.errorEffects?l(e,r.errorEffects({s:e,args:o,p:s,err:n,ds:null,derived:null,state:e,props:s,error:n,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],o,!1))})):null},onDone:function(e,n,o,s,i,l){var c,u;null===(c=r.sideEffects)||void 0===c||c.call(r,{s:e,args:o,p:s,a:i,res:n,notifyWarning:l,ds:null,derived:null,state:e,props:s,actions:i,result:n,promiseId:null===(u=r.getPromiseId)||void 0===u?void 0:u.call.apply(u,t([r],o,!1))})},onFail:function(e,n,o,s,i,l){var c,u;null===(c=r.errorSideEffects)||void 0===c||c.call(r,{s:e,args:o,p:s,a:i,err:n,notifyWarning:l,ds:null,derived:null,state:e,props:s,actions:i,error:n,promiseId:null===(u=r.getPromiseId)||void 0===u?void 0:u.call.apply(u,t([r],o,!1))})},getErrorMessage:function(e,n,o){var s,i;return null===(s=r.getErrorMessage)||void 0===s?void 0:s.call(r,{err:e,p:o,args:n,ds:null,derived:null,state:null,s:null,error:e,props:o,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],n,!1))})},getSuccessMessage:function(e,n,o){var s,i;return null===(s=r.getSuccessMessage)||void 0===s?void 0:s.call(r,{res:e,args:n,p:o,ds:null,derived:null,state:null,s:null,result:e,props:o,promiseId:null===(i=r.getPromiseId)||void 0===i?void 0:i.call.apply(i,t([r],n,!1))})}}):Promise.reject(new Error("This action is not a synchronous action"))},exports.testV6SyncAction=function(r,n){if(e.isSimpleSyncAction(r)){return n((function(e,n,t){return l(e,r({s:e,args:n,p:t,ds:null,derived:null,state:e,props:t,promiseId:null}))})),Promise.resolve()}return Promise.reject(new Error("This action is not a synchronous action"))};
2
2
  //# sourceMappingURL=v5_test.js.map