state-decorator 7.0.0-rc7 → 7.0.0-rc8

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/es/helpers.d.ts CHANGED
@@ -1,33 +1,34 @@
1
1
  /**
2
2
  * Effect function that sets the first action argument to the specified prop.
3
+ * if dirtyProp is set
3
4
  */
4
- export declare function setArgIn<S, K extends keyof S>(propName: K): (ctx: {
5
+ export declare function setArgIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
5
6
  s: S;
6
7
  args: [S[K]];
7
8
  }) => Partial<S>;
8
9
  /**
9
10
  * Effect function that sets <code>true</code> in the specified prop.
10
11
  */
11
- export declare function setTrueIn<S, K extends keyof S>(propName: K): (ctx: {
12
+ export declare function setTrueIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
12
13
  s: S;
13
14
  }) => Partial<S>;
14
15
  /**
15
16
  * Effect function that sets <code>false</code> in the specified prop.
16
17
  */
17
- export declare function setFalseIn<S, K extends keyof S>(propName: K): (ctx: {
18
+ export declare function setFalseIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
18
19
  s: S;
19
20
  }) => Partial<S>;
20
21
  /**
21
22
  * Effect function that sets toggles the boolean value of the specified prop.
22
23
  */
23
- export declare function toggleProp<S, K extends keyof S>(propName: K): (ctx: {
24
+ export declare function toggleProp<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
24
25
  s: S;
25
26
  }) => Partial<S>;
26
27
  /**
27
28
  * Effect function that sets the update the specifed prop as an array using first action argument as index
28
29
  * and second as value to set.
29
30
  */
30
- export declare function setArgsInMap<S, K extends keyof S, T>(propName: K): (ctx: {
31
+ export declare function setArgsInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
31
32
  s: S;
32
33
  args: [string, T];
33
34
  }) => Partial<S>;
@@ -35,14 +36,14 @@ export declare function setArgsInMap<S, K extends keyof S, T>(propName: K): (ctx
35
36
  * Effect function that sets the update the specifed prop as an array using first action argument as index
36
37
  * and second as value to set.
37
38
  */
38
- export declare function setArgsInArray<S, K extends keyof S, T>(propName: K): (ctx: {
39
+ export declare function setArgsInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
39
40
  s: S;
40
41
  args: [number, T];
41
42
  }) => Partial<S>;
42
43
  /**
43
44
  * Effect function that sets the asynchronous action result to the specified prop.
44
45
  */
45
- export declare function setResIn<S, K extends keyof S>(propName: K): (ctx: {
46
+ export declare function setResIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
46
47
  s: S;
47
48
  res: S[K];
48
49
  }) => Partial<S>;
@@ -50,7 +51,7 @@ export declare function setResIn<S, K extends keyof S>(propName: K): (ctx: {
50
51
  * Effect function that sets the update the specifed prop as an array using first action argument as index
51
52
  * and second as value to set.
52
53
  */
53
- export declare function setResInArray<S, K extends keyof S, T>(propName: K): (ctx: {
54
+ export declare function setResInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
54
55
  s: S;
55
56
  args: [number];
56
57
  res: T;
@@ -59,7 +60,7 @@ export declare function setResInArray<S, K extends keyof S, T>(propName: K): (ct
59
60
  * Effect function that sets the update the specifed prop as an array using first action argument as index
60
61
  * and second as value to set.
61
62
  */
62
- export declare function setResInMap<S, K extends keyof S, T>(propName: K): (ctx: {
63
+ export declare function setResInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
63
64
  s: S;
64
65
  args: [string];
65
66
  res: T;
package/es/helpers.js CHANGED
@@ -1,2 +1,2 @@
1
- var r=function(){return r=Object.assign||function(r){for(var n,t=1,u=arguments.length;t<u;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(r[e]=n[e]);return r},r.apply(this,arguments)};function n(r,n,t){if(t||2===arguments.length)for(var u,e=0,o=n.length;e<o;e++)!u&&e in n||(u||(u=Array.prototype.slice.call(n,0,e)),u[e]=n[e]);return r.concat(u||Array.prototype.slice.call(n))}function t(r){return function(n){var t,u=n.s,e=n.args[0];return u[r]===e?null:((t={})[r]=e,t)}}function u(r){return function(n){var t;return n.s[r]?null:((t={})[r]=!0,t)}}function e(r){return function(n){var t;return n.s[r]?((t={})[r]=!1,t):null}}function o(r){return function(n){var t,u=n.s;return(t={})[r]=!u[r],t}}function c(n){return function(t){var u,e,o=t.s,c=t.args,i=c[0],a=c[1];return(u={})[n]=r(r({},o[n]),((e={})[i]=a,e)),u}}function i(r){return function(t){var u,e=t.s,o=t.args,c=o[0],i=o[1],a=n([],e[r],!0);return a[c]=i,(u={})[r]=a,u}}function a(r){return function(n){var t,u=n.res;return(t={})[r]=u,t}}function f(r){return function(t){var u,e=t.s,o=t.args[0],c=t.res,i=n([],e[r],!0);return i[o]=c,(u={})[r]=i,u}}function s(n){return function(t){var u,e,o=t.s,c=t.args[0],i=t.res;return(u={})[n]=r(r({},o[n]),((e={})[c]=i,e)),u}}export{t as setArgIn,i as setArgsInArray,c as setArgsInMap,e as setFalseIn,a as setResIn,f as setResInArray,s as setResInMap,u as setTrueIn,o as toggleProp};
1
+ var r=function(){return r=Object.assign||function(r){for(var n,t=1,u=arguments.length;t<u;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(r[e]=n[e]);return r},r.apply(this,arguments)};function n(r,n,t){if(t||2===arguments.length)for(var u,e=0,o=n.length;e<o;e++)!u&&e in n||(u||(u=Array.prototype.slice.call(n,0,e)),u[e]=n[e]);return r.concat(u||Array.prototype.slice.call(n))}function t(r,n){return n&&(r[n]=!0),r}function u(r,n){return function(u){var e,o=u.s,c=u.args[0];return o[r]===c?null:t(((e={})[r]=c,e),n)}}function e(r,n){return function(u){var e;return u.s[r]?null:t(((e={})[r]=!0,e),n)}}function o(r,n){return function(u){var e;return u.s[r]?t(((e={})[r]=!1,e),n):null}}function c(r,n){return function(u){var e,o=u.s;return t(((e={})[r]=!o[r],e),n)}}function i(n,u){return function(e){var o,c,i=e.s,a=e.args,f=a[0],s=a[1];return t(((o={})[n]=r(r({},i[n]),((c={})[f]=s,c)),o),u)}}function a(r,u){return function(e){var o,c=e.s,i=e.args,a=i[0],f=i[1],s=n([],c[r],!0);return s[a]=f,t(((o={})[r]=s,o),u)}}function f(r,n){return function(u){var e,o=u.res;return t(((e={})[r]=o,e),n)}}function s(r,u){return function(e){var o,c=e.s,i=e.args[0],a=e.res,f=n([],c[r],!0);return f[i]=a,t(((o={})[r]=f,o),u)}}function l(n,u){return function(e){var o,c,i=e.s,a=e.args[0],f=e.res;return t(((o={})[n]=r(r({},i[n]),((c={})[a]=f,c)),o),u)}}export{u as setArgIn,a as setArgsInArray,i as setArgsInMap,o as setFalseIn,f as setResIn,s as setResInArray,l as setResInMap,e as setTrueIn,c as toggleProp};
2
2
  //# sourceMappingURL=helpers.js.map
package/es/index.d.ts CHANGED
@@ -109,7 +109,7 @@ export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K ex
109
109
  * @param store The store to listen to.
110
110
  * @returns The store.
111
111
  */
112
- export declare function useSyncStore<S, A extends DecoratedActions, P, DS>(store: StoreApi<S, A, P, DS>): StateListenerContext<S, DS, A>;
112
+ export declare function useStore<S, A extends DecoratedActions, P, DS>(store: StoreApi<S, A, P, DS>): StateListenerContext<S, DS, A>;
113
113
  /**
114
114
  * A react hook to get a state slice from a store context.
115
115
  * The component be refreshed if, and only if, one property of the slice has changed.
package/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import r,{useMemo as n,useContext as e,useRef as t,useEffect as u,useReducer as o,useLayoutEffect as c}from"react";import{createRef as i,isSimpleSyncAction as a,decorateSimpleSyncAction as l,isAsyncAction as f,decorateAsyncAction as s,computeAsyncActionInput as d,isSyncAction as v,decorateSyncAction as p,globalConfig as O,onPropChange as _,DEFAULT_PROMISE_ID as E,fixDerivedDeps as S,computeDerivedValues as y,buildOnMountInvocationContext as g,buildOnUnMountInvocationContext as L,isLoadingImpl as h,runMiddlewares as b,buildLoadingMap as A,buildErrorMap as m}from"./impl";export{EffectError,ParallelActionError,setGlobalConfig}from"./impl";import{logDetailedEffects as R}from"./development";var T=function(){return T=Object.assign||function(r){for(var n,e=1,t=arguments.length;e<t;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r},T.apply(this,arguments)};function w(r){var n={exports:{}};return r(n,n.exports),n.exports}var M="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},j=r.useState,D=r.useEffect,x=r.useLayoutEffect,V=r.useDebugValue;function k(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!M(r,e)}catch(r){return!0}}var C="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,n){var e=n(),t=j({inst:{value:e,getSnapshot:n}}),u=t[0].inst,o=t[1];return x((function(){u.value=e,u.getSnapshot=n,k(u)&&o({inst:u})}),[r,e,n]),D((function(){return k(u)&&o({inst:u}),r((function(){k(u)&&o({inst:u})}))}),[r]),V(e),e},I={useSyncExternalStore:void 0!==r.useSyncExternalStore?r.useSyncExternalStore:C},P=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function u(r){for(var n=arguments.length,e=new Array(n>1?n-1:0),u=1;u<n;u++)e[u-1]=arguments[u];!function(r,n,e){var u=t.ReactDebugCurrentFrame.getStackAddendum();""!==u&&(n+="%s",e=e.concat([u]));var o=e.map((function(r){return String(r)}));o.unshift("Warning: "+n),Function.prototype.apply.call(console[r],console,o)}("error",r,e)}var o="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},c=n.useState,i=n.useEffect,a=n.useLayoutEffect,l=n.useDebugValue,f=!1,s=!1;function d(r){var n=r.getSnapshot,e=r.value;try{var t=n();return!o(e,t)}catch(r){return!0}}var v=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(r,n,e){return n()}:function(r,e,t){f||void 0!==n.startTransition&&(f=!0,u("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=e();if(!s){var p=e();o(v,p)||(u("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var O=c({inst:{value:v,getSnapshot:e}}),_=O[0].inst,E=O[1];return a((function(){_.value=v,_.getSnapshot=e,d(_)&&E({inst:_})}),[r,v,e]),i((function(){d(_)&&E({inst:_});return r((function(){d(_)&&E({inst:_})}))}),[r]),l(v),v},p=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:v;e.useSyncExternalStore=p,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),G=w((function(r){"production"===process.env.NODE_ENV?r.exports=I:r.exports=P}));var K,B="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},N=G.useSyncExternalStore,H=r.useRef,U=r.useEffect,W=r.useMemo,F=r.useDebugValue,Y={useSyncExternalStoreWithSelector:function(r,n,e,t,u){var o=H(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=W((function(){function r(r){if(!a){if(a=!0,o=r,r=t(r),void 0!==u&&c.hasValue){var n=c.value;if(u(n,r))return i=n}return i=r}if(n=i,B(o,r))return n;var e=t(r);return void 0!==u&&u(n,e)?n:(o=r,i=e)}var o,i,a=!1,l=void 0===e?null:e;return[function(){return r(n())},null===l?void 0:function(){return r(l())}]}),[n,e,t,u]);var i=N(r,o[0],o[1]);return U((function(){c.hasValue=!0,c.value=i}),[i]),F(i),i}},z=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=G;var u="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},o=t.useSyncExternalStore,c=n.useRef,i=n.useEffect,a=n.useMemo,l=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(r,n,e,t,f){var s,d=c(null);null===d.current?(s={hasValue:!1,value:null},d.current=s):s=d.current;var v=a((function(){var r,o,c=!1,i=function(n){if(!c){c=!0,r=n;var e=t(n);if(void 0!==f&&s.hasValue){var i=s.value;if(f(i,e))return o=i,i}return o=e,e}var a=o;if(u(r,n))return a;var l=t(n);return void 0!==f&&f(a,l)?a:(r=n,o=l,l)},a=void 0===e?null:e;return[function(){return i(n())},null===a?void 0:function(){return i(a())}]}),[n,e,t,f]),p=v[0],O=v[1],_=o(r,p,O);return i((function(){s.hasValue=!0,s.value=_}),[_]),l(_),_},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),J=w((function(r){"production"===process.env.NODE_ENV?r.exports=Y:r.exports=z}));!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse"}(K||(K={}));var q=J.useSyncExternalStoreWithSelector,Q=G.useSyncExternalStore;function X(r){var n=i(),e=i(),t=i(),u=i(),o=i(),c=i(),w=i(),M=i(),j=i(),D=i(),x=i(),V=i(!1),k=i(),C=i([]),I=r.actions,P=r.middlewares,G=void 0===P?[]:P,K=function(r,n){var e={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&n.indexOf(t)<0&&(e[t]=r[t]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(t=Object.getOwnPropertySymbols(r);u<t.length;u++)n.indexOf(t[u])<0&&Object.prototype.propertyIsEnumerable.call(r,t[u])&&(e[t[u]]=r[t[u]])}return e}(r,["actions","middlewares"]),B=r.getInitialState||function(){return r.initialState},N={},H=0;function U(){k.current=T(T(T(T({},u.current),n.current),e.current.state),{isLoading:Q,abortAction:X,loading:M.current,loadingMap:w.current,loadingParallelMap:c.current,errorMap:Z(),errorParallelMap:j.current}),Object.keys(N).forEach((function(r){var n;null===(n=N[r])||void 0===n||n.call(N)}))}function W(r){n.current=r,y(n,t,e,K),U()}function F(r){c.current=r,w.current=function(){if(V.current){var r=c.current;return Object.keys(r).reduce((function(n,e){var t=r[e];return n[e]=null!=Object.keys(t).find((function(r){return!!t[r]})),n}),{})}return null}(),M.current=function(){if(V.current){var r=c.current;return null!=Object.keys(r).find((function(n){var e=r[n];return Object.keys(e).find((function(r){return!!e[r]}))}))}return null}()}function Y(c){var i;if(!V.current){t.current=c,V.current=!0,n.current=B(c);var a=new Set(null==K?void 0:K.initialActionsMarkedLoading),l=Object.keys(I).reduce((function(r,n){var e;return r[n]=a.has(n)?((e={})[E]=!0,e):{},r}),{});F(l),j.current=Object.keys(I).reduce((function(r,n){return r[n]={},r}),{}),o.current={},D.current={},x.current={},e.current={state:null,deps:{}},(null==K?void 0:K.derivedState)&&S(K),C.current=[];var f={options:K,get state(){return n.current},actions:I,setState:W};r.logEnabled&&R&&G.push(R());var s=function(r){var n,e=r();C.current.push(e),null===(n=e.init)||void 0===n||n.call(e,f)};null===(i=O.defaultMiddlewares)||void 0===i||i.forEach(s),null==G||G.forEach(s),y(n,t,e,K),_(n,e,t,null,u,K,B,J,!0,!1),(null==K?void 0:K.onMount)&&K.onMount(g(n,e,t,u)),U()}}function z(r,n){void 0===n&&(n=E);var e=j.current[r];(null==e?void 0:e[n])&&delete e[n],U()}function J(r,u,o,i,a,l,f,s){void 0===f&&(f=!1),void 0===s&&(s=!1);var d=!1;if(V.current){var v=u,p=!!a&&h(v||c.current,[o,null==l?void 0:l.promiseId]),O=b(C.current,n.current,r,p,o,i,a,l),_=O.newState,S=O.newLoading;if(null!=_&&(d=!0,n.current=_),p!==S&&(v=A(v,o,(null==l?void 0:l.promiseId)||E,S),0===Object.keys(v).length&&(v=void 0)),null!=v&&(d=!0,F(v)),d)y(n,t,e,K),s||(n.current=_||n.current,U());else if(f){y(n,t,e,K)&&!s&&U()}}}var q=Object.keys(I);function Q(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return h.apply(void 0,function(r,n,e){if(e||2===arguments.length)for(var t,u=0,o=n.length;u<o;u++)!t&&u in n||(t||(t=Array.prototype.slice.call(n,0,u)),t[u]=n[u]);return r.concat(t||Array.prototype.slice.call(n))}([c.current],r,!1))}function X(r,n){var e,t;void 0===n&&(n=E);var u=null===(t=null===(e=D.current[r])||void 0===e?void 0:e[n])||void 0===t?void 0:t.abortController,o=!1;return u&&(u.abort(),o=!0),o}function Z(){return V.current?m(j.current):null}return u.current=q.reduce((function(r,i){var O=I[i];return a(O)?r[i]=l(i,O,n,e,t,V,K,J):f(O)?r[i]=s({actionName:i,stateRef:n,derivedStateRef:e,propsRef:t,loadingParallelMapRef:c,errorMapRef:j,actionsRef:u,promisesRef:D,conflictActionsRef:x,initializedRef:V,options:K,setState:J,clearError:z,action:d(O)}):v(O)&&(r[i]=p(i,O,n,e,t,u,V,o,K,J,z)),r}),{}),{getConfig:function(){return T({},r)},setProps:function(r){var o=t.current;t.current=r,V.current?_(n,e,t,o,u,K,B,J,!1,!1):Y(r)},addStateListener:function(r){var n="".concat(H++);return N[n]=r,function(){delete N[n]}},init:Y,destroy:function(){var r;if(V.current){var u=Object.keys(I).reduce((function(r,n){var e=I[n];if(f(e)&&e.abortable){var t=c.current[n],u=Object.keys(t).reduce((function(r,e){return t[e]&&(X(n,e),r.push(e)),r}),[]);u.length>0&&(r[n]=u)}return r}),{});null===(r=null==K?void 0:K.onUnmount)||void 0===r||r.call(K,L(n,e,t,u)),t.current=null,n.current=null,c.current=null,w.current=null,M.current=null,j.current=null,D.current=null,x.current=null,e.current=null,k.current=null,Object.keys(o.current).forEach((function(r){clearTimeout(o.current[r])})),o.current=null,N={},V.current=!1,C.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),C.current=[]}},isLoading:Q,abortAction:X,clearError:z,getSnapshot:function(){return k.current},invokeOnMountDeferred:function(){_(n,e,t,null,u,K,B,J,!0,!0),(null==K?void 0:K.onMountDeferred)&&K.onMountDeferred(g(n,e,t,u))},get actions(){return u.current},get state(){return V.current?T(T({},n.current),e.current.state):null},get loading(){return M.current},get loadingMap(){return w.current},get errorMap(){return Z()},get loadingParallelMap(){return V.current?c.current:null},get errorParallelMap(){return V.current?j.current:null}}}function Z(r,e){var t=n((function(){return e instanceof Function?e:function(r){return er(r,e)}}),[e]);return q(r.addStateListener,r.getSnapshot,r.getSnapshot,t,O.comparator)}function $(r){return Q(r.addStateListener,r.getSnapshot)}function rr(r,n){return Z(e(r),n)}function nr(r,n,e){void 0===e&&(e=!0);var i=t();return null==i.current&&(i.current=X(r)),u((function(){return i.current.invokeOnMountDeferred(),function(){var r;null===(r=i.current)||void 0===r||r.destroy()}}),[]),function(r,n,e){void 0===n&&(n=null),void 0===e&&(e=!0);var u=o((function(r){return r>100?0:r+1}),0)[1],i=t(r);return r.setProps(n),c((function(){r.init(n)}),[]),c((function(){if(e)return i.current.addStateListener((function(){u()}))}),[e]),r}(i.current,n,e)}function er(r,n){return n.reduce((function(n,e){return r.hasOwnProperty(e)&&(n[e]=r[e]),n}),{})}function tr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return er(n,r)}}export default nr;export{K as ConflictPolicy,X as createStore,er as pick,tr as slice,nr as useLocalStore,rr as useStoreContextSlice,Z as useStoreSlice,$ as useSyncStore};
1
+ import r,{useMemo as n,useContext as e,useRef as t,useEffect as u,useReducer as o,useLayoutEffect as c}from"react";import{createRef as i,isSimpleSyncAction as a,decorateSimpleSyncAction as l,isAsyncAction as f,decorateAsyncAction as s,computeAsyncActionInput as d,isSyncAction as v,decorateSyncAction as p,globalConfig as O,onPropChange as _,DEFAULT_PROMISE_ID as E,fixDerivedDeps as S,computeDerivedValues as y,buildOnMountInvocationContext as g,buildOnUnMountInvocationContext as L,isLoadingImpl as h,runMiddlewares as b,buildLoadingMap as A,buildErrorMap as m}from"./impl";export{EffectError,ParallelActionError,setGlobalConfig}from"./impl";import{logDetailedEffects as R}from"./development";var T=function(){return T=Object.assign||function(r){for(var n,e=1,t=arguments.length;e<t;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r},T.apply(this,arguments)};function w(r){var n={exports:{}};return r(n,n.exports),n.exports}var M="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},j=r.useState,D=r.useEffect,x=r.useLayoutEffect,V=r.useDebugValue;function k(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!M(r,e)}catch(r){return!0}}var C="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,n){var e=n(),t=j({inst:{value:e,getSnapshot:n}}),u=t[0].inst,o=t[1];return x((function(){u.value=e,u.getSnapshot=n,k(u)&&o({inst:u})}),[r,e,n]),D((function(){return k(u)&&o({inst:u}),r((function(){k(u)&&o({inst:u})}))}),[r]),V(e),e},I={useSyncExternalStore:void 0!==r.useSyncExternalStore?r.useSyncExternalStore:C},P=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function u(r){for(var n=arguments.length,e=new Array(n>1?n-1:0),u=1;u<n;u++)e[u-1]=arguments[u];!function(r,n,e){var u=t.ReactDebugCurrentFrame.getStackAddendum();""!==u&&(n+="%s",e=e.concat([u]));var o=e.map((function(r){return String(r)}));o.unshift("Warning: "+n),Function.prototype.apply.call(console[r],console,o)}("error",r,e)}var o="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},c=n.useState,i=n.useEffect,a=n.useLayoutEffect,l=n.useDebugValue,f=!1,s=!1;function d(r){var n=r.getSnapshot,e=r.value;try{var t=n();return!o(e,t)}catch(r){return!0}}var v=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(r,n,e){return n()}:function(r,e,t){f||void 0!==n.startTransition&&(f=!0,u("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=e();if(!s){var p=e();o(v,p)||(u("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var O=c({inst:{value:v,getSnapshot:e}}),_=O[0].inst,E=O[1];return a((function(){_.value=v,_.getSnapshot=e,d(_)&&E({inst:_})}),[r,v,e]),i((function(){d(_)&&E({inst:_});return r((function(){d(_)&&E({inst:_})}))}),[r]),l(v),v},p=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:v;e.useSyncExternalStore=p,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),G=w((function(r){"production"===process.env.NODE_ENV?r.exports=I:r.exports=P}));var K,B="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},N=G.useSyncExternalStore,H=r.useRef,U=r.useEffect,W=r.useMemo,F=r.useDebugValue,Y={useSyncExternalStoreWithSelector:function(r,n,e,t,u){var o=H(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=W((function(){function r(r){if(!a){if(a=!0,o=r,r=t(r),void 0!==u&&c.hasValue){var n=c.value;if(u(n,r))return i=n}return i=r}if(n=i,B(o,r))return n;var e=t(r);return void 0!==u&&u(n,e)?n:(o=r,i=e)}var o,i,a=!1,l=void 0===e?null:e;return[function(){return r(n())},null===l?void 0:function(){return r(l())}]}),[n,e,t,u]);var i=N(r,o[0],o[1]);return U((function(){c.hasValue=!0,c.value=i}),[i]),F(i),i}},z=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=G;var u="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},o=t.useSyncExternalStore,c=n.useRef,i=n.useEffect,a=n.useMemo,l=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(r,n,e,t,f){var s,d=c(null);null===d.current?(s={hasValue:!1,value:null},d.current=s):s=d.current;var v=a((function(){var r,o,c=!1,i=function(n){if(!c){c=!0,r=n;var e=t(n);if(void 0!==f&&s.hasValue){var i=s.value;if(f(i,e))return o=i,i}return o=e,e}var a=o;if(u(r,n))return a;var l=t(n);return void 0!==f&&f(a,l)?a:(r=n,o=l,l)},a=void 0===e?null:e;return[function(){return i(n())},null===a?void 0:function(){return i(a())}]}),[n,e,t,f]),p=v[0],O=v[1],_=o(r,p,O);return i((function(){s.hasValue=!0,s.value=_}),[_]),l(_),_},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),J=w((function(r){"production"===process.env.NODE_ENV?r.exports=Y:r.exports=z}));!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse"}(K||(K={}));var q=J.useSyncExternalStoreWithSelector,Q=G.useSyncExternalStore;function X(r){var n=i(),e=i(),t=i(),u=i(),o=i(),c=i(),w=i(),M=i(),j=i(),D=i(),x=i(),V=i(!1),k=i(),C=i([]),I=r.actions,P=r.middlewares,G=void 0===P?[]:P,K=function(r,n){var e={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&n.indexOf(t)<0&&(e[t]=r[t]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(t=Object.getOwnPropertySymbols(r);u<t.length;u++)n.indexOf(t[u])<0&&Object.prototype.propertyIsEnumerable.call(r,t[u])&&(e[t[u]]=r[t[u]])}return e}(r,["actions","middlewares"]),B=r.getInitialState||function(){return r.initialState},N={},H=0;function U(){k.current=T(T(T(T({},u.current),n.current),e.current.state),{isLoading:Q,abortAction:X,loading:M.current,loadingMap:w.current,loadingParallelMap:c.current,errorMap:Z(),errorParallelMap:j.current}),Object.keys(N).forEach((function(r){var n;null===(n=N[r])||void 0===n||n.call(N)}))}function W(r){n.current=r,y(n,t,e,K),U()}function F(r){c.current=r,w.current=function(){if(V.current){var r=c.current;return Object.keys(r).reduce((function(n,e){var t=r[e];return n[e]=null!=Object.keys(t).find((function(r){return!!t[r]})),n}),{})}return null}(),M.current=function(){if(V.current){var r=c.current;return null!=Object.keys(r).find((function(n){var e=r[n];return Object.keys(e).find((function(r){return!!e[r]}))}))}return null}()}function Y(c){var i;if(!V.current){t.current=c,V.current=!0,n.current=B(c);var a=new Set(null==K?void 0:K.initialActionsMarkedLoading),l=Object.keys(I).reduce((function(r,n){var e;return r[n]=a.has(n)?((e={})[E]=!0,e):{},r}),{});F(l),j.current=Object.keys(I).reduce((function(r,n){return r[n]={},r}),{}),o.current={},D.current={},x.current={},e.current={state:null,deps:{}},(null==K?void 0:K.derivedState)&&S(K),C.current=[];var f={options:K,get state(){return n.current},actions:I,setState:W};r.logEnabled&&R&&G.push(R());var s=function(r){var n,e=r();C.current.push(e),null===(n=e.init)||void 0===n||n.call(e,f)};null===(i=O.defaultMiddlewares)||void 0===i||i.forEach(s),null==G||G.forEach(s),y(n,t,e,K),_(n,e,t,null,u,K,B,J,!0,!1),(null==K?void 0:K.onMount)&&K.onMount(g(n,e,t,u)),U()}}function z(r,n){void 0===n&&(n=E);var e=j.current[r];(null==e?void 0:e[n])&&delete e[n],U()}function J(r,u,o,i,a,l,f,s){void 0===f&&(f=!1),void 0===s&&(s=!1);var d=!1;if(V.current){var v=u,p=!!a&&h(v||c.current,[o,null==l?void 0:l.promiseId]),O=b(C.current,n.current,r,p,o,i,a,l),_=O.newState,S=O.newLoading;if(null!=_&&(d=!0,n.current=_),p!==S&&(v=A(v,o,(null==l?void 0:l.promiseId)||E,S),0===Object.keys(v).length&&(v=void 0)),null!=v&&(d=!0,F(v)),d)y(n,t,e,K),s||(n.current=_||n.current,U());else if(f){y(n,t,e,K)&&!s&&U()}}}var q=Object.keys(I);function Q(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return h.apply(void 0,function(r,n,e){if(e||2===arguments.length)for(var t,u=0,o=n.length;u<o;u++)!t&&u in n||(t||(t=Array.prototype.slice.call(n,0,u)),t[u]=n[u]);return r.concat(t||Array.prototype.slice.call(n))}([c.current],r,!1))}function X(r,n){var e,t;void 0===n&&(n=E);var u=null===(t=null===(e=D.current[r])||void 0===e?void 0:e[n])||void 0===t?void 0:t.abortController,o=!1;return u&&(u.abort(),o=!0),o}function Z(){return V.current?m(j.current):null}return u.current=q.reduce((function(r,i){var O=I[i];return a(O)?r[i]=l(i,O,n,e,t,V,K,J):f(O)?r[i]=s({actionName:i,stateRef:n,derivedStateRef:e,propsRef:t,loadingParallelMapRef:c,errorMapRef:j,actionsRef:u,promisesRef:D,conflictActionsRef:x,initializedRef:V,options:K,setState:J,clearError:z,action:d(O)}):v(O)&&(r[i]=p(i,O,n,e,t,u,V,o,K,J,z)),r}),{}),{getConfig:function(){return T({},r)},setProps:function(r){var o=t.current;t.current=r,V.current?_(n,e,t,o,u,K,B,J,!1,!1):Y(r)},addStateListener:function(r){var n="".concat(H++);return N[n]=r,function(){delete N[n]}},init:Y,destroy:function(){var r;if(V.current){var u=Object.keys(I).reduce((function(r,n){var e=I[n];if(f(e)&&e.abortable){var t=c.current[n],u=Object.keys(t).reduce((function(r,e){return t[e]&&(X(n,e),r.push(e)),r}),[]);u.length>0&&(r[n]=u)}return r}),{});null===(r=null==K?void 0:K.onUnmount)||void 0===r||r.call(K,L(n,e,t,u)),t.current=null,n.current=null,c.current=null,w.current=null,M.current=null,j.current=null,D.current=null,x.current=null,e.current=null,k.current=null,Object.keys(o.current).forEach((function(r){clearTimeout(o.current[r])})),o.current=null,N={},V.current=!1,C.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),C.current=[]}},isLoading:Q,abortAction:X,clearError:z,getSnapshot:function(){return k.current},invokeOnMountDeferred:function(){_(n,e,t,null,u,K,B,J,!0,!0),(null==K?void 0:K.onMountDeferred)&&K.onMountDeferred(g(n,e,t,u))},get actions(){return u.current},get state(){return V.current?T(T({},n.current),e.current.state):null},get loading(){return M.current},get loadingMap(){return w.current},get errorMap(){return Z()},get loadingParallelMap(){return V.current?c.current:null},get errorParallelMap(){return V.current?j.current:null}}}function Z(r,e){var t=n((function(){return e instanceof Function?e:function(r){return er(r,e)}}),[e]);return q(r.addStateListener,r.getSnapshot,r.getSnapshot,t,O.comparator)}function $(r){return Q(r.addStateListener,r.getSnapshot)}function rr(r,n){return Z(e(r),n)}function nr(r,n,e){void 0===e&&(e=!0);var i=t();return null==i.current&&(i.current=X(r)),u((function(){return i.current.invokeOnMountDeferred(),function(){var r;null===(r=i.current)||void 0===r||r.destroy()}}),[]),function(r,n,e){void 0===n&&(n=null),void 0===e&&(e=!0);var u=o((function(r){return r>100?0:r+1}),0)[1],i=t(r);return r.setProps(n),c((function(){r.init(n)}),[]),c((function(){if(e)return i.current.addStateListener((function(){u()}))}),[e]),r}(i.current,n,e)}function er(r,n){return n.reduce((function(n,e){return r.hasOwnProperty(e)&&(n[e]=r[e]),n}),{})}function tr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return er(n,r)}}export default nr;export{K as ConflictPolicy,X as createStore,er as pick,tr as slice,nr as useLocalStore,$ as useStore,rr as useStoreContextSlice,Z as useStoreSlice};
2
2
  //# sourceMappingURL=index.js.map
package/helpers.d.ts CHANGED
@@ -1,33 +1,34 @@
1
1
  /**
2
2
  * Effect function that sets the first action argument to the specified prop.
3
+ * if dirtyProp is set
3
4
  */
4
- export declare function setArgIn<S, K extends keyof S>(propName: K): (ctx: {
5
+ export declare function setArgIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
5
6
  s: S;
6
7
  args: [S[K]];
7
8
  }) => Partial<S>;
8
9
  /**
9
10
  * Effect function that sets <code>true</code> in the specified prop.
10
11
  */
11
- export declare function setTrueIn<S, K extends keyof S>(propName: K): (ctx: {
12
+ export declare function setTrueIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
12
13
  s: S;
13
14
  }) => Partial<S>;
14
15
  /**
15
16
  * Effect function that sets <code>false</code> in the specified prop.
16
17
  */
17
- export declare function setFalseIn<S, K extends keyof S>(propName: K): (ctx: {
18
+ export declare function setFalseIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
18
19
  s: S;
19
20
  }) => Partial<S>;
20
21
  /**
21
22
  * Effect function that sets toggles the boolean value of the specified prop.
22
23
  */
23
- export declare function toggleProp<S, K extends keyof S>(propName: K): (ctx: {
24
+ export declare function toggleProp<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
24
25
  s: S;
25
26
  }) => Partial<S>;
26
27
  /**
27
28
  * Effect function that sets the update the specifed prop as an array using first action argument as index
28
29
  * and second as value to set.
29
30
  */
30
- export declare function setArgsInMap<S, K extends keyof S, T>(propName: K): (ctx: {
31
+ export declare function setArgsInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
31
32
  s: S;
32
33
  args: [string, T];
33
34
  }) => Partial<S>;
@@ -35,14 +36,14 @@ export declare function setArgsInMap<S, K extends keyof S, T>(propName: K): (ctx
35
36
  * Effect function that sets the update the specifed prop as an array using first action argument as index
36
37
  * and second as value to set.
37
38
  */
38
- export declare function setArgsInArray<S, K extends keyof S, T>(propName: K): (ctx: {
39
+ export declare function setArgsInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
39
40
  s: S;
40
41
  args: [number, T];
41
42
  }) => Partial<S>;
42
43
  /**
43
44
  * Effect function that sets the asynchronous action result to the specified prop.
44
45
  */
45
- export declare function setResIn<S, K extends keyof S>(propName: K): (ctx: {
46
+ export declare function setResIn<S, K extends keyof S, K2 extends keyof S>(propName: K, dirtyProp?: K2): (ctx: {
46
47
  s: S;
47
48
  res: S[K];
48
49
  }) => Partial<S>;
@@ -50,7 +51,7 @@ export declare function setResIn<S, K extends keyof S>(propName: K): (ctx: {
50
51
  * Effect function that sets the update the specifed prop as an array using first action argument as index
51
52
  * and second as value to set.
52
53
  */
53
- export declare function setResInArray<S, K extends keyof S, T>(propName: K): (ctx: {
54
+ export declare function setResInArray<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
54
55
  s: S;
55
56
  args: [number];
56
57
  res: T;
@@ -59,7 +60,7 @@ export declare function setResInArray<S, K extends keyof S, T>(propName: K): (ct
59
60
  * Effect function that sets the update the specifed prop as an array using first action argument as index
60
61
  * and second as value to set.
61
62
  */
62
- export declare function setResInMap<S, K extends keyof S, T>(propName: K): (ctx: {
63
+ export declare function setResInMap<S, K extends keyof S, K2 extends keyof S, T>(propName: K, dirtyProp?: K2): (ctx: {
63
64
  s: S;
64
65
  args: [string];
65
66
  res: T;
package/helpers.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=function(){return r=Object.assign||function(r){for(var n,t=1,e=arguments.length;t<e;t++)for(var s in n=arguments[t])Object.prototype.hasOwnProperty.call(n,s)&&(r[s]=n[s]);return r},r.apply(this,arguments)};function n(r,n,t){if(t||2===arguments.length)for(var e,s=0,u=n.length;s<u;s++)!e&&s in n||(e||(e=Array.prototype.slice.call(n,0,s)),e[s]=n[s]);return r.concat(e||Array.prototype.slice.call(n))}exports.setArgIn=function(r){return function(n){var t,e=n.s,s=n.args[0];return e[r]===s?null:((t={})[r]=s,t)}},exports.setArgsInArray=function(r){return function(t){var e,s=t.s,u=t.args,o=u[0],a=u[1],c=n([],s[r],!0);return c[o]=a,(e={})[r]=c,e}},exports.setArgsInMap=function(n){return function(t){var e,s,u=t.s,o=t.args,a=o[0],c=o[1];return(e={})[n]=r(r({},u[n]),((s={})[a]=c,s)),e}},exports.setFalseIn=function(r){return function(n){var t;return n.s[r]?((t={})[r]=!1,t):null}},exports.setResIn=function(r){return function(n){var t,e=n.res;return(t={})[r]=e,t}},exports.setResInArray=function(r){return function(t){var e,s=t.s,u=t.args[0],o=t.res,a=n([],s[r],!0);return a[u]=o,(e={})[r]=a,e}},exports.setResInMap=function(n){return function(t){var e,s,u=t.s,o=t.args[0],a=t.res;return(e={})[n]=r(r({},u[n]),((s={})[o]=a,s)),e}},exports.setTrueIn=function(r){return function(n){var t;return n.s[r]?null:((t={})[r]=!0,t)}},exports.toggleProp=function(r){return function(n){var t,e=n.s;return(t={})[r]=!e[r],t}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=function(){return r=Object.assign||function(r){for(var n,t=1,e=arguments.length;t<e;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r},r.apply(this,arguments)};function n(r,n,t){if(t||2===arguments.length)for(var e,u=0,s=n.length;u<s;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return r.concat(e||Array.prototype.slice.call(n))}function t(r,n){return n&&(r[n]=!0),r}exports.setArgIn=function(r,n){return function(e){var u,s=e.s,o=e.args[0];return s[r]===o?null:t(((u={})[r]=o,u),n)}},exports.setArgsInArray=function(r,e){return function(u){var s,o=u.s,a=u.args,c=a[0],i=a[1],f=n([],o[r],!0);return f[c]=i,t(((s={})[r]=f,s),e)}},exports.setArgsInMap=function(n,e){return function(u){var s,o,a=u.s,c=u.args,i=c[0],f=c[1];return t(((s={})[n]=r(r({},a[n]),((o={})[i]=f,o)),s),e)}},exports.setFalseIn=function(r,n){return function(e){var u;return e.s[r]?t(((u={})[r]=!1,u),n):null}},exports.setResIn=function(r,n){return function(e){var u,s=e.res;return t(((u={})[r]=s,u),n)}},exports.setResInArray=function(r,e){return function(u){var s,o=u.s,a=u.args[0],c=u.res,i=n([],o[r],!0);return i[a]=c,t(((s={})[r]=i,s),e)}},exports.setResInMap=function(n,e){return function(u){var s,o,a=u.s,c=u.args[0],i=u.res;return t(((s={})[n]=r(r({},a[n]),((o={})[c]=i,o)),s),e)}},exports.setTrueIn=function(r,n){return function(e){var u;return e.s[r]?null:t(((u={})[r]=!0,u),n)}},exports.toggleProp=function(r,n){return function(e){var u,s=e.s;return t(((u={})[r]=!s[r],u),n)}};
2
2
  //# sourceMappingURL=helpers.js.map
package/index.d.ts CHANGED
@@ -109,7 +109,7 @@ export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K ex
109
109
  * @param store The store to listen to.
110
110
  * @returns The store.
111
111
  */
112
- export declare function useSyncStore<S, A extends DecoratedActions, P, DS>(store: StoreApi<S, A, P, DS>): StateListenerContext<S, DS, A>;
112
+ export declare function useStore<S, A extends DecoratedActions, P, DS>(store: StoreApi<S, A, P, DS>): StateListenerContext<S, DS, A>;
113
113
  /**
114
114
  * A react hook to get a state slice from a store context.
115
115
  * The component be refreshed if, and only if, one property of the slice has changed.
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./impl"),t=require("./development");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=n(e),o=function(){return o=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var u in r=arguments[t])Object.prototype.hasOwnProperty.call(r,u)&&(e[u]=r[u]);return e},o.apply(this,arguments)};function c(e){var r={exports:{}};return e(r,r.exports),r.exports}var i="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},a=u.default.useState,l=u.default.useEffect,f=u.default.useLayoutEffect,s=u.default.useDebugValue;function d(e){var r=e.getSnapshot;e=e.value;try{var t=r();return!i(e,t)}catch(e){return!0}}var v="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,r){return r()}:function(e,r){var t=r(),n=a({inst:{value:t,getSnapshot:r}}),u=n[0].inst,o=n[1];return f((function(){u.value=t,u.getSnapshot=r,d(u)&&o({inst:u})}),[e,t,r]),l((function(){return d(u)&&o({inst:u}),e((function(){d(u)&&o({inst:u})}))}),[e]),s(t),t},p={useSyncExternalStore:void 0!==u.default.useSyncExternalStore?u.default.useSyncExternalStore:v},O=c((function(e,r){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=u.default,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),u=1;u<r;u++)n[u-1]=arguments[u];!function(e,r,n){var u=t.ReactDebugCurrentFrame.getStackAddendum();""!==u&&(r+="%s",n=n.concat([u]));var o=n.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,n)}var o="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},c=e.useState,i=e.useEffect,a=e.useLayoutEffect,l=e.useDebugValue,f=!1,s=!1;function d(e){var r=e.getSnapshot,t=e.value;try{var n=r();return!o(t,n)}catch(e){return!0}}var v=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(e,r,t){return r()}:function(r,t,u){f||void 0!==e.startTransition&&(f=!0,n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=t();if(!s){var p=t();o(v,p)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var O=c({inst:{value:v,getSnapshot:t}}),_=O[0].inst,E=O[1];return a((function(){_.value=v,_.getSnapshot=t,d(_)&&E({inst:_})}),[r,v,t]),i((function(){d(_)&&E({inst:_});return r((function(){d(_)&&E({inst:_})}))}),[r]),l(v),v},p=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:v;r.useSyncExternalStore=p,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),_=c((function(e){"production"===process.env.NODE_ENV?e.exports=p:e.exports=O}));var E,S="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},y=_.useSyncExternalStore,g=u.default.useRef,L=u.default.useEffect,b=u.default.useMemo,A=u.default.useDebugValue,h={useSyncExternalStoreWithSelector:function(e,r,t,n,u){var o=g(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=b((function(){function e(e){if(!a){if(a=!0,o=e,e=n(e),void 0!==u&&c.hasValue){var r=c.value;if(u(r,e))return i=r}return i=e}if(r=i,S(o,e))return r;var t=n(e);return void 0!==u&&u(r,t)?r:(o=e,i=t)}var o,i,a=!1,l=void 0===t?null:t;return[function(){return e(r())},null===l?void 0:function(){return e(l())}]}),[r,t,n,u]);var i=y(e,o[0],o[1]);return L((function(){c.hasValue=!0,c.value=i}),[i]),A(i),i}},R=c((function(e,r){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=u.default,t=_;var n="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},o=t.useSyncExternalStore,c=e.useRef,i=e.useEffect,a=e.useMemo,l=e.useDebugValue;r.useSyncExternalStoreWithSelector=function(e,r,t,u,f){var s,d=c(null);null===d.current?(s={hasValue:!1,value:null},d.current=s):s=d.current;var v=a((function(){var e,o,c=!1,i=function(r){if(!c){c=!0,e=r;var t=u(r);if(void 0!==f&&s.hasValue){var i=s.value;if(f(i,t))return o=i,i}return o=t,t}var a=o;if(n(e,r))return a;var l=u(r);return void 0!==f&&f(a,l)?a:(e=r,o=l,l)},a=void 0===t?null:t;return[function(){return i(r())},null===a?void 0:function(){return i(a())}]}),[r,t,u,f]),p=v[0],O=v[1],_=o(e,p,O);return i((function(){s.hasValue=!0,s.value=_}),[_]),l(_),_},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),x=c((function(e){"production"===process.env.NODE_ENV?e.exports=h:e.exports=R}));exports.ConflictPolicy=void 0,(E=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",E.IGNORE="ignore",E.KEEP_LAST="keepLast",E.KEEP_ALL="keepAll",E.PARALLEL="parallel",E.REUSE="reuse";var D=x.useSyncExternalStoreWithSelector,M=_.useSyncExternalStore;function m(e){var n=r.createRef(),u=r.createRef(),c=r.createRef(),i=r.createRef(),a=r.createRef(),l=r.createRef(),f=r.createRef(),s=r.createRef(),d=r.createRef(),v=r.createRef(),p=r.createRef(),O=r.createRef(!1),_=r.createRef(),E=r.createRef([]),S=e.actions,y=e.middlewares,g=void 0===y?[]:y,L=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)r.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(t[n[u]]=e[n[u]])}return t}(e,["actions","middlewares"]),b=e.getInitialState||function(){return e.initialState},A={},h=0;function R(){_.current=o(o(o(o({},i.current),n.current),u.current.state),{isLoading:w,abortAction:C,loading:s.current,loadingMap:f.current,loadingParallelMap:l.current,errorMap:P(),errorParallelMap:d.current}),Object.keys(A).forEach((function(e){var r;null===(r=A[e])||void 0===r||r.call(A)}))}function x(e){n.current=e,r.computeDerivedValues(n,c,u,L),R()}function D(e){l.current=e,f.current=function(){if(O.current){var e=l.current;return Object.keys(e).reduce((function(r,t){var n=e[t];return r[t]=null!=Object.keys(n).find((function(e){return!!n[e]})),r}),{})}return null}(),s.current=function(){if(O.current){var e=l.current;return null!=Object.keys(e).find((function(r){var t=e[r];return Object.keys(t).find((function(e){return!!t[e]}))}))}return null}()}function M(o){var l;if(!O.current){c.current=o,O.current=!0,n.current=b(o);var f=new Set(null==L?void 0:L.initialActionsMarkedLoading),s=Object.keys(S).reduce((function(e,t){var n;return e[t]=f.has(t)?((n={})[r.DEFAULT_PROMISE_ID]=!0,n):{},e}),{});D(s),d.current=Object.keys(S).reduce((function(e,r){return e[r]={},e}),{}),a.current={},v.current={},p.current={},u.current={state:null,deps:{}},(null==L?void 0:L.derivedState)&&r.fixDerivedDeps(L),E.current=[];var _={options:L,get state(){return n.current},actions:S,setState:x};e.logEnabled&&t.logDetailedEffects&&g.push(t.logDetailedEffects());var y=function(e){var r,t=e();E.current.push(t),null===(r=t.init)||void 0===r||r.call(t,_)};null===(l=r.globalConfig.defaultMiddlewares)||void 0===l||l.forEach(y),null==g||g.forEach(y),r.computeDerivedValues(n,c,u,L),r.onPropChange(n,u,c,null,i,L,b,T,!0,!1),(null==L?void 0:L.onMount)&&L.onMount(r.buildOnMountInvocationContext(n,u,c,i)),R()}}function m(e,t){void 0===t&&(t=r.DEFAULT_PROMISE_ID);var n=d.current[e];(null==n?void 0:n[t])&&delete n[t],R()}function T(e,t,o,i,a,f,s,d){void 0===s&&(s=!1),void 0===d&&(d=!1);var v=!1;if(O.current){var p=t,_=!!a&&r.isLoadingImpl(p||l.current,[o,null==f?void 0:f.promiseId]),S=r.runMiddlewares(E.current,n.current,e,_,o,i,a,f),y=S.newState,g=S.newLoading;if(null!=y&&(v=!0,n.current=y),_!==g&&(p=r.buildLoadingMap(p,o,(null==f?void 0:f.promiseId)||r.DEFAULT_PROMISE_ID,g),0===Object.keys(p).length&&(p=void 0)),null!=p&&(v=!0,D(p)),v)r.computeDerivedValues(n,c,u,L),d||(n.current=y||n.current,R());else if(s){r.computeDerivedValues(n,c,u,L)&&!d&&R()}}}var j=Object.keys(S);function w(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return r.isLoadingImpl.apply(void 0,function(e,r,t){if(t||2===arguments.length)for(var n,u=0,o=r.length;u<o;u++)!n&&u in r||(n||(n=Array.prototype.slice.call(r,0,u)),n[u]=r[u]);return e.concat(n||Array.prototype.slice.call(r))}([l.current],e,!1))}function C(e,t){var n,u;void 0===t&&(t=r.DEFAULT_PROMISE_ID);var o=null===(u=null===(n=v.current[e])||void 0===n?void 0:n[t])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function P(){return O.current?r.buildErrorMap(d.current):null}return i.current=j.reduce((function(e,t){var o=S[t];return r.isSimpleSyncAction(o)?e[t]=r.decorateSimpleSyncAction(t,o,n,u,c,O,L,T):r.isAsyncAction(o)?e[t]=r.decorateAsyncAction({actionName:t,stateRef:n,derivedStateRef:u,propsRef:c,loadingParallelMapRef:l,errorMapRef:d,actionsRef:i,promisesRef:v,conflictActionsRef:p,initializedRef:O,options:L,setState:T,clearError:m,action:r.computeAsyncActionInput(o)}):r.isSyncAction(o)&&(e[t]=r.decorateSyncAction(t,o,n,u,c,i,O,a,L,T,m)),e}),{}),{getConfig:function(){return o({},e)},setProps:function(e){var t=c.current;c.current=e,O.current?r.onPropChange(n,u,c,t,i,L,b,T,!1,!1):M(e)},addStateListener:function(e){var r="".concat(h++);return A[r]=e,function(){delete A[r]}},init:M,destroy:function(){var e;if(O.current){var t=Object.keys(S).reduce((function(e,t){var n=S[t];if(r.isAsyncAction(n)&&n.abortable){var u=l.current[t],o=Object.keys(u).reduce((function(e,r){return u[r]&&(C(t,r),e.push(r)),e}),[]);o.length>0&&(e[t]=o)}return e}),{});null===(e=null==L?void 0:L.onUnmount)||void 0===e||e.call(L,r.buildOnUnMountInvocationContext(n,u,c,t)),c.current=null,n.current=null,l.current=null,f.current=null,s.current=null,d.current=null,v.current=null,p.current=null,u.current=null,_.current=null,Object.keys(a.current).forEach((function(e){clearTimeout(a.current[e])})),a.current=null,A={},O.current=!1,E.current.forEach((function(e){var r;null===(r=e.destroy)||void 0===r||r.call(e)})),E.current=[]}},isLoading:w,abortAction:C,clearError:m,getSnapshot:function(){return _.current},invokeOnMountDeferred:function(){r.onPropChange(n,u,c,null,i,L,b,T,!0,!0),(null==L?void 0:L.onMountDeferred)&&L.onMountDeferred(r.buildOnMountInvocationContext(n,u,c,i))},get actions(){return i.current},get state(){return O.current?o(o({},n.current),u.current.state):null},get loading(){return s.current},get loadingMap(){return f.current},get errorMap(){return P()},get loadingParallelMap(){return O.current?l.current:null},get errorParallelMap(){return O.current?d.current:null}}}function T(t,n){var u=e.useMemo((function(){return n instanceof Function?n:function(e){return w(e,n)}}),[n]);return D(t.addStateListener,t.getSnapshot,t.getSnapshot,u,r.globalConfig.comparator)}function j(r,t,n){void 0===n&&(n=!0);var u=e.useRef();return null==u.current&&(u.current=m(r)),e.useEffect((function(){return u.current.invokeOnMountDeferred(),function(){var e;null===(e=u.current)||void 0===e||e.destroy()}}),[]),function(r,t,n){void 0===t&&(t=null),void 0===n&&(n=!0);var u=e.useReducer((function(e){return e>100?0:e+1}),0)[1],o=e.useRef(r);return r.setProps(t),e.useLayoutEffect((function(){r.init(t)}),[]),e.useLayoutEffect((function(){if(n)return o.current.addStateListener((function(){u()}))}),[n]),r}(u.current,t,n)}function w(e,r){return r.reduce((function(r,t){return e.hasOwnProperty(t)&&(r[t]=e[t]),r}),{})}Object.defineProperty(exports,"EffectError",{enumerable:!0,get:function(){return r.EffectError}}),Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return r.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return r.setGlobalConfig}}),exports.createStore=m,exports.default=j,exports.pick=w,exports.slice=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return function(r){return w(r,e)}},exports.useLocalStore=j,exports.useStoreContextSlice=function(r,t){return T(e.useContext(r),t)},exports.useStoreSlice=T,exports.useSyncStore=function(e){return M(e.addStateListener,e.getSnapshot)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./impl"),t=require("./development");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=n(e),o=function(){return o=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var u in r=arguments[t])Object.prototype.hasOwnProperty.call(r,u)&&(e[u]=r[u]);return e},o.apply(this,arguments)};function c(e){var r={exports:{}};return e(r,r.exports),r.exports}var i="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},a=u.default.useState,l=u.default.useEffect,f=u.default.useLayoutEffect,s=u.default.useDebugValue;function d(e){var r=e.getSnapshot;e=e.value;try{var t=r();return!i(e,t)}catch(e){return!0}}var v="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,r){return r()}:function(e,r){var t=r(),n=a({inst:{value:t,getSnapshot:r}}),u=n[0].inst,o=n[1];return f((function(){u.value=t,u.getSnapshot=r,d(u)&&o({inst:u})}),[e,t,r]),l((function(){return d(u)&&o({inst:u}),e((function(){d(u)&&o({inst:u})}))}),[e]),s(t),t},p={useSyncExternalStore:void 0!==u.default.useSyncExternalStore?u.default.useSyncExternalStore:v},O=c((function(e,r){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=u.default,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),u=1;u<r;u++)n[u-1]=arguments[u];!function(e,r,n){var u=t.ReactDebugCurrentFrame.getStackAddendum();""!==u&&(r+="%s",n=n.concat([u]));var o=n.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,n)}var o="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},c=e.useState,i=e.useEffect,a=e.useLayoutEffect,l=e.useDebugValue,f=!1,s=!1;function d(e){var r=e.getSnapshot,t=e.value;try{var n=r();return!o(t,n)}catch(e){return!0}}var v=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(e,r,t){return r()}:function(r,t,u){f||void 0!==e.startTransition&&(f=!0,n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=t();if(!s){var p=t();o(v,p)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var O=c({inst:{value:v,getSnapshot:t}}),_=O[0].inst,E=O[1];return a((function(){_.value=v,_.getSnapshot=t,d(_)&&E({inst:_})}),[r,v,t]),i((function(){d(_)&&E({inst:_});return r((function(){d(_)&&E({inst:_})}))}),[r]),l(v),v},p=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:v;r.useSyncExternalStore=p,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),_=c((function(e){"production"===process.env.NODE_ENV?e.exports=p:e.exports=O}));var E,S="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},y=_.useSyncExternalStore,g=u.default.useRef,L=u.default.useEffect,b=u.default.useMemo,A=u.default.useDebugValue,h={useSyncExternalStoreWithSelector:function(e,r,t,n,u){var o=g(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=b((function(){function e(e){if(!a){if(a=!0,o=e,e=n(e),void 0!==u&&c.hasValue){var r=c.value;if(u(r,e))return i=r}return i=e}if(r=i,S(o,e))return r;var t=n(e);return void 0!==u&&u(r,t)?r:(o=e,i=t)}var o,i,a=!1,l=void 0===t?null:t;return[function(){return e(r())},null===l?void 0:function(){return e(l())}]}),[r,t,n,u]);var i=y(e,o[0],o[1]);return L((function(){c.hasValue=!0,c.value=i}),[i]),A(i),i}},R=c((function(e,r){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=u.default,t=_;var n="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},o=t.useSyncExternalStore,c=e.useRef,i=e.useEffect,a=e.useMemo,l=e.useDebugValue;r.useSyncExternalStoreWithSelector=function(e,r,t,u,f){var s,d=c(null);null===d.current?(s={hasValue:!1,value:null},d.current=s):s=d.current;var v=a((function(){var e,o,c=!1,i=function(r){if(!c){c=!0,e=r;var t=u(r);if(void 0!==f&&s.hasValue){var i=s.value;if(f(i,t))return o=i,i}return o=t,t}var a=o;if(n(e,r))return a;var l=u(r);return void 0!==f&&f(a,l)?a:(e=r,o=l,l)},a=void 0===t?null:t;return[function(){return i(r())},null===a?void 0:function(){return i(a())}]}),[r,t,u,f]),p=v[0],O=v[1],_=o(e,p,O);return i((function(){s.hasValue=!0,s.value=_}),[_]),l(_),_},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),x=c((function(e){"production"===process.env.NODE_ENV?e.exports=h:e.exports=R}));exports.ConflictPolicy=void 0,(E=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",E.IGNORE="ignore",E.KEEP_LAST="keepLast",E.KEEP_ALL="keepAll",E.PARALLEL="parallel",E.REUSE="reuse";var D=x.useSyncExternalStoreWithSelector,M=_.useSyncExternalStore;function m(e){var n=r.createRef(),u=r.createRef(),c=r.createRef(),i=r.createRef(),a=r.createRef(),l=r.createRef(),f=r.createRef(),s=r.createRef(),d=r.createRef(),v=r.createRef(),p=r.createRef(),O=r.createRef(!1),_=r.createRef(),E=r.createRef([]),S=e.actions,y=e.middlewares,g=void 0===y?[]:y,L=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)r.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(t[n[u]]=e[n[u]])}return t}(e,["actions","middlewares"]),b=e.getInitialState||function(){return e.initialState},A={},h=0;function R(){_.current=o(o(o(o({},i.current),n.current),u.current.state),{isLoading:w,abortAction:C,loading:s.current,loadingMap:f.current,loadingParallelMap:l.current,errorMap:P(),errorParallelMap:d.current}),Object.keys(A).forEach((function(e){var r;null===(r=A[e])||void 0===r||r.call(A)}))}function x(e){n.current=e,r.computeDerivedValues(n,c,u,L),R()}function D(e){l.current=e,f.current=function(){if(O.current){var e=l.current;return Object.keys(e).reduce((function(r,t){var n=e[t];return r[t]=null!=Object.keys(n).find((function(e){return!!n[e]})),r}),{})}return null}(),s.current=function(){if(O.current){var e=l.current;return null!=Object.keys(e).find((function(r){var t=e[r];return Object.keys(t).find((function(e){return!!t[e]}))}))}return null}()}function M(o){var l;if(!O.current){c.current=o,O.current=!0,n.current=b(o);var f=new Set(null==L?void 0:L.initialActionsMarkedLoading),s=Object.keys(S).reduce((function(e,t){var n;return e[t]=f.has(t)?((n={})[r.DEFAULT_PROMISE_ID]=!0,n):{},e}),{});D(s),d.current=Object.keys(S).reduce((function(e,r){return e[r]={},e}),{}),a.current={},v.current={},p.current={},u.current={state:null,deps:{}},(null==L?void 0:L.derivedState)&&r.fixDerivedDeps(L),E.current=[];var _={options:L,get state(){return n.current},actions:S,setState:x};e.logEnabled&&t.logDetailedEffects&&g.push(t.logDetailedEffects());var y=function(e){var r,t=e();E.current.push(t),null===(r=t.init)||void 0===r||r.call(t,_)};null===(l=r.globalConfig.defaultMiddlewares)||void 0===l||l.forEach(y),null==g||g.forEach(y),r.computeDerivedValues(n,c,u,L),r.onPropChange(n,u,c,null,i,L,b,T,!0,!1),(null==L?void 0:L.onMount)&&L.onMount(r.buildOnMountInvocationContext(n,u,c,i)),R()}}function m(e,t){void 0===t&&(t=r.DEFAULT_PROMISE_ID);var n=d.current[e];(null==n?void 0:n[t])&&delete n[t],R()}function T(e,t,o,i,a,f,s,d){void 0===s&&(s=!1),void 0===d&&(d=!1);var v=!1;if(O.current){var p=t,_=!!a&&r.isLoadingImpl(p||l.current,[o,null==f?void 0:f.promiseId]),S=r.runMiddlewares(E.current,n.current,e,_,o,i,a,f),y=S.newState,g=S.newLoading;if(null!=y&&(v=!0,n.current=y),_!==g&&(p=r.buildLoadingMap(p,o,(null==f?void 0:f.promiseId)||r.DEFAULT_PROMISE_ID,g),0===Object.keys(p).length&&(p=void 0)),null!=p&&(v=!0,D(p)),v)r.computeDerivedValues(n,c,u,L),d||(n.current=y||n.current,R());else if(s){r.computeDerivedValues(n,c,u,L)&&!d&&R()}}}var j=Object.keys(S);function w(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return r.isLoadingImpl.apply(void 0,function(e,r,t){if(t||2===arguments.length)for(var n,u=0,o=r.length;u<o;u++)!n&&u in r||(n||(n=Array.prototype.slice.call(r,0,u)),n[u]=r[u]);return e.concat(n||Array.prototype.slice.call(r))}([l.current],e,!1))}function C(e,t){var n,u;void 0===t&&(t=r.DEFAULT_PROMISE_ID);var o=null===(u=null===(n=v.current[e])||void 0===n?void 0:n[t])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function P(){return O.current?r.buildErrorMap(d.current):null}return i.current=j.reduce((function(e,t){var o=S[t];return r.isSimpleSyncAction(o)?e[t]=r.decorateSimpleSyncAction(t,o,n,u,c,O,L,T):r.isAsyncAction(o)?e[t]=r.decorateAsyncAction({actionName:t,stateRef:n,derivedStateRef:u,propsRef:c,loadingParallelMapRef:l,errorMapRef:d,actionsRef:i,promisesRef:v,conflictActionsRef:p,initializedRef:O,options:L,setState:T,clearError:m,action:r.computeAsyncActionInput(o)}):r.isSyncAction(o)&&(e[t]=r.decorateSyncAction(t,o,n,u,c,i,O,a,L,T,m)),e}),{}),{getConfig:function(){return o({},e)},setProps:function(e){var t=c.current;c.current=e,O.current?r.onPropChange(n,u,c,t,i,L,b,T,!1,!1):M(e)},addStateListener:function(e){var r="".concat(h++);return A[r]=e,function(){delete A[r]}},init:M,destroy:function(){var e;if(O.current){var t=Object.keys(S).reduce((function(e,t){var n=S[t];if(r.isAsyncAction(n)&&n.abortable){var u=l.current[t],o=Object.keys(u).reduce((function(e,r){return u[r]&&(C(t,r),e.push(r)),e}),[]);o.length>0&&(e[t]=o)}return e}),{});null===(e=null==L?void 0:L.onUnmount)||void 0===e||e.call(L,r.buildOnUnMountInvocationContext(n,u,c,t)),c.current=null,n.current=null,l.current=null,f.current=null,s.current=null,d.current=null,v.current=null,p.current=null,u.current=null,_.current=null,Object.keys(a.current).forEach((function(e){clearTimeout(a.current[e])})),a.current=null,A={},O.current=!1,E.current.forEach((function(e){var r;null===(r=e.destroy)||void 0===r||r.call(e)})),E.current=[]}},isLoading:w,abortAction:C,clearError:m,getSnapshot:function(){return _.current},invokeOnMountDeferred:function(){r.onPropChange(n,u,c,null,i,L,b,T,!0,!0),(null==L?void 0:L.onMountDeferred)&&L.onMountDeferred(r.buildOnMountInvocationContext(n,u,c,i))},get actions(){return i.current},get state(){return O.current?o(o({},n.current),u.current.state):null},get loading(){return s.current},get loadingMap(){return f.current},get errorMap(){return P()},get loadingParallelMap(){return O.current?l.current:null},get errorParallelMap(){return O.current?d.current:null}}}function T(t,n){var u=e.useMemo((function(){return n instanceof Function?n:function(e){return w(e,n)}}),[n]);return D(t.addStateListener,t.getSnapshot,t.getSnapshot,u,r.globalConfig.comparator)}function j(r,t,n){void 0===n&&(n=!0);var u=e.useRef();return null==u.current&&(u.current=m(r)),e.useEffect((function(){return u.current.invokeOnMountDeferred(),function(){var e;null===(e=u.current)||void 0===e||e.destroy()}}),[]),function(r,t,n){void 0===t&&(t=null),void 0===n&&(n=!0);var u=e.useReducer((function(e){return e>100?0:e+1}),0)[1],o=e.useRef(r);return r.setProps(t),e.useLayoutEffect((function(){r.init(t)}),[]),e.useLayoutEffect((function(){if(n)return o.current.addStateListener((function(){u()}))}),[n]),r}(u.current,t,n)}function w(e,r){return r.reduce((function(r,t){return e.hasOwnProperty(t)&&(r[t]=e[t]),r}),{})}Object.defineProperty(exports,"EffectError",{enumerable:!0,get:function(){return r.EffectError}}),Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return r.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return r.setGlobalConfig}}),exports.createStore=m,exports.default=j,exports.pick=w,exports.slice=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return function(r){return w(r,e)}},exports.useLocalStore=j,exports.useStore=function(e){return M(e.addStateListener,e.getSnapshot)},exports.useStoreContextSlice=function(r,t){return T(e.useContext(r),t)},exports.useStoreSlice=T;
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-decorator",
3
- "version": "7.0.0-rc7",
3
+ "version": "7.0.0-rc8",
4
4
  "description": "React state management library",
5
5
  "main": "index.js",
6
6
  "module": "es/index.js",