state-decorator 7.7.0-beta.1 → 8.0.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/README.md CHANGED
@@ -6,6 +6,42 @@
6
6
 
7
7
  The StateDecorator is a set of React hooks that manage a complex component state in an easy, testable and deterministic way.
8
8
 
9
+ ## Table of contents
10
+
11
+ - [Features](#features)
12
+ - [V7: Partial state and new hooks](#v7-partial-state-and-new-hooks)
13
+ - [V8: Better React 19 compatibility](#v8-better-react-19-compatibility)
14
+ - [Getting started](#getting-started)
15
+ - [React hooks](#react-hooks)
16
+ - [StoreApi](#storeapi)
17
+ - [Initial state](#initial-state)
18
+ - [Action context](#action-context)
19
+ - [Actions](#actions)
20
+ - [Synchronous actions](#synchronous-actions)
21
+ - [Asynchronous actions](#asynchronous-actions)
22
+ - [Error management](#ErrorManagement)
23
+ - [Conflicting actions](#ConflictingActions)
24
+ - [Global / local Stores and State sharing](#GlobalLocalStores)
25
+ - [Derived state](#derived-state)
26
+ - [Global configuration](#global-configuration)
27
+ - [Trace actions](#trace-actions)
28
+ - [Concise logger](#concise-logger)
29
+ - [Detailed Logger](#detailed-logger)
30
+ - [Redux devtools](#redux-devtools)
31
+ - [Unit testing](#unit-testing)
32
+ - [Example](#example)
33
+ - [Error testing](#error-testing)
34
+ - [API](#api)
35
+ - [Immutability](#immutability)
36
+ - [Build](#build)
37
+ - [Limitations](#limitations)
38
+ - [Migration](#migration)
39
+ - [V7 to V8](#v7-to-v8)
40
+ - [V6 to V7](#v6-to-v7)
41
+ - [V5 to V6](#v5-to-v6)
42
+ - [Examples](#examples)
43
+ - [Visual Studio Code user snippet](#visual-studio-code-user-snippet)
44
+
9
45
  # Features
10
46
 
11
47
  - Deterministic state changes (clear separation of effects and side effects)
@@ -28,6 +64,11 @@ The StateDecorator is a set of React hooks that manage a complex component state
28
64
  - New effect helpers
29
65
  - See migration details in [migration section](#migration).
30
66
 
67
+ # V8: Better React 19 compatibility
68
+
69
+ - Fixed a React 18+/19 concurrent rendering issue: **onMount** (and **onPropsChange** entries flagged **onMount: true**) used to run during **init()**, which can itself run during render. Under concurrent rendering, a discarded and retried render attempt could trigger these side effects (e.g. data fetches) more than once per real mount. They are now deferred to a new **runMountEffects()** store method, called once from a layout effect after the render that actually commits — see [Call actions on mount](#call-actions-on-mount).
70
+ - See migration details in [migration section](#migration).
71
+
31
72
  # Getting started
32
73
 
33
74
  ## Installation
@@ -141,13 +182,40 @@ export function App(props: Props) => {
141
182
 
142
183
  # React hooks
143
184
 
144
- | Hook | Purpose | Returns | Is component refreshed on store change? | Is store destroyed on unmount? |
145
- | -------------------- | ------------------------------------------------------------- | ------- | --------------------------------------- | ------------------------------ |
146
- | useLocalStore | Create a store and binds it to the react component. | Store | if **refreshOnUpdate** is set | Y |
147
- | useStore | Binds a store instance to the react component. | Store | yes | N |
148
- | useBindStore | Binds a store instance to the react component (inject props). | Store | yes | N |
149
- | useStoreSlice | Get a slice of a store. | Slice | yes | N |
150
- | useStoreContextSlice | Get a slice of a store stored in a context | Slice | If slice has changed only | N |
185
+ | Hook | Purpose | Returns | Is component refreshed on store change? | Is store destroyed on unmount? |
186
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------- | ------- | --------------------------------------- | ------------------------------ |
187
+ | useLocalStore | Create a store and binds it to the react component. | Store | if **refreshOnUpdate** is set | Y |
188
+ | useStore | Subscribes the component to a store instance already owned/initialized elsewhere (does not call `init`/`setProps`). | Store | yes | N |
189
+ | useBindStore | Binds a store instance to the react component (inject props). | Store | yes | N |
190
+ | useStoreSlice | Get a slice of a store. | Slice | yes | N |
191
+ | useStoreContextSlice | Get a slice of a store stored in a context | Slice | If slice has changed only | N |
192
+
193
+ # StoreApi
194
+
195
+ Whatever hook is used (or a plain `createStore`), the resulting store exposes the same **StoreApi**:
196
+
197
+ | Member | Signature | Description |
198
+ | ------------------------------------ | ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199
+ | state | `S & DS` | Current state, merged with derived state if any. |
200
+ | actions | `A` | Decorated actions, ready to call. |
201
+ | loading | `boolean` | `true` if at least one asynchronous action is currently loading. |
202
+ | loadingMap | `LoadingMap<A>` | Per-action loading flags (computed on access). |
203
+ | errorMap | `ErrorMap<A>` | Per-action error map (computed on access). |
204
+ | loadingParallelMap | `LoadingParallelMap<A>` | Per-action, per-`promiseId` loading flags for parallel actions. |
205
+ | errorParallelMap | `ErrorParallelMap<A>` | Per-action, per-`promiseId` error map for parallel actions. |
206
+ | `init(p)` | `(p: P) => void` | Initializes the store with the given props: computes initial state, runs `onPropsChange` effects. Called automatically by **useLocalStore** / **useBindStore**. |
207
+ | `runMountEffects()` | `() => void` | Runs **onMount** (and `onPropsChange` entries flagged `onMount: true`) exactly once. Must be called after `init()`, from an effect (never a render body). Called automatically by **useLocalStore** / **useBindStore** — see [Call actions on mount](#call-actions-on-mount). |
208
+ | `setProps(p)` | `(p: P) => void` | Updates the store with new props, triggering matching `onPropsChange` entries. |
209
+ | `destroy()` | `() => void` | Destroys the store: runs **onUnmount**, clears listeners/timers. Called automatically when a **useLocalStore**-owned component unmounts. |
210
+ | `abortAction(name, promiseId?)` | `(actionName: keyof A, promiseId?: string) => boolean` | Aborts a running asynchronous action marked `abortable`. See [Abort asynchronous action](#abort-asynchronous-action). |
211
+ | `addStateListener(listener)` | `(listener: () => void) => unregister` | Subscribes to state changes; returns an unregister function. |
212
+ | `isLoading(...)` | `IsLoadingFunc<A>` | Returns `true` if any of the given action names (or `[name, promiseId]` tuples) are loading. |
213
+ | `clearError(...)` | `ClearErrorFunc<A>` | Clears the error of an action marked `isErrorManaged: true`. |
214
+ | `getConfig()` | `() => StoreConfig<S, A, P, DS>` | Returns the store's configuration. |
215
+ | `getSnapshot()` | `() => StateListenerContext<S, DS, A, P>` | Returns a snapshot of the current state/props/actions. Used internally (e.g. by `useSyncExternalStore`). |
216
+ | `listenToStoreProps(depStore, keys)` | `(depStore: StoreApi, keys: K[]) => unregister` | Subscribes to another store's state changes and mirrors the listed properties into this store's props (via `setProps`) whenever they change. Returns an unregister function. |
217
+
218
+ **Note**: most of these methods (`init`, `runMountEffects`, `destroy`, `setProps`) are lifecycle methods already called for you by **useLocalStore** and **useBindStore**. You only need to call them yourself when driving a store outside these two hooks — e.g. a plain **createStore** used without React, or read through **useStore** / **useStoreSlice** (which only subscribe, they don't own the lifecycle).
151
219
 
152
220
  # Initial state
153
221
 
@@ -648,7 +716,7 @@ const actions: StoreActions<State, Actions> = {
648
716
 
649
717
  ## Call actions on mount
650
718
 
651
- When store is created (for example whe React component in mounted), the **onMount** option is called.
719
+ When the store is mounted, the **onMount** option is called.
652
720
 
653
721
  ```typescript
654
722
  import { StoreConfig } from 'state-decorator';
@@ -662,9 +730,19 @@ const config: StoreConfig<State, Actions, Props> = {
662
730
  };
663
731
  ```
664
732
 
665
- After React component is mounted using _useLocalStore_, the **onMountDeferred** option is called (in a _useEffect_).
666
- The **onMount** is called _during_ the render of the hooks. If the onMount code is containing a function that is changing parent state,
667
- React will not update the parent state and will issue a warning.
733
+ **onMount** (and any **onPropsChange** entry flagged **onMount: true**, see below) is _not_ called by **init()**. It is called by **runMountEffects()**, a separate store method that must be called once, after **init()**, from a React layout/passive effect (never from a render body) — **useLocalStore** and **useBindStore** already call it for you automatically, since these are the hooks that own the store's lifecycle (they call `init`/`runMountEffects`/`destroy`). **useStore** does not: it only subscribes to a store that is already initialized and mounted elsewhere (e.g. by `useBindStore`, `useLocalStore`, or manual code), so it never calls `init` or `runMountEffects` itself.
734
+
735
+ If you use **createStore** without any of these hooks (a store driven entirely outside React, e.g. `store.init(props)` called directly), you are responsible for calling `store.runMountEffects()` yourself once after `init()` — otherwise **onMount** (and any props change effects flagged `onMount: true`) will never run.
736
+
737
+ ```typescript
738
+ const store = createStore(config);
739
+ store.init(props);
740
+ store.runMountEffects(); // required if the store isn't bound via useLocalStore / useBindStore
741
+ ```
742
+
743
+ **onMount** is called from a layout effect (_useLayoutEffect_), synchronously right after mount and before paint. **onMountDeferred** is called from a passive effect (_useEffect_), after paint.
744
+
745
+ Use **onMount** for state changes that should be visible on first paint (e.g. avoiding a flash of missing data). Use **onMountDeferred** for work that doesn't need to block paint (e.g. expensive initialization, or work that depends on child components' own effects/refs having already run).
668
746
 
669
747
  ```typescript
670
748
  import { StoreConfig } from 'state-decorator';
@@ -735,7 +813,7 @@ const config: StoreConfig<State, Actions, Props> = {
735
813
 
736
814
  ## OnMount
737
815
 
738
- If the onMount flag is set on the props change configuration, the effects and side effects will be executed at the store creation when the component is mounted.
816
+ If the onMount flag is set on the props change configuration, the effects and side effects will be executed when **runMountEffects()** is called (see [Call actions on mount](#call-actions-on-mount) above) — automatically after mount when using **useLocalStore** / **useStore** / **useBindStore**, or manually via `store.runMountEffects()` if the store isn't bound to any of these hooks.
739
817
 
740
818
  It allows to trigger same actions at creation time and when the dependencies props are changed.
741
819
 
@@ -786,7 +864,7 @@ const config: StoreConfig<State, Actions, Props> = {
786
864
  - Use several prop change configurations to separate dependencies between props and have simple definition.
787
865
  - Use onMount flag to have a more systematic and simpler code.
788
866
 
789
- # Global / local Stores and State sharing
867
+ # <a name="GlobalLocalStores"></a>Global / local Stores and State sharing
790
868
 
791
869
  There are two ways to share state and actions:
792
870
 
@@ -825,13 +903,13 @@ export const store = createStore(getInitialState, userAppActions);
825
903
 
826
904
  // In another file
827
905
  import { memo } from 'react';
828
- import { useStore } from 'state-decorator';
906
+ import { useBindStore } from 'state-decorator';
829
907
  import store from './GlobalStore';
830
908
 
831
- // Bind to react component
909
+ // Bind to react component and inject props
832
910
  // Each time the store state changes, a re-render is done.
833
911
  export function Container(props: Props) {
834
- const { state, actions } = useStore(store, props);
912
+ const { state, actions } = useBindStore(store, props);
835
913
  return (
836
914
  <div>
837
915
  <Title text={state.title} />
@@ -1046,7 +1124,7 @@ const store = createStore<State, Actions, Props, DerivedState>({
1046
1124
  });
1047
1125
 
1048
1126
  export function App(props: Props) {
1049
- const { state } = useStore(store, props);
1127
+ const { state } = useBindStore(store, props);
1050
1128
  // state contains the store state and derived state
1051
1129
  return (
1052
1130
  <div>
@@ -1701,6 +1779,20 @@ resolve: {
1701
1779
 
1702
1780
  # Migration
1703
1781
 
1782
+ ## V7 to V8
1783
+
1784
+ No breaking changes for **useLocalStore** / **useStore** / **useBindStore** users — they behave the same, no code change needed.
1785
+
1786
+ The only breaking change concerns code using **createStore** directly without any of these hooks: **onMount** (and **onPropsChange** entries flagged **onMount: true**) is no longer called by **init()**. It is now called by a new **runMountEffects()** store method, which you must call once yourself, right after **init()**:
1787
+
1788
+ ```diff
1789
+ const store = createStore(config);
1790
+ store.init(props);
1791
+ +store.runMountEffects();
1792
+ ```
1793
+
1794
+ If you skip this, **onMount** (and `onMount`-flagged **onPropsChange** entries) will simply never run. See [Call actions on mount](#call-actions-on-mount) for details.
1795
+
1704
1796
  ## V6 to V7
1705
1797
 
1706
1798
  ### Step 1: V6 compatibility layer
package/es/index.d.ts CHANGED
@@ -42,7 +42,6 @@ export type StoreApi<S, A extends DecoratedActions, P, DS = {}> = {
42
42
  /**
43
43
  * Runs onMount (and onPropsChange entries flagged onMount) exactly once for this store instance.
44
44
  * Must be called from an effect (useLayoutEffect/useEffect), never from a render body.
45
- * @internal
46
45
  */
47
46
  readonly runMountEffects: () => void;
48
47
  /**
package/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import r,{useMemo as n,useContext as e,useRef as t,useEffect as u,useLayoutEffect as o,useReducer as c}from"react";import{createRef as i,isFuncConfig as a,isSimpleSyncAction as l,decorateSimpleSyncAction as f,isAsyncAction as s,decorateAsyncAction as d,computeAsyncActionInput as v,isSyncAction as p,decorateSyncAction as O,globalConfig as _,onPropChange as E,DEFAULT_PROMISE_ID as S,fixDerivedDeps as y,computeDerivedValues as g,buildOnMountInvocationContext as L,buildOnUnMountInvocationContext as h,isLoadingImpl as b,runMiddlewares as A,buildLoadingMap as m,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 j(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))}function w(r){var n={exports:{}};return r(n,n.exports),n.exports}"function"==typeof SuppressedError&&SuppressedError;var V="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},x=r.useState,D=r.useEffect,k=r.useLayoutEffect,P=r.useDebugValue;function C(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!V(r,e)}catch(r){return!0}}var G="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,n){var e=n(),t=x({inst:{value:e,getSnapshot:n}}),u=t[0].inst,o=t[1];return k((function(){u.value=e,u.getSnapshot=n,C(u)&&o({inst:u})}),[r,e,n]),D((function(){return C(u)&&o({inst:u}),r((function(){C(u)&&o({inst:u})}))}),[r]),P(e),e},K={useSyncExternalStore:void 0!==r.useSyncExternalStore?r.useSyncExternalStore:G},B=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){function n(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!u(r,e)}catch(r){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var t=r,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.useState,c=t.useEffect,i=t.useLayoutEffect,a=t.useDebugValue,l=!1,f=!1,s="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,e){l||void 0===t.startTransition||(l=!0,console.error("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 s=e();if(!f){var d=e();u(s,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var v=(d=o({inst:{value:s,getSnapshot:e}}))[0].inst,p=d[1];return i((function(){v.value=s,v.getSnapshot=e,n(v)&&p({inst:v})}),[r,s,e]),c((function(){return n(v)&&p({inst:v}),r((function(){n(v)&&p({inst:v})}))}),[r]),a(s),s};e.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:s,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),I=K,H=B,N=w((function(r){"production"===process.env.NODE_ENV?r.exports=I:r.exports=H})),U=N;var W,z="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},F=N.useSyncExternalStore,J=r.useRef,Y=r.useEffect,q=r.useMemo,Q=r.useDebugValue,X={useSyncExternalStoreWithSelector:function(r,n,e,t,u){var o=J(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=q((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,z(o,r))return n;var e=t(r);return void 0!==u&&u(n,e)?(o=r,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=F(r,o[0],o[1]);return Y((function(){c.hasValue=!0,c.value=i}),[i]),Q(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(Error());var n=r,t=N,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=c(null);if(null===s.current){var d={hasValue:!1,value:null};s.current=d}else d=s.current;s=a((function(){function r(r){if(!i){if(i=!0,o=r,r=t(r),void 0!==f&&d.hasValue){var n=d.value;if(f(n,r))return c=n}return c=r}if(n=c,u(o,r))return n;var e=t(r);return void 0!==f&&f(n,e)?(o=r,n):(o=r,c=e)}var o,c,i=!1,a=void 0===e?null:e;return[function(){return r(n())},null===a?void 0:function(){return r(a())}]}),[n,e,t,f]);var v=o(r,s[0],s[1]);return i((function(){d.hasValue=!0,d.value=v}),[v]),l(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),$=X,rr=Z,nr=w((function(r){"production"===process.env.NODE_ENV?r.exports=$:r.exports=rr}));!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse",r.ABORT="abort"}(W||(W={}));var er=nr.useSyncExternalStoreWithSelector,tr=U.useSyncExternalStore;function ur(r){var n=i(),e=i(),t=i(),u=i(),o=i(),c=i(),w=i(),V=i(),x=i(),D=i(),k=i(),P=i(!1),C=i(!1),G=i(!1),K=i(),B=i([]),I=r.actions,H=r.middlewares,N=void 0===H?[]:H,U=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"]),W=a(r)?r.getInitialState:function(){return r.initialState},z={},F=0;function J(){K.current=T(T(T(T(T({},t.current),u.current),n.current),e.current.state),{isLoading:nr,abortAction:er,loading:V.current,loadingMap:w.current,loadingParallelMap:c.current,errorMap:tr(),errorParallelMap:x.current}),G.current=!1,Object.keys(z).forEach((function(r){var n;null===(n=z[r])||void 0===n||n.call(z)}))}function Y(r){var o=t.current;t.current=r,P.current?E(n,e,t,o,u,U,W,$,!1,!1):X(r)}function q(r){n.current=r,g(n,t,e,U),J()}function Q(r){c.current=r,w.current=function(){if(P.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}(),V.current=function(){if(P.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 X(u){var c;if(!P.current){t.current=u,P.current=!0,n.current=W(u);var i=new Set(null==U?void 0:U.initialActionsMarkedLoading),a=Object.keys(I).reduce((function(r,n){var e;return r[n]=i.has(n)?((e={})[S]=!0,e):{},r}),{});Q(a),x.current=Object.keys(I).reduce((function(r,n){return r[n]={},r}),{}),o.current={},D.current={},k.current={},e.current={state:null,deps:{}},(null==U?void 0:U.derivedState)&&y(U),B.current=[];var l={options:U,get state(){return n.current},actions:I,setState:q};r.logEnabled&&R&&N.push(R());var f=function(r){var n,e=r();B.current.push(e),null===(n=e.init)||void 0===n||n.call(e,l)};null===(c=_.defaultMiddlewares)||void 0===c||c.forEach(f),null==N||N.forEach(f),g(n,t,e,U),J()}}function Z(r,n){void 0===n&&(n=S);var e=x.current[r];(null==e?void 0:e[n])&&delete e[n],J()}function $(r,u,o,i,a,l,f,s,d){void 0===f&&(f=!1),void 0===s&&(s=!1),void 0===d&&(d=!1);var v=!1;if(!P.current)return J;var p=u,O=!!a&&b(p||c.current,[o,null==l?void 0:l.promiseId]),_=A(B.current,n.current,r,O,o,i,a,l),E=_.newState,y=_.newLoading;if(null!=E&&(v=!0,n.current=E),O!==y&&(p=m(p,o,(null==l?void 0:l.promiseId)||S,y),0===Object.keys(p).length&&(p=void 0)),null!=p&&(v=!0,Q(p)),v)g(n,t,e,U),s||(n.current=E||n.current,d||J());else if(f){!g(n,t,e,U)||s||d||J()}return J}var rr=Object.keys(I);function nr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return b.apply(void 0,j([c.current],r,!1))}function er(r,n){var e,t;void 0===n&&(n=S);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 tr(){return P.current?M(x.current):null}return u.current=rr.reduce((function(r,i){var a=I[i];return l(a)?r[i]=f(i,a,n,e,t,P,U,$):s(a)?r[i]=d({actionName:i,stateRef:n,derivedStateRef:e,propsRef:t,loadingParallelMapRef:c,errorMapRef:x,actionsRef:u,promisesRef:D,conflictActionsRef:k,initializedRef:P,timeoutRef:o,needNotifyListenersRef:G,options:U,setState:$,clearError:Z,action:v(a)}):p(a)&&(r[i]=O(i,a,n,e,t,u,P,o,G,U,$,Z)),r}),{}),{getConfig:function(){return T({},r)},setProps:Y,addStateListener:function(r){var n="".concat(F++);return z[n]=r,function(){delete z[n]}},init:X,runMountEffects:function(){P.current&&!C.current&&(C.current=!0,E(n,e,t,null,u,U,W,$,!0,!1),(null==U?void 0:U.onMount)&&U.onMount(L(n,e,t,u)),J())},destroy:function(){var r;if(P.current){var u=Object.keys(I).reduce((function(r,n){var e=I[n];if(s(e)&&e.abortable){var t=c.current[n],u=Object.keys(t).reduce((function(r,e){return t[e]&&(er(n,e),r.push(e)),r}),[]);u.length>0&&(r[n]=u)}return r}),{});null===(r=null==U?void 0:U.onUnmount)||void 0===r||r.call(U,h(n,e,t,u)),Object.keys(o.current).forEach((function(r){clearTimeout(o.current[r])})),t.current=null,n.current=null,c.current=null,w.current=null,V.current=null,x.current=null,D.current=null,k.current=null,e.current=null,K.current=null,o.current=null,z={},P.current=!1,C.current=!1,B.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),B.current=[]}},isLoading:nr,abortAction:er,clearError:Z,getSnapshot:function(){return K.current},invokeOnMountDeferred:function(){E(n,e,t,null,u,U,W,$,!0,!0),(null==U?void 0:U.onMountDeferred)&&U.onMountDeferred(L(n,e,t,u))},listenToStoreProps:function(r,n){var e=r.state?fr(r.state,n):{};return r.addStateListener((function(){var u=r.state;if(u){var o=fr(u,n);n.some((function(r){return!Object.is(e[r],o[r])}))&&(e=o,Y(T(T({},t.current),o)))}}))},get actions(){return u.current},get state(){return P.current?T(T({},n.current),e.current.state):null},get loading(){return V.current},get loadingMap(){return w.current},get errorMap(){return tr()},get loadingParallelMap(){return P.current?c.current:null},get errorParallelMap(){return P.current?x.current:null}}}function or(r,e,t){void 0===t&&(t=[]);var u=n((function(){return e instanceof Function?e:function(r){return fr(r,e)}}),j([e],t,!0));return er(r.addStateListener,r.getSnapshot,void 0,u,_.comparator)}function cr(r){return tr(r.addStateListener,r.getSnapshot),r}function ir(r,n){return or(e(r),n)}function ar(r,n,e){void 0===e&&(e=!0);var i=t();return null==i.current&&(i.current=ur(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=c((function(r){return r>100?0:r+1}),0)[1],i=t(r);return r.setProps(n),o((function(){r.init(n),r.runMountEffects()}),[]),o((function(){if(e)return i.current.addStateListener((function(){u()}))}),[e]),r}(i.current,n,e)}function lr(r,n){return r.setProps(n),tr(r.addStateListener,r.getSnapshot),o((function(){r.init(n),r.runMountEffects()}),[]),u((function(){r.invokeOnMountDeferred()}),[r]),r}function fr(r,n){return n.reduce((function(n,e){return r.hasOwnProperty(e)&&(n[e]=r[e]),n}),{})}function sr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return fr(n,r)}}export{W as ConflictPolicy,ur as createStore,ar as default,fr as pick,sr as slice,lr as useBindStore,ar as useLocalStore,cr as useStore,ir as useStoreContextSlice,or as useStoreSlice};
1
+ import r,{useMemo as n,useContext as e,useRef as t,useEffect as u,useLayoutEffect as o,useReducer as c}from"react";import{createRef as i,isFuncConfig as a,isSimpleSyncAction as l,decorateSimpleSyncAction as f,isAsyncAction as s,decorateAsyncAction as d,computeAsyncActionInput as v,isSyncAction as p,decorateSyncAction as O,globalConfig as _,onPropChange as E,DEFAULT_PROMISE_ID as S,fixDerivedDeps as y,computeDerivedValues as g,buildOnMountInvocationContext as L,buildOnUnMountInvocationContext as h,isLoadingImpl as b,runMiddlewares as A,buildLoadingMap as m,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 j(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))}function w(r){var n={exports:{}};return r(n,n.exports),n.exports}"function"==typeof SuppressedError&&SuppressedError;var V="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},x=r.useState,D=r.useEffect,k=r.useLayoutEffect,P=r.useDebugValue;function C(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!V(r,e)}catch(r){return!0}}var G="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,n){var e=n(),t=x({inst:{value:e,getSnapshot:n}}),u=t[0].inst,o=t[1];return k((function(){u.value=e,u.getSnapshot=n,C(u)&&o({inst:u})}),[r,e,n]),D((function(){return C(u)&&o({inst:u}),r((function(){C(u)&&o({inst:u})}))}),[r]),P(e),e},K={useSyncExternalStore:void 0!==r.useSyncExternalStore?r.useSyncExternalStore:G},B=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){function n(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!u(r,e)}catch(r){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var t=r,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.useState,c=t.useEffect,i=t.useLayoutEffect,a=t.useDebugValue,l=!1,f=!1,s="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,e){l||void 0===t.startTransition||(l=!0,console.error("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 s=e();if(!f){var d=e();u(s,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var v=(d=o({inst:{value:s,getSnapshot:e}}))[0].inst,p=d[1];return i((function(){v.value=s,v.getSnapshot=e,n(v)&&p({inst:v})}),[r,s,e]),c((function(){return n(v)&&p({inst:v}),r((function(){n(v)&&p({inst:v})}))}),[r]),a(s),s};e.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:s,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),I=K,H=B,N=w((function(r){"production"===process.env.NODE_ENV?r.exports=I:r.exports=H})),U=N;var W,z="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},F=N.useSyncExternalStore,J=r.useRef,Y=r.useEffect,q=r.useMemo,Q=r.useDebugValue,X={useSyncExternalStoreWithSelector:function(r,n,e,t,u){var o=J(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=q((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,z(o,r))return n;var e=t(r);return void 0!==u&&u(n,e)?(o=r,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=F(r,o[0],o[1]);return Y((function(){c.hasValue=!0,c.value=i}),[i]),Q(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(Error());var n=r,t=N,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=c(null);if(null===s.current){var d={hasValue:!1,value:null};s.current=d}else d=s.current;s=a((function(){function r(r){if(!i){if(i=!0,o=r,r=t(r),void 0!==f&&d.hasValue){var n=d.value;if(f(n,r))return c=n}return c=r}if(n=c,u(o,r))return n;var e=t(r);return void 0!==f&&f(n,e)?(o=r,n):(o=r,c=e)}var o,c,i=!1,a=void 0===e?null:e;return[function(){return r(n())},null===a?void 0:function(){return r(a())}]}),[n,e,t,f]);var v=o(r,s[0],s[1]);return i((function(){d.hasValue=!0,d.value=v}),[v]),l(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),$=X,rr=Z,nr=w((function(r){"production"===process.env.NODE_ENV?r.exports=$:r.exports=rr}));!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse",r.ABORT="abort"}(W||(W={}));var er=nr.useSyncExternalStoreWithSelector,tr=U.useSyncExternalStore;function ur(r){var n=i(),e=i(),t=i(),u=i(),o=i(),c=i(),w=i(),V=i(),x=i(),D=i(),k=i(),P=i(!1),C=i(!1),G=i(!1),K=i(),B=i([]),I=r.actions,H=r.middlewares,N=void 0===H?[]:H,U=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"]),W=a(r)?r.getInitialState:function(){return r.initialState},z={},F=0;function J(){K.current=T(T(T(T(T({},t.current),u.current),n.current),e.current.state),{isLoading:nr,abortAction:er,loading:V.current,loadingMap:w.current,loadingParallelMap:c.current,errorMap:tr(),errorParallelMap:x.current}),G.current=!1,Object.keys(z).forEach((function(r){var n;null===(n=z[r])||void 0===n||n.call(z)}))}function Y(r){var o=t.current;t.current=r,P.current?E(n,e,t,o,u,U,W,$,!1,!1):X(r)}function q(r){n.current=r,g(n,t,e,U),J()}function Q(r){c.current=r,w.current=function(){if(P.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}(),V.current=function(){if(P.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 X(u){var c;if(!P.current){t.current=u,P.current=!0,n.current=W(u);var i=new Set(null==U?void 0:U.initialActionsMarkedLoading),a=Object.keys(I).reduce((function(r,n){var e;return r[n]=i.has(n)?((e={})[S]=!0,e):{},r}),{});Q(a),x.current=Object.keys(I).reduce((function(r,n){return r[n]={},r}),{}),o.current={},D.current={},k.current={},e.current={state:null,deps:{}},(null==U?void 0:U.derivedState)&&y(U),B.current=[];var l={options:U,get state(){return n.current},actions:I,setState:q};r.logEnabled&&R&&N.push(R());var f=function(r){var n,e=r();B.current.push(e),null===(n=e.init)||void 0===n||n.call(e,l)};null===(c=_.defaultMiddlewares)||void 0===c||c.forEach(f),null==N||N.forEach(f),g(n,t,e,U),J()}}function Z(r,n){void 0===n&&(n=S);var e=x.current[r];(null==e?void 0:e[n])&&delete e[n],J()}function $(r,u,o,i,a,l,f,s,d){void 0===f&&(f=!1),void 0===s&&(s=!1),void 0===d&&(d=!1);var v=!1;if(!P.current)return J;var p=u,O=!!a&&b(p||c.current,[o,null==l?void 0:l.promiseId]),_=A(B.current,n.current,r,O,o,i,a,l),E=_.newState,y=_.newLoading;if(null!=E&&(v=!0,n.current=E),O!==y&&(p=m(p,o,(null==l?void 0:l.promiseId)||S,y),0===Object.keys(p).length&&(p=void 0)),null!=p&&(v=!0,Q(p)),v)g(n,t,e,U),s||(n.current=E||n.current,d||J());else if(f){!g(n,t,e,U)||s||d||J()}return J}var rr=Object.keys(I);function nr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return b.apply(void 0,j([c.current],r,!1))}function er(r,n){var e,t;void 0===n&&(n=S);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 tr(){return P.current?M(x.current):null}return u.current=rr.reduce((function(r,i){var a=I[i];return l(a)?r[i]=f(i,a,n,e,t,P,U,$):s(a)?r[i]=d({actionName:i,stateRef:n,derivedStateRef:e,propsRef:t,loadingParallelMapRef:c,errorMapRef:x,actionsRef:u,promisesRef:D,conflictActionsRef:k,initializedRef:P,timeoutRef:o,needNotifyListenersRef:G,options:U,setState:$,clearError:Z,action:v(a)}):p(a)&&(r[i]=O(i,a,n,e,t,u,P,o,G,U,$,Z)),r}),{}),{getConfig:function(){return T({},r)},setProps:Y,addStateListener:function(r){var n="".concat(F++);return z[n]=r,function(){delete z[n]}},init:X,runMountEffects:function(){P.current&&!C.current&&(C.current=!0,E(n,e,t,null,u,U,W,$,!0,!1),(null==U?void 0:U.onMount)&&U.onMount(L(n,e,t,u)),J())},destroy:function(){var r;if(P.current){var u=Object.keys(I).reduce((function(r,n){var e=I[n];if(s(e)&&e.abortable){var t=c.current[n],u=Object.keys(t).reduce((function(r,e){return t[e]&&(er(n,e),r.push(e)),r}),[]);u.length>0&&(r[n]=u)}return r}),{});null===(r=null==U?void 0:U.onUnmount)||void 0===r||r.call(U,h(n,e,t,u)),Object.keys(o.current).forEach((function(r){clearTimeout(o.current[r])})),t.current=null,n.current=null,c.current=null,w.current=null,V.current=null,x.current=null,D.current=null,k.current=null,e.current=null,K.current=null,o.current=null,z={},P.current=!1,C.current=!1,B.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),B.current=[]}},isLoading:nr,abortAction:er,clearError:Z,getSnapshot:function(){return K.current},invokeOnMountDeferred:function(){E(n,e,t,null,u,U,W,$,!0,!0),(null==U?void 0:U.onMountDeferred)&&U.onMountDeferred(L(n,e,t,u))},listenToStoreProps:function(r,n){var e=r.state?fr(r.state,n):{};return r.addStateListener((function(){var u=r.state;if(u){var o=fr(u,n);n.some((function(r){return!Object.is(e[r],o[r])}))&&(e=o,Y(T(T({},t.current),o)))}}))},get actions(){return u.current},get state(){return P.current?T(T({},n.current),e.current.state):null},get loading(){return V.current},get loadingMap(){return w.current},get errorMap(){return tr()},get loadingParallelMap(){return P.current?c.current:null},get errorParallelMap(){return P.current?x.current:null}}}function or(r,e,t){void 0===t&&(t=[]);var u=n((function(){return e instanceof Function?e:function(r){return fr(r,e)}}),j([e],t,!0));return er(r.addStateListener,r.getSnapshot,void 0,u,_.comparator)}function cr(r){return tr(r.addStateListener,r.getSnapshot),r}function ir(r,n){return or(e(r),n)}function ar(r,n,e){void 0===e&&(e=!0);var i=t();return null==i.current&&(i.current=ur(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=c((function(r){return r>100?0:r+1}),0)[1],i=t(r);return r.setProps(n),o((function(){if(e)return i.current.addStateListener((function(){u()}))}),[e]),o((function(){r.init(n),r.runMountEffects()}),[]),r}(i.current,n,e)}function lr(r,n){return r.setProps(n),tr(r.addStateListener,r.getSnapshot),o((function(){r.init(n),r.runMountEffects()}),[]),u((function(){r.invokeOnMountDeferred()}),[r]),r}function fr(r,n){return n.reduce((function(n,e){return r.hasOwnProperty(e)&&(n[e]=r[e]),n}),{})}function sr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return fr(n,r)}}export{W as ConflictPolicy,ur as createStore,ar as default,fr as pick,sr as slice,lr as useBindStore,ar as useLocalStore,cr as useStore,ir as useStoreContextSlice,or as useStoreSlice};
2
2
  //# sourceMappingURL=index.js.map
package/es/v5.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createStore as e}from"./index";import{useReducer as n,useRef as r,useLayoutEffect as t,useEffect as o}from"react";var i,s=function(){return s=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},s.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse",e.ABORT="abort"}(i||(i={}));var u=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==typeof n&&"object"==typeof r){if(n.constructor!==r.constructor)return!1;var t,o,i;if(Array.isArray(n)){if((t=n.length)!=r.length)return!1;for(o=t;0!=o--;)if(!e(n[o],r[o]))return!1;return!0}if(n.constructor===RegExp)return n.source===r.source&&n.flags===r.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===r.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===r.toString();if((t=(i=Object.keys(n)).length)!==Object.keys(r).length)return!1;for(o=t;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=t;0!=o--;){var s=i[o];if(!e(n[s],r[s]))return!1}return!0}return n!=n&&r!=r},c=null;function a(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function f(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function l(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))}function p(e){return e instanceof Function}function g(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function d(e){return Object.keys(e).reduce((function(n,r){var t=e[r];if(p(t))n[r]=function(e){return t(e.s,e.args,e.p)};else if(g(t)){var o={effects:function(e){return t.action(e.s,e.args,e.p)}};t.onActionDone&&(o.sideEffects=function(e){var n=e.s,r=e.p,o=e.args,i=e.a,s=e.notifyWarning;t.onActionDone(n,o,r,i,s)}),n[r]=o}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(t)||a(t)){var s;s=a(t)?{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promiseGet(i,n,r,o,s)},retryCount:3,conflictPolicy:i.REUSE}:{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promise(i,n,r,o,s)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=t[e]&&(s[e]=t[e])})),t.successMessage&&(s.getSuccessMessage=function(){return t.successMessage}),t.errorMessage&&(s.getSuccessMessage=function(){return t.errorMessage}),t.getSuccessMessage&&(s.getSuccessMessage=function(e){var n=e.res,r=e.args,o=e.p;return t.getSuccessMessage(n,r,o)}),t.getErrorMessage&&(s.getErrorMessage=function(e){var n=e.err,r=e.args,o=e.p;return t.getErrorMessage(n,r,o)}),t.preReducer&&(s.preEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.preReducer(n,o,r)}),t.optimisticReducer&&(s.optimisticEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.optimisticReducer(n,o,r)}),t.reducer&&(s.effects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args;return t.reducer(n,r,i,o)}),t.errorReducer&&(s.errorEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args;return t.errorReducer(n,r,i,o)}),t.onDone&&(s.sideEffects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args,s=e.a,u=e.notifyWarning;return t.onDone(n,r,i,o,s,u)}),t.onFail&&(s.errorSideEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args,s=e.a,u=e.notifyWarning;return t.onFail(n,r,i,o,s,u)}),n[r]=s}return n}),{})}function v(o,i,u,a,f){void 0===a&&(a={});var l,p,g,v,y=n((function(e){return e>100?0:e+1}),0)[1],E=r(),h=r();null==E.current&&(E.current=d(i)),null==h.current&&(h.current=(l=a,p={},g=Object.keys(l),v=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],g.forEach((function(e){v.includes(e)||(p[e]=l[e])})),l.onMount&&(p.onMount=function(e){var n=e.s,r=e.p,t=e.a;return l.onMount(t,r,n)}),l.getPropsRefValues&&(p.onPropsChange={getDeps:l.getPropsRefValues,effects:function(e){var n=e.s,r=e.p,t=e.indices;return l.onPropsChangeReducer?l.onPropsChangeReducer(n,r,t):null},sideEffects:function(e){var n=e.s,r=e.p,t=e.a,o=e.indices;return null==l.onPropsChange?null:l.onPropsChange(n,r,t,o)}}),l.initialActionsMarkedLoading&&(p.initialActionsMarkedLoading=l.initialActionsMarkedLoading),p));var m=r();if(null==m.current){var O=f;a.logEnabled&&O.push(c()),m.current=e(s(s({getInitialState:o,actions:E.current},h.current),{middlewares:O}))}m.current.setProps(u),t((function(){m.current.init(u),m.current.runMountEffects()}),[]),t((function(){return m.current.addStateListener((function(){y()}))}),[]);var P=m.current;return{state:P.state,actions:P.actions,loading:P.loading,loadingMap:P.loadingMap,loadingParallelMap:P.loadingParallelMap,abortAction:P.abortAction}}function y(e){o((function(){var n=e();return"function"==typeof n?n:void 0}),[e])}function E(e,n){void 0===n&&(n=[]),o((function(){return e}),[n,e])}function h(e){o((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[e])}"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||(c=function(e){return void 0===e&&(e=console),function(){var n="",r=e,t=function(e,n){var r;if(n!==e){var t=null!=e?typeof e:typeof n;if("number"===t||"string"===t||"boolean"===t)r="".concat(e," => ").concat(""===n?'""':n);else if(e&&e.length||n&&n.length)if(null==e)r="was ".concat(e,", now contains ").concat(n.length," element(s)");else if(null==n)r="contained ".concat(e.length," element(s), now is ").concat(n);else if(0===e.length)r="was empty, now contains ".concat(n.length," elements");else if(0===n.length)r="contained ".concat(e.length," elements, now is empty");else{var o=n.filter((function(n){return!e.find((function(e){return u(n,e)}))})),i=e.filter((function(e){return!n.find((function(n){return u(e,n)}))}));o.length>10&&(o="".concat(o.length," element(s) added")),i.length>10&&(i="".concat(i.length," element(s) removed")),r={added:o,removed:i}}else r=n}return r},o=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(t){var i,s;n=(null===(i=t.options)||void 0===i?void 0:i.name)?"[".concat(null===(s=t.options)||void 0===s?void 0:s.name,"]"):"";var u=t.state;e.group(n,"initialState"),Object.keys(u).forEach((function(e){r.log(e,":",o(u[e]))})),e.groupEnd()},destroy:null,effects:function(e,i,s,u){var c,a=null===(c=e.context)||void 0===c?void 0:c.args,f=[n,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?f.push(u?"START":"CANCELLED"):"effects"===e.type?f.push("DONE"):f.push("FAILED")),null!=s||a&&0!==Object.keys(a).length?r.group.apply(r,f):r.log.apply(r,f),a&&Object.keys(a).length>0&&(r.group("Arguments"),a.forEach((function(e){r.log(e,":",o(e))})),r.groupEnd()),null!=s){if(r.groupCollapsed("Before"),null==i)r.log("was null");else Object.keys(i).forEach((function(e){r.log(e,":",o(i[e]))}));if(r.groupEnd(),r.groupCollapsed("After"),null==s)r.log("was null");else Object.keys(s).forEach((function(e){r.log(e,":",o(s[e]))}));if(r.groupEnd(),null!=s){r.group("Diff");var l=function(e,n){var r={};return e&&Object.keys(e).forEach((function(o){if(n.hasOwnProperty(o)){var i=e[o],s=n[o],u=t(i,s);u&&(r[o]=u)}else r[o]="was deleted"})),Object.keys(n).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var i=n[o];r[o]=t(void 0,i)}})),r}(i,s);Object.keys(l).forEach((function(e){return r.log(e,":",l[e])})),r.groupEnd()}}return r.groupEnd(),null}}}});export{v as default,g as isAdvancedSyncAction,f as isAsyncAction,l as isAsyncPromiseGetAction,p as isSyncAction,y as useOnMount,h as useOnUnload,E as useOnUnmount};
1
+ import{createStore as e}from"./index";import{useReducer as n,useRef as r,useLayoutEffect as t,useEffect as o}from"react";var i,s=function(){return s=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},s.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse",e.ABORT="abort"}(i||(i={}));var u=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==typeof n&&"object"==typeof r){if(n.constructor!==r.constructor)return!1;var t,o,i;if(Array.isArray(n)){if((t=n.length)!=r.length)return!1;for(o=t;0!=o--;)if(!e(n[o],r[o]))return!1;return!0}if(n.constructor===RegExp)return n.source===r.source&&n.flags===r.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===r.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===r.toString();if((t=(i=Object.keys(n)).length)!==Object.keys(r).length)return!1;for(o=t;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=t;0!=o--;){var s=i[o];if(!e(n[s],r[s]))return!1}return!0}return n!=n&&r!=r},c=null;function a(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function f(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function l(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))}function p(e){return e instanceof Function}function g(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function d(e){return Object.keys(e).reduce((function(n,r){var t=e[r];if(p(t))n[r]=function(e){return t(e.s,e.args,e.p)};else if(g(t)){var o={effects:function(e){return t.action(e.s,e.args,e.p)}};t.onActionDone&&(o.sideEffects=function(e){var n=e.s,r=e.p,o=e.args,i=e.a,s=e.notifyWarning;t.onActionDone(n,o,r,i,s)}),n[r]=o}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(t)||a(t)){var s;s=a(t)?{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promiseGet(i,n,r,o,s)},retryCount:3,conflictPolicy:i.REUSE}:{getPromise:function(e){var n=e.s,r=e.p,o=e.a,i=e.args,s=e.abortSignal;return t.promise(i,n,r,o,s)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=t[e]&&(s[e]=t[e])})),t.successMessage&&(s.getSuccessMessage=function(){return t.successMessage}),t.errorMessage&&(s.getSuccessMessage=function(){return t.errorMessage}),t.getSuccessMessage&&(s.getSuccessMessage=function(e){var n=e.res,r=e.args,o=e.p;return t.getSuccessMessage(n,r,o)}),t.getErrorMessage&&(s.getErrorMessage=function(e){var n=e.err,r=e.args,o=e.p;return t.getErrorMessage(n,r,o)}),t.preReducer&&(s.preEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.preReducer(n,o,r)}),t.optimisticReducer&&(s.optimisticEffects=function(e){var n=e.s,r=e.p,o=e.args;return t.optimisticReducer(n,o,r)}),t.reducer&&(s.effects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args;return t.reducer(n,r,i,o)}),t.errorReducer&&(s.errorEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args;return t.errorReducer(n,r,i,o)}),t.onDone&&(s.sideEffects=function(e){var n=e.s,r=e.res,o=e.p,i=e.args,s=e.a,u=e.notifyWarning;return t.onDone(n,r,i,o,s,u)}),t.onFail&&(s.errorSideEffects=function(e){var n=e.s,r=e.err,o=e.p,i=e.args,s=e.a,u=e.notifyWarning;return t.onFail(n,r,i,o,s,u)}),n[r]=s}return n}),{})}function v(o,i,u,a,f){void 0===a&&(a={});var l,p,g,v,y=n((function(e){return e>100?0:e+1}),0)[1],E=r(),h=r();null==E.current&&(E.current=d(i)),null==h.current&&(h.current=(l=a,p={},g=Object.keys(l),v=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],g.forEach((function(e){v.includes(e)||(p[e]=l[e])})),l.onMount&&(p.onMount=function(e){var n=e.s,r=e.p,t=e.a;return l.onMount(t,r,n)}),l.getPropsRefValues&&(p.onPropsChange={getDeps:l.getPropsRefValues,effects:function(e){var n=e.s,r=e.p,t=e.indices;return l.onPropsChangeReducer?l.onPropsChangeReducer(n,r,t):null},sideEffects:function(e){var n=e.s,r=e.p,t=e.a,o=e.indices;return null==l.onPropsChange?null:l.onPropsChange(n,r,t,o)}}),l.initialActionsMarkedLoading&&(p.initialActionsMarkedLoading=l.initialActionsMarkedLoading),p));var m=r();if(null==m.current){var O=f;a.logEnabled&&O.push(c()),m.current=e(s(s({getInitialState:o,actions:E.current},h.current),{middlewares:O}))}m.current.setProps(u),t((function(){return m.current.addStateListener((function(){y()}))}),[]),t((function(){m.current.init(u),m.current.runMountEffects()}),[]);var P=m.current;return{state:P.state,actions:P.actions,loading:P.loading,loadingMap:P.loadingMap,loadingParallelMap:P.loadingParallelMap,abortAction:P.abortAction}}function y(e){o((function(){var n=e();return"function"==typeof n?n:void 0}),[e])}function E(e,n){void 0===n&&(n=[]),o((function(){return e}),[n,e])}function h(e){o((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[e])}"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||(c=function(e){return void 0===e&&(e=console),function(){var n="",r=e,t=function(e,n){var r;if(n!==e){var t=null!=e?typeof e:typeof n;if("number"===t||"string"===t||"boolean"===t)r="".concat(e," => ").concat(""===n?'""':n);else if(e&&e.length||n&&n.length)if(null==e)r="was ".concat(e,", now contains ").concat(n.length," element(s)");else if(null==n)r="contained ".concat(e.length," element(s), now is ").concat(n);else if(0===e.length)r="was empty, now contains ".concat(n.length," elements");else if(0===n.length)r="contained ".concat(e.length," elements, now is empty");else{var o=n.filter((function(n){return!e.find((function(e){return u(n,e)}))})),i=e.filter((function(e){return!n.find((function(n){return u(e,n)}))}));o.length>10&&(o="".concat(o.length," element(s) added")),i.length>10&&(i="".concat(i.length," element(s) removed")),r={added:o,removed:i}}else r=n}return r},o=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(t){var i,s;n=(null===(i=t.options)||void 0===i?void 0:i.name)?"[".concat(null===(s=t.options)||void 0===s?void 0:s.name,"]"):"";var u=t.state;e.group(n,"initialState"),Object.keys(u).forEach((function(e){r.log(e,":",o(u[e]))})),e.groupEnd()},destroy:null,effects:function(e,i,s,u){var c,a=null===(c=e.context)||void 0===c?void 0:c.args,f=[n,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?f.push(u?"START":"CANCELLED"):"effects"===e.type?f.push("DONE"):f.push("FAILED")),null!=s||a&&0!==Object.keys(a).length?r.group.apply(r,f):r.log.apply(r,f),a&&Object.keys(a).length>0&&(r.group("Arguments"),a.forEach((function(e){r.log(e,":",o(e))})),r.groupEnd()),null!=s){if(r.groupCollapsed("Before"),null==i)r.log("was null");else Object.keys(i).forEach((function(e){r.log(e,":",o(i[e]))}));if(r.groupEnd(),r.groupCollapsed("After"),null==s)r.log("was null");else Object.keys(s).forEach((function(e){r.log(e,":",o(s[e]))}));if(r.groupEnd(),null!=s){r.group("Diff");var l=function(e,n){var r={};return e&&Object.keys(e).forEach((function(o){if(n.hasOwnProperty(o)){var i=e[o],s=n[o],u=t(i,s);u&&(r[o]=u)}else r[o]="was deleted"})),Object.keys(n).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var i=n[o];r[o]=t(void 0,i)}})),r}(i,s);Object.keys(l).forEach((function(e){return r.log(e,":",l[e])})),r.groupEnd()}}return r.groupEnd(),null}}}});export{v as default,g as isAdvancedSyncAction,f as isAsyncAction,l as isAsyncPromiseGetAction,p as isSyncAction,y as useOnMount,h as useOnUnload,E as useOnUnmount};
2
2
  //# sourceMappingURL=v5.js.map
package/index.d.ts CHANGED
@@ -42,7 +42,6 @@ export type StoreApi<S, A extends DecoratedActions, P, DS = {}> = {
42
42
  /**
43
43
  * Runs onMount (and onPropsChange entries flagged onMount) exactly once for this store instance.
44
44
  * Must be called from an effect (useLayoutEffect/useEffect), never from a render body.
45
- * @internal
46
45
  */
47
46
  readonly runMountEffects: () => void;
48
47
  /**
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./impl"),r=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 t,r=1,n=arguments.length;r<n;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e},o.apply(this,arguments)};function c(e,t,r){if(r||2===arguments.length)for(var n,u=0,o=t.length;u<o;u++)!n&&u in t||(n||(n=Array.prototype.slice.call(t,0,u)),n[u]=t[u]);return e.concat(n||Array.prototype.slice.call(t))}function i(e){var t={exports:{}};return e(t,t.exports),t.exports}"function"==typeof SuppressedError&&SuppressedError;var a="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},l=u.default.useState,f=u.default.useEffect,s=u.default.useLayoutEffect,d=u.default.useDebugValue;function v(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!a(e,r)}catch(e){return!0}}var p="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var r=t(),n=l({inst:{value:r,getSnapshot:t}}),u=n[0].inst,o=n[1];return s((function(){u.value=r,u.getSnapshot=t,v(u)&&o({inst:u})}),[e,r,t]),f((function(){return v(u)&&o({inst:u}),e((function(){v(u)&&o({inst:u})}))}),[e]),d(r),r},O={useSyncExternalStore:void 0!==u.default.useSyncExternalStore?u.default.useSyncExternalStore:p},E=i((function(e,t){"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=u.default,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,c=r.useEffect,i=r.useLayoutEffect,a=r.useDebugValue,l=!1,f=!1,s="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,u){l||void 0===r.startTransition||(l=!0,console.error("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 s=u();if(!f){var d=u();n(s,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var v=(d=o({inst:{value:s,getSnapshot:u}}))[0].inst,p=d[1];return i((function(){v.value=s,v.getSnapshot=u,e(v)&&p({inst:v})}),[t,s,u]),c((function(){return e(v)&&p({inst:v}),t((function(){e(v)&&p({inst:v})}))}),[t]),a(s),s};t.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:s,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),S=O,_=E,y=i((function(e){"production"===process.env.NODE_ENV?e.exports=S:e.exports=_})),g=y;var L,b="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},A=y.useSyncExternalStore,R=u.default.useRef,h=u.default.useEffect,x=u.default.useMemo,M=u.default.useDebugValue,D={useSyncExternalStoreWithSelector:function(e,t,r,n,u){var o=R(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=x((function(){function e(e){if(!a){if(a=!0,o=e,e=n(e),void 0!==u&&c.hasValue){var t=c.value;if(u(t,e))return i=t}return i=e}if(t=i,b(o,e))return t;var r=n(e);return void 0!==u&&u(t,r)?(o=e,t):(o=e,i=r)}var o,i,a=!1,l=void 0===r?null:r;return[function(){return e(t())},null===l?void 0:function(){return e(l())}]}),[t,r,n,u]);var i=A(e,o[0],o[1]);return h((function(){c.hasValue=!0,c.value=i}),[i]),M(i),i}},m=i((function(e,t){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=u.default,r=y,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useSyncExternalStore,c=e.useRef,i=e.useEffect,a=e.useMemo,l=e.useDebugValue;t.useSyncExternalStoreWithSelector=function(e,t,r,u,f){var s=c(null);if(null===s.current){var d={hasValue:!1,value:null};s.current=d}else d=s.current;s=a((function(){function e(e){if(!i){if(i=!0,o=e,e=u(e),void 0!==f&&d.hasValue){var t=d.value;if(f(t,e))return c=t}return c=e}if(t=c,n(o,e))return t;var r=u(e);return void 0!==f&&f(t,r)?(o=e,t):(o=e,c=r)}var o,c,i=!1,a=void 0===r?null:r;return[function(){return e(t())},null===a?void 0:function(){return e(a())}]}),[t,r,u,f]);var v=o(e,s[0],s[1]);return i((function(){d.hasValue=!0,d.value=v}),[v]),l(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),T=D,j=m,P=i((function(e){"production"===process.env.NODE_ENV?e.exports=T:e.exports=j}));exports.ConflictPolicy=void 0,(L=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",L.IGNORE="ignore",L.KEEP_LAST="keepLast",L.KEEP_ALL="keepAll",L.PARALLEL="parallel",L.REUSE="reuse",L.ABORT="abort";var C=P.useSyncExternalStoreWithSelector,V=g.useSyncExternalStore;function w(e){var n=t.createRef(),u=t.createRef(),i=t.createRef(),a=t.createRef(),l=t.createRef(),f=t.createRef(),s=t.createRef(),d=t.createRef(),v=t.createRef(),p=t.createRef(),O=t.createRef(),E=t.createRef(!1),S=t.createRef(!1),_=t.createRef(!1),y=t.createRef(),g=t.createRef([]),L=e.actions,b=e.middlewares,A=void 0===b?[]:b,R=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(r[n[u]]=e[n[u]])}return r}(e,["actions","middlewares"]),h=t.isFuncConfig(e)?e.getInitialState:function(){return e.initialState},x={},M=0;function D(){y.current=o(o(o(o(o({},i.current),a.current),n.current),u.current.state),{isLoading:I,abortAction:k,loading:d.current,loadingMap:s.current,loadingParallelMap:f.current,errorMap:B(),errorParallelMap:v.current}),_.current=!1,Object.keys(x).forEach((function(e){var t;null===(t=x[e])||void 0===t||t.call(x)}))}function m(e){var r=i.current;i.current=e,E.current?t.onPropChange(n,u,i,r,a,R,h,V,!1,!1):P(e)}function T(e){n.current=e,t.computeDerivedValues(n,i,u,R),D()}function j(e){f.current=e,s.current=function(){if(E.current){var e=f.current;return Object.keys(e).reduce((function(t,r){var n=e[r];return t[r]=null!=Object.keys(n).find((function(e){return!!n[e]})),t}),{})}return null}(),d.current=function(){if(E.current){var e=f.current;return null!=Object.keys(e).find((function(t){var r=e[t];return Object.keys(r).find((function(e){return!!r[e]}))}))}return null}()}function P(o){var c;if(!E.current){i.current=o,E.current=!0,n.current=h(o);var a=new Set(null==R?void 0:R.initialActionsMarkedLoading),f=Object.keys(L).reduce((function(e,r){var n;return e[r]=a.has(r)?((n={})[t.DEFAULT_PROMISE_ID]=!0,n):{},e}),{});j(f),v.current=Object.keys(L).reduce((function(e,t){return e[t]={},e}),{}),l.current={},p.current={},O.current={},u.current={state:null,deps:{}},(null==R?void 0:R.derivedState)&&t.fixDerivedDeps(R),g.current=[];var s={options:R,get state(){return n.current},actions:L,setState:T};e.logEnabled&&r.logDetailedEffects&&A.push(r.logDetailedEffects());var d=function(e){var t,r=e();g.current.push(r),null===(t=r.init)||void 0===t||t.call(r,s)};null===(c=t.globalConfig.defaultMiddlewares)||void 0===c||c.forEach(d),null==A||A.forEach(d),t.computeDerivedValues(n,i,u,R),D()}}function C(e,r){void 0===r&&(r=t.DEFAULT_PROMISE_ID);var n=v.current[e];(null==n?void 0:n[r])&&delete n[r],D()}function V(e,r,o,c,a,l,s,d,v){void 0===s&&(s=!1),void 0===d&&(d=!1),void 0===v&&(v=!1);var p=!1;if(!E.current)return D;var O=r,S=!!a&&t.isLoadingImpl(O||f.current,[o,null==l?void 0:l.promiseId]),_=t.runMiddlewares(g.current,n.current,e,S,o,c,a,l),y=_.newState,L=_.newLoading;if(null!=y&&(p=!0,n.current=y),S!==L&&(O=t.buildLoadingMap(O,o,(null==l?void 0:l.promiseId)||t.DEFAULT_PROMISE_ID,L),0===Object.keys(O).length&&(O=void 0)),null!=O&&(p=!0,j(O)),p)t.computeDerivedValues(n,i,u,R),d||(n.current=y||n.current,v||D());else if(s){!t.computeDerivedValues(n,i,u,R)||d||v||D()}return D}var w=Object.keys(L);function I(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.isLoadingImpl.apply(void 0,c([f.current],e,!1))}function k(e,r){var n,u;void 0===r&&(r=t.DEFAULT_PROMISE_ID);var o=null===(u=null===(n=p.current[e])||void 0===n?void 0:n[r])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function B(){return E.current?t.buildErrorMap(v.current):null}return a.current=w.reduce((function(e,r){var o=L[r];return t.isSimpleSyncAction(o)?e[r]=t.decorateSimpleSyncAction(r,o,n,u,i,E,R,V):t.isAsyncAction(o)?e[r]=t.decorateAsyncAction({actionName:r,stateRef:n,derivedStateRef:u,propsRef:i,loadingParallelMapRef:f,errorMapRef:v,actionsRef:a,promisesRef:p,conflictActionsRef:O,initializedRef:E,timeoutRef:l,needNotifyListenersRef:_,options:R,setState:V,clearError:C,action:t.computeAsyncActionInput(o)}):t.isSyncAction(o)&&(e[r]=t.decorateSyncAction(r,o,n,u,i,a,E,l,_,R,V,C)),e}),{}),{getConfig:function(){return o({},e)},setProps:m,addStateListener:function(e){var t="".concat(M++);return x[t]=e,function(){delete x[t]}},init:P,runMountEffects:function(){E.current&&!S.current&&(S.current=!0,t.onPropChange(n,u,i,null,a,R,h,V,!0,!1),(null==R?void 0:R.onMount)&&R.onMount(t.buildOnMountInvocationContext(n,u,i,a)),D())},destroy:function(){var e;if(E.current){var r=Object.keys(L).reduce((function(e,r){var n=L[r];if(t.isAsyncAction(n)&&n.abortable){var u=f.current[r],o=Object.keys(u).reduce((function(e,t){return u[t]&&(k(r,t),e.push(t)),e}),[]);o.length>0&&(e[r]=o)}return e}),{});null===(e=null==R?void 0:R.onUnmount)||void 0===e||e.call(R,t.buildOnUnMountInvocationContext(n,u,i,r)),Object.keys(l.current).forEach((function(e){clearTimeout(l.current[e])})),i.current=null,n.current=null,f.current=null,s.current=null,d.current=null,v.current=null,p.current=null,O.current=null,u.current=null,y.current=null,l.current=null,x={},E.current=!1,S.current=!1,g.current.forEach((function(e){var t;null===(t=e.destroy)||void 0===t||t.call(e)})),g.current=[]}},isLoading:I,abortAction:k,clearError:C,getSnapshot:function(){return y.current},invokeOnMountDeferred:function(){t.onPropChange(n,u,i,null,a,R,h,V,!0,!0),(null==R?void 0:R.onMountDeferred)&&R.onMountDeferred(t.buildOnMountInvocationContext(n,u,i,a))},listenToStoreProps:function(e,t){var r=e.state?G(e.state,t):{};return e.addStateListener((function(){var n=e.state;if(n){var u=G(n,t);t.some((function(e){return!Object.is(r[e],u[e])}))&&(r=u,m(o(o({},i.current),u)))}}))},get actions(){return a.current},get state(){return E.current?o(o({},n.current),u.current.state):null},get loading(){return d.current},get loadingMap(){return s.current},get errorMap(){return B()},get loadingParallelMap(){return E.current?f.current:null},get errorParallelMap(){return E.current?v.current:null}}}function I(r,n,u){void 0===u&&(u=[]);var o=e.useMemo((function(){return n instanceof Function?n:function(e){return G(e,n)}}),c([n],u,!0));return C(r.addStateListener,r.getSnapshot,void 0,o,t.globalConfig.comparator)}function k(t,r,n){void 0===n&&(n=!0);var u=e.useRef();return null==u.current&&(u.current=w(t)),e.useEffect((function(){return u.current.invokeOnMountDeferred(),function(){var e;null===(e=u.current)||void 0===e||e.destroy()}}),[]),function(t,r,n){void 0===r&&(r=null),void 0===n&&(n=!0);var u=e.useReducer((function(e){return e>100?0:e+1}),0)[1],o=e.useRef(t);return t.setProps(r),e.useLayoutEffect((function(){t.init(r),t.runMountEffects()}),[]),e.useLayoutEffect((function(){if(n)return o.current.addStateListener((function(){u()}))}),[n]),t}(u.current,r,n)}function G(e,t){return t.reduce((function(t,r){return e.hasOwnProperty(r)&&(t[r]=e[r]),t}),{})}Object.defineProperty(exports,"EffectError",{enumerable:!0,get:function(){return t.EffectError}}),Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return t.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return t.setGlobalConfig}}),exports.createStore=w,exports.default=k,exports.pick=G,exports.slice=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return G(t,e)}},exports.useBindStore=function(t,r){return t.setProps(r),V(t.addStateListener,t.getSnapshot),e.useLayoutEffect((function(){t.init(r),t.runMountEffects()}),[]),e.useEffect((function(){t.invokeOnMountDeferred()}),[t]),t},exports.useLocalStore=k,exports.useStore=function(e){return V(e.addStateListener,e.getSnapshot),e},exports.useStoreContextSlice=function(t,r){return I(e.useContext(t),r)},exports.useStoreSlice=I;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./impl"),r=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 t,r=1,n=arguments.length;r<n;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e},o.apply(this,arguments)};function c(e,t,r){if(r||2===arguments.length)for(var n,u=0,o=t.length;u<o;u++)!n&&u in t||(n||(n=Array.prototype.slice.call(t,0,u)),n[u]=t[u]);return e.concat(n||Array.prototype.slice.call(t))}function i(e){var t={exports:{}};return e(t,t.exports),t.exports}"function"==typeof SuppressedError&&SuppressedError;var a="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},l=u.default.useState,f=u.default.useEffect,s=u.default.useLayoutEffect,d=u.default.useDebugValue;function v(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!a(e,r)}catch(e){return!0}}var p="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var r=t(),n=l({inst:{value:r,getSnapshot:t}}),u=n[0].inst,o=n[1];return s((function(){u.value=r,u.getSnapshot=t,v(u)&&o({inst:u})}),[e,r,t]),f((function(){return v(u)&&o({inst:u}),e((function(){v(u)&&o({inst:u})}))}),[e]),d(r),r},O={useSyncExternalStore:void 0!==u.default.useSyncExternalStore?u.default.useSyncExternalStore:p},E=i((function(e,t){"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=u.default,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,c=r.useEffect,i=r.useLayoutEffect,a=r.useDebugValue,l=!1,f=!1,s="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,u){l||void 0===r.startTransition||(l=!0,console.error("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 s=u();if(!f){var d=u();n(s,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var v=(d=o({inst:{value:s,getSnapshot:u}}))[0].inst,p=d[1];return i((function(){v.value=s,v.getSnapshot=u,e(v)&&p({inst:v})}),[t,s,u]),c((function(){return e(v)&&p({inst:v}),t((function(){e(v)&&p({inst:v})}))}),[t]),a(s),s};t.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:s,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),S=O,_=E,y=i((function(e){"production"===process.env.NODE_ENV?e.exports=S:e.exports=_})),g=y;var L,b="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},A=y.useSyncExternalStore,R=u.default.useRef,h=u.default.useEffect,x=u.default.useMemo,M=u.default.useDebugValue,D={useSyncExternalStoreWithSelector:function(e,t,r,n,u){var o=R(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=x((function(){function e(e){if(!a){if(a=!0,o=e,e=n(e),void 0!==u&&c.hasValue){var t=c.value;if(u(t,e))return i=t}return i=e}if(t=i,b(o,e))return t;var r=n(e);return void 0!==u&&u(t,r)?(o=e,t):(o=e,i=r)}var o,i,a=!1,l=void 0===r?null:r;return[function(){return e(t())},null===l?void 0:function(){return e(l())}]}),[t,r,n,u]);var i=A(e,o[0],o[1]);return h((function(){c.hasValue=!0,c.value=i}),[i]),M(i),i}},m=i((function(e,t){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=u.default,r=y,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useSyncExternalStore,c=e.useRef,i=e.useEffect,a=e.useMemo,l=e.useDebugValue;t.useSyncExternalStoreWithSelector=function(e,t,r,u,f){var s=c(null);if(null===s.current){var d={hasValue:!1,value:null};s.current=d}else d=s.current;s=a((function(){function e(e){if(!i){if(i=!0,o=e,e=u(e),void 0!==f&&d.hasValue){var t=d.value;if(f(t,e))return c=t}return c=e}if(t=c,n(o,e))return t;var r=u(e);return void 0!==f&&f(t,r)?(o=e,t):(o=e,c=r)}var o,c,i=!1,a=void 0===r?null:r;return[function(){return e(t())},null===a?void 0:function(){return e(a())}]}),[t,r,u,f]);var v=o(e,s[0],s[1]);return i((function(){d.hasValue=!0,d.value=v}),[v]),l(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()})),T=D,j=m,P=i((function(e){"production"===process.env.NODE_ENV?e.exports=T:e.exports=j}));exports.ConflictPolicy=void 0,(L=exports.ConflictPolicy||(exports.ConflictPolicy={})).REJECT="reject",L.IGNORE="ignore",L.KEEP_LAST="keepLast",L.KEEP_ALL="keepAll",L.PARALLEL="parallel",L.REUSE="reuse",L.ABORT="abort";var C=P.useSyncExternalStoreWithSelector,V=g.useSyncExternalStore;function w(e){var n=t.createRef(),u=t.createRef(),i=t.createRef(),a=t.createRef(),l=t.createRef(),f=t.createRef(),s=t.createRef(),d=t.createRef(),v=t.createRef(),p=t.createRef(),O=t.createRef(),E=t.createRef(!1),S=t.createRef(!1),_=t.createRef(!1),y=t.createRef(),g=t.createRef([]),L=e.actions,b=e.middlewares,A=void 0===b?[]:b,R=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(r[n[u]]=e[n[u]])}return r}(e,["actions","middlewares"]),h=t.isFuncConfig(e)?e.getInitialState:function(){return e.initialState},x={},M=0;function D(){y.current=o(o(o(o(o({},i.current),a.current),n.current),u.current.state),{isLoading:I,abortAction:k,loading:d.current,loadingMap:s.current,loadingParallelMap:f.current,errorMap:B(),errorParallelMap:v.current}),_.current=!1,Object.keys(x).forEach((function(e){var t;null===(t=x[e])||void 0===t||t.call(x)}))}function m(e){var r=i.current;i.current=e,E.current?t.onPropChange(n,u,i,r,a,R,h,V,!1,!1):P(e)}function T(e){n.current=e,t.computeDerivedValues(n,i,u,R),D()}function j(e){f.current=e,s.current=function(){if(E.current){var e=f.current;return Object.keys(e).reduce((function(t,r){var n=e[r];return t[r]=null!=Object.keys(n).find((function(e){return!!n[e]})),t}),{})}return null}(),d.current=function(){if(E.current){var e=f.current;return null!=Object.keys(e).find((function(t){var r=e[t];return Object.keys(r).find((function(e){return!!r[e]}))}))}return null}()}function P(o){var c;if(!E.current){i.current=o,E.current=!0,n.current=h(o);var a=new Set(null==R?void 0:R.initialActionsMarkedLoading),f=Object.keys(L).reduce((function(e,r){var n;return e[r]=a.has(r)?((n={})[t.DEFAULT_PROMISE_ID]=!0,n):{},e}),{});j(f),v.current=Object.keys(L).reduce((function(e,t){return e[t]={},e}),{}),l.current={},p.current={},O.current={},u.current={state:null,deps:{}},(null==R?void 0:R.derivedState)&&t.fixDerivedDeps(R),g.current=[];var s={options:R,get state(){return n.current},actions:L,setState:T};e.logEnabled&&r.logDetailedEffects&&A.push(r.logDetailedEffects());var d=function(e){var t,r=e();g.current.push(r),null===(t=r.init)||void 0===t||t.call(r,s)};null===(c=t.globalConfig.defaultMiddlewares)||void 0===c||c.forEach(d),null==A||A.forEach(d),t.computeDerivedValues(n,i,u,R),D()}}function C(e,r){void 0===r&&(r=t.DEFAULT_PROMISE_ID);var n=v.current[e];(null==n?void 0:n[r])&&delete n[r],D()}function V(e,r,o,c,a,l,s,d,v){void 0===s&&(s=!1),void 0===d&&(d=!1),void 0===v&&(v=!1);var p=!1;if(!E.current)return D;var O=r,S=!!a&&t.isLoadingImpl(O||f.current,[o,null==l?void 0:l.promiseId]),_=t.runMiddlewares(g.current,n.current,e,S,o,c,a,l),y=_.newState,L=_.newLoading;if(null!=y&&(p=!0,n.current=y),S!==L&&(O=t.buildLoadingMap(O,o,(null==l?void 0:l.promiseId)||t.DEFAULT_PROMISE_ID,L),0===Object.keys(O).length&&(O=void 0)),null!=O&&(p=!0,j(O)),p)t.computeDerivedValues(n,i,u,R),d||(n.current=y||n.current,v||D());else if(s){!t.computeDerivedValues(n,i,u,R)||d||v||D()}return D}var w=Object.keys(L);function I(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.isLoadingImpl.apply(void 0,c([f.current],e,!1))}function k(e,r){var n,u;void 0===r&&(r=t.DEFAULT_PROMISE_ID);var o=null===(u=null===(n=p.current[e])||void 0===n?void 0:n[r])||void 0===u?void 0:u.abortController,c=!1;return o&&(o.abort(),c=!0),c}function B(){return E.current?t.buildErrorMap(v.current):null}return a.current=w.reduce((function(e,r){var o=L[r];return t.isSimpleSyncAction(o)?e[r]=t.decorateSimpleSyncAction(r,o,n,u,i,E,R,V):t.isAsyncAction(o)?e[r]=t.decorateAsyncAction({actionName:r,stateRef:n,derivedStateRef:u,propsRef:i,loadingParallelMapRef:f,errorMapRef:v,actionsRef:a,promisesRef:p,conflictActionsRef:O,initializedRef:E,timeoutRef:l,needNotifyListenersRef:_,options:R,setState:V,clearError:C,action:t.computeAsyncActionInput(o)}):t.isSyncAction(o)&&(e[r]=t.decorateSyncAction(r,o,n,u,i,a,E,l,_,R,V,C)),e}),{}),{getConfig:function(){return o({},e)},setProps:m,addStateListener:function(e){var t="".concat(M++);return x[t]=e,function(){delete x[t]}},init:P,runMountEffects:function(){E.current&&!S.current&&(S.current=!0,t.onPropChange(n,u,i,null,a,R,h,V,!0,!1),(null==R?void 0:R.onMount)&&R.onMount(t.buildOnMountInvocationContext(n,u,i,a)),D())},destroy:function(){var e;if(E.current){var r=Object.keys(L).reduce((function(e,r){var n=L[r];if(t.isAsyncAction(n)&&n.abortable){var u=f.current[r],o=Object.keys(u).reduce((function(e,t){return u[t]&&(k(r,t),e.push(t)),e}),[]);o.length>0&&(e[r]=o)}return e}),{});null===(e=null==R?void 0:R.onUnmount)||void 0===e||e.call(R,t.buildOnUnMountInvocationContext(n,u,i,r)),Object.keys(l.current).forEach((function(e){clearTimeout(l.current[e])})),i.current=null,n.current=null,f.current=null,s.current=null,d.current=null,v.current=null,p.current=null,O.current=null,u.current=null,y.current=null,l.current=null,x={},E.current=!1,S.current=!1,g.current.forEach((function(e){var t;null===(t=e.destroy)||void 0===t||t.call(e)})),g.current=[]}},isLoading:I,abortAction:k,clearError:C,getSnapshot:function(){return y.current},invokeOnMountDeferred:function(){t.onPropChange(n,u,i,null,a,R,h,V,!0,!0),(null==R?void 0:R.onMountDeferred)&&R.onMountDeferred(t.buildOnMountInvocationContext(n,u,i,a))},listenToStoreProps:function(e,t){var r=e.state?G(e.state,t):{};return e.addStateListener((function(){var n=e.state;if(n){var u=G(n,t);t.some((function(e){return!Object.is(r[e],u[e])}))&&(r=u,m(o(o({},i.current),u)))}}))},get actions(){return a.current},get state(){return E.current?o(o({},n.current),u.current.state):null},get loading(){return d.current},get loadingMap(){return s.current},get errorMap(){return B()},get loadingParallelMap(){return E.current?f.current:null},get errorParallelMap(){return E.current?v.current:null}}}function I(r,n,u){void 0===u&&(u=[]);var o=e.useMemo((function(){return n instanceof Function?n:function(e){return G(e,n)}}),c([n],u,!0));return C(r.addStateListener,r.getSnapshot,void 0,o,t.globalConfig.comparator)}function k(t,r,n){void 0===n&&(n=!0);var u=e.useRef();return null==u.current&&(u.current=w(t)),e.useEffect((function(){return u.current.invokeOnMountDeferred(),function(){var e;null===(e=u.current)||void 0===e||e.destroy()}}),[]),function(t,r,n){void 0===r&&(r=null),void 0===n&&(n=!0);var u=e.useReducer((function(e){return e>100?0:e+1}),0)[1],o=e.useRef(t);return t.setProps(r),e.useLayoutEffect((function(){if(n)return o.current.addStateListener((function(){u()}))}),[n]),e.useLayoutEffect((function(){t.init(r),t.runMountEffects()}),[]),t}(u.current,r,n)}function G(e,t){return t.reduce((function(t,r){return e.hasOwnProperty(r)&&(t[r]=e[r]),t}),{})}Object.defineProperty(exports,"EffectError",{enumerable:!0,get:function(){return t.EffectError}}),Object.defineProperty(exports,"ParallelActionError",{enumerable:!0,get:function(){return t.ParallelActionError}}),Object.defineProperty(exports,"setGlobalConfig",{enumerable:!0,get:function(){return t.setGlobalConfig}}),exports.createStore=w,exports.default=k,exports.pick=G,exports.slice=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return G(t,e)}},exports.useBindStore=function(t,r){return t.setProps(r),V(t.addStateListener,t.getSnapshot),e.useLayoutEffect((function(){t.init(r),t.runMountEffects()}),[]),e.useEffect((function(){t.invokeOnMountDeferred()}),[t]),t},exports.useLocalStore=k,exports.useStore=function(e){return V(e.addStateListener,e.getSnapshot),e},exports.useStoreContextSlice=function(t,r){return I(e.useContext(t),r)},exports.useStoreSlice=I;
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-decorator",
3
- "version": "7.7.0-beta.1",
3
+ "version": "8.0.0",
4
4
  "description": "React state management library",
5
5
  "main": "index.js",
6
6
  "module": "es/index.js",
package/v5.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("./index"),r=require("react"),t=function(){return t=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},t.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse",e.ABORT="abort"}(e||(e={}));var o=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==typeof n&&"object"==typeof r){if(n.constructor!==r.constructor)return!1;var t,o,s;if(Array.isArray(n)){if((t=n.length)!=r.length)return!1;for(o=t;0!=o--;)if(!e(n[o],r[o]))return!1;return!0}if(n.constructor===RegExp)return n.source===r.source&&n.flags===r.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===r.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===r.toString();if((t=(s=Object.keys(n)).length)!==Object.keys(r).length)return!1;for(o=t;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=t;0!=o--;){var u=s[o];if(!e(n[u],r[u]))return!1}return!0}return n!=n&&r!=r},s=null;function u(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function i(e){return e instanceof Function}function c(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function a(n){return Object.keys(n).reduce((function(r,t){var o=n[t];if(i(o))r[t]=function(e){return o(e.s,e.args,e.p)};else if(c(o)){var s={effects:function(e){return o.action(e.s,e.args,e.p)}};o.onActionDone&&(s.sideEffects=function(e){var n=e.s,r=e.p,t=e.args,s=e.a,u=e.notifyWarning;o.onActionDone(n,t,r,s,u)}),r[t]=s}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(o)||u(o)){var a;a=u(o)?{getPromise:function(e){var n=e.s,r=e.p,t=e.a,s=e.args,u=e.abortSignal;return o.promiseGet(s,n,r,t,u)},retryCount:3,conflictPolicy:e.REUSE}:{getPromise:function(e){var n=e.s,r=e.p,t=e.a,s=e.args,u=e.abortSignal;return o.promise(s,n,r,t,u)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=o[e]&&(a[e]=o[e])})),o.successMessage&&(a.getSuccessMessage=function(){return o.successMessage}),o.errorMessage&&(a.getSuccessMessage=function(){return o.errorMessage}),o.getSuccessMessage&&(a.getSuccessMessage=function(e){var n=e.res,r=e.args,t=e.p;return o.getSuccessMessage(n,r,t)}),o.getErrorMessage&&(a.getErrorMessage=function(e){var n=e.err,r=e.args,t=e.p;return o.getErrorMessage(n,r,t)}),o.preReducer&&(a.preEffects=function(e){var n=e.s,r=e.p,t=e.args;return o.preReducer(n,t,r)}),o.optimisticReducer&&(a.optimisticEffects=function(e){var n=e.s,r=e.p,t=e.args;return o.optimisticReducer(n,t,r)}),o.reducer&&(a.effects=function(e){var n=e.s,r=e.res,t=e.p,s=e.args;return o.reducer(n,r,s,t)}),o.errorReducer&&(a.errorEffects=function(e){var n=e.s,r=e.err,t=e.p,s=e.args;return o.errorReducer(n,r,s,t)}),o.onDone&&(a.sideEffects=function(e){var n=e.s,r=e.res,t=e.p,s=e.args,u=e.a,i=e.notifyWarning;return o.onDone(n,r,s,t,u,i)}),o.onFail&&(a.errorSideEffects=function(e){var n=e.s,r=e.err,t=e.p,s=e.args,u=e.a,i=e.notifyWarning;return o.onFail(n,r,s,t,u,i)}),r[t]=a}return r}),{})}"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||(s=function(e){return void 0===e&&(e=console),function(){var n="",r=e,t=function(e,n){var r;if(n!==e){var t=null!=e?typeof e:typeof n;if("number"===t||"string"===t||"boolean"===t)r="".concat(e," => ").concat(""===n?'""':n);else if(e&&e.length||n&&n.length)if(null==e)r="was ".concat(e,", now contains ").concat(n.length," element(s)");else if(null==n)r="contained ".concat(e.length," element(s), now is ").concat(n);else if(0===e.length)r="was empty, now contains ".concat(n.length," elements");else if(0===n.length)r="contained ".concat(e.length," elements, now is empty");else{var s=n.filter((function(n){return!e.find((function(e){return o(n,e)}))})),u=e.filter((function(e){return!n.find((function(n){return o(e,n)}))}));s.length>10&&(s="".concat(s.length," element(s) added")),u.length>10&&(u="".concat(u.length," element(s) removed")),r={added:s,removed:u}}else r=n}return r},s=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(t){var o,u;n=(null===(o=t.options)||void 0===o?void 0:o.name)?"[".concat(null===(u=t.options)||void 0===u?void 0:u.name,"]"):"";var i=t.state;e.group(n,"initialState"),Object.keys(i).forEach((function(e){r.log(e,":",s(i[e]))})),e.groupEnd()},destroy:null,effects:function(e,o,u,i){var c,a=null===(c=e.context)||void 0===c?void 0:c.args,f=[n,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?f.push(i?"START":"CANCELLED"):"effects"===e.type?f.push("DONE"):f.push("FAILED")),null!=u||a&&0!==Object.keys(a).length?r.group.apply(r,f):r.log.apply(r,f),a&&Object.keys(a).length>0&&(r.group("Arguments"),a.forEach((function(e){r.log(e,":",s(e))})),r.groupEnd()),null!=u){if(r.groupCollapsed("Before"),null==o)r.log("was null");else Object.keys(o).forEach((function(e){r.log(e,":",s(o[e]))}));if(r.groupEnd(),r.groupCollapsed("After"),null==u)r.log("was null");else Object.keys(u).forEach((function(e){r.log(e,":",s(u[e]))}));if(r.groupEnd(),null!=u){r.group("Diff");var l=function(e,n){var r={};return e&&Object.keys(e).forEach((function(o){if(n.hasOwnProperty(o)){var s=e[o],u=n[o],i=t(s,u);i&&(r[o]=i)}else r[o]="was deleted"})),Object.keys(n).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var s=n[o];r[o]=t(void 0,s)}})),r}(o,u);Object.keys(l).forEach((function(e){return r.log(e,":",l[e])})),r.groupEnd()}}return r.groupEnd(),null}}}}),exports.default=function(e,o,u,i,c){void 0===i&&(i={});var f,l,p,g,d=r.useReducer((function(e){return e>100?0:e+1}),0)[1],v=r.useRef(),y=r.useRef();null==v.current&&(v.current=a(o)),null==y.current&&(y.current=(f=i,l={},p=Object.keys(f),g=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],p.forEach((function(e){g.includes(e)||(l[e]=f[e])})),f.onMount&&(l.onMount=function(e){var n=e.s,r=e.p,t=e.a;return f.onMount(t,r,n)}),f.getPropsRefValues&&(l.onPropsChange={getDeps:f.getPropsRefValues,effects:function(e){var n=e.s,r=e.p,t=e.indices;return f.onPropsChangeReducer?f.onPropsChangeReducer(n,r,t):null},sideEffects:function(e){var n=e.s,r=e.p,t=e.a,o=e.indices;return null==f.onPropsChange?null:f.onPropsChange(n,r,t,o)}}),f.initialActionsMarkedLoading&&(l.initialActionsMarkedLoading=f.initialActionsMarkedLoading),l));var E=r.useRef();if(null==E.current){var h=c;i.logEnabled&&h.push(s()),E.current=n.createStore(t(t({getInitialState:e,actions:v.current},y.current),{middlewares:h}))}E.current.setProps(u),r.useLayoutEffect((function(){E.current.init(u),E.current.runMountEffects()}),[]),r.useLayoutEffect((function(){return E.current.addStateListener((function(){d()}))}),[]);var O=E.current;return{state:O.state,actions:O.actions,loading:O.loading,loadingMap:O.loadingMap,loadingParallelMap:O.loadingParallelMap,abortAction:O.abortAction}},exports.isAdvancedSyncAction=c,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))},exports.isAsyncPromiseGetAction=function(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))},exports.isSyncAction=i,exports.useOnMount=function(e){r.useEffect((function(){var n=e();return"function"==typeof n?n:void 0}),[e])},exports.useOnUnload=function(e){r.useEffect((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[e])},exports.useOnUnmount=function(e,n){void 0===n&&(n=[]),r.useEffect((function(){return e}),[n,e])};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("./index"),r=require("react"),t=function(){return t=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},t.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse",e.ABORT="abort"}(e||(e={}));var o=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==typeof n&&"object"==typeof r){if(n.constructor!==r.constructor)return!1;var t,o,s;if(Array.isArray(n)){if((t=n.length)!=r.length)return!1;for(o=t;0!=o--;)if(!e(n[o],r[o]))return!1;return!0}if(n.constructor===RegExp)return n.source===r.source&&n.flags===r.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===r.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===r.toString();if((t=(s=Object.keys(n)).length)!==Object.keys(r).length)return!1;for(o=t;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=t;0!=o--;){var u=s[o];if(!e(n[u],r[u]))return!1}return!0}return n!=n&&r!=r},s=null;function u(e){return!(e instanceof Function)&&e.hasOwnProperty("promiseGet")}function i(e){return e instanceof Function}function c(e){return!(e instanceof Function||e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))}function a(n){return Object.keys(n).reduce((function(r,t){var o=n[t];if(i(o))r[t]=function(e){return o(e.s,e.args,e.p)};else if(c(o)){var s={effects:function(e){return o.action(e.s,e.args,e.p)}};o.onActionDone&&(s.sideEffects=function(e){var n=e.s,r=e.p,t=e.args,s=e.a,u=e.notifyWarning;o.onActionDone(n,t,r,s,u)}),r[t]=s}else if(function(e){return!(e instanceof Function)&&e.hasOwnProperty("promise")}(o)||u(o)){var a;a=u(o)?{getPromise:function(e){var n=e.s,r=e.p,t=e.a,s=e.args,u=e.abortSignal;return o.promiseGet(s,n,r,t,u)},retryCount:3,conflictPolicy:e.REUSE}:{getPromise:function(e){var n=e.s,r=e.p,t=e.a,s=e.args,u=e.abortSignal;return o.promise(s,n,r,t,u)}},["abortable","conflictPolicy","getPromiseId","isTriggerRetryError","rejectPromiseOnError","retryCount","debounceTimeout","debounceSideEffectsTimeout","retryDelaySeed"].forEach((function(e){null!=o[e]&&(a[e]=o[e])})),o.successMessage&&(a.getSuccessMessage=function(){return o.successMessage}),o.errorMessage&&(a.getSuccessMessage=function(){return o.errorMessage}),o.getSuccessMessage&&(a.getSuccessMessage=function(e){var n=e.res,r=e.args,t=e.p;return o.getSuccessMessage(n,r,t)}),o.getErrorMessage&&(a.getErrorMessage=function(e){var n=e.err,r=e.args,t=e.p;return o.getErrorMessage(n,r,t)}),o.preReducer&&(a.preEffects=function(e){var n=e.s,r=e.p,t=e.args;return o.preReducer(n,t,r)}),o.optimisticReducer&&(a.optimisticEffects=function(e){var n=e.s,r=e.p,t=e.args;return o.optimisticReducer(n,t,r)}),o.reducer&&(a.effects=function(e){var n=e.s,r=e.res,t=e.p,s=e.args;return o.reducer(n,r,s,t)}),o.errorReducer&&(a.errorEffects=function(e){var n=e.s,r=e.err,t=e.p,s=e.args;return o.errorReducer(n,r,s,t)}),o.onDone&&(a.sideEffects=function(e){var n=e.s,r=e.res,t=e.p,s=e.args,u=e.a,i=e.notifyWarning;return o.onDone(n,r,s,t,u,i)}),o.onFail&&(a.errorSideEffects=function(e){var n=e.s,r=e.err,t=e.p,s=e.args,u=e.a,i=e.notifyWarning;return o.onFail(n,r,s,t,u,i)}),r[t]=a}return r}),{})}"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||(s=function(e){return void 0===e&&(e=console),function(){var n="",r=e,t=function(e,n){var r;if(n!==e){var t=null!=e?typeof e:typeof n;if("number"===t||"string"===t||"boolean"===t)r="".concat(e," => ").concat(""===n?'""':n);else if(e&&e.length||n&&n.length)if(null==e)r="was ".concat(e,", now contains ").concat(n.length," element(s)");else if(null==n)r="contained ".concat(e.length," element(s), now is ").concat(n);else if(0===e.length)r="was empty, now contains ".concat(n.length," elements");else if(0===n.length)r="contained ".concat(e.length," elements, now is empty");else{var s=n.filter((function(n){return!e.find((function(e){return o(n,e)}))})),u=e.filter((function(e){return!n.find((function(n){return o(e,n)}))}));s.length>10&&(s="".concat(s.length," element(s) added")),u.length>10&&(u="".concat(u.length," element(s) removed")),r={added:s,removed:u}}else r=n}return r},s=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(t){var o,u;n=(null===(o=t.options)||void 0===o?void 0:o.name)?"[".concat(null===(u=t.options)||void 0===u?void 0:u.name,"]"):"";var i=t.state;e.group(n,"initialState"),Object.keys(i).forEach((function(e){r.log(e,":",s(i[e]))})),e.groupEnd()},destroy:null,effects:function(e,o,u,i){var c,a=null===(c=e.context)||void 0===c?void 0:c.args,f=[n,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?f.push(i?"START":"CANCELLED"):"effects"===e.type?f.push("DONE"):f.push("FAILED")),null!=u||a&&0!==Object.keys(a).length?r.group.apply(r,f):r.log.apply(r,f),a&&Object.keys(a).length>0&&(r.group("Arguments"),a.forEach((function(e){r.log(e,":",s(e))})),r.groupEnd()),null!=u){if(r.groupCollapsed("Before"),null==o)r.log("was null");else Object.keys(o).forEach((function(e){r.log(e,":",s(o[e]))}));if(r.groupEnd(),r.groupCollapsed("After"),null==u)r.log("was null");else Object.keys(u).forEach((function(e){r.log(e,":",s(u[e]))}));if(r.groupEnd(),null!=u){r.group("Diff");var l=function(e,n){var r={};return e&&Object.keys(e).forEach((function(o){if(n.hasOwnProperty(o)){var s=e[o],u=n[o],i=t(s,u);i&&(r[o]=i)}else r[o]="was deleted"})),Object.keys(n).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var s=n[o];r[o]=t(void 0,s)}})),r}(o,u);Object.keys(l).forEach((function(e){return r.log(e,":",l[e])})),r.groupEnd()}}return r.groupEnd(),null}}}}),exports.default=function(e,o,u,i,c){void 0===i&&(i={});var f,l,p,g,d=r.useReducer((function(e){return e>100?0:e+1}),0)[1],v=r.useRef(),y=r.useRef();null==v.current&&(v.current=a(o)),null==y.current&&(y.current=(f=i,l={},p=Object.keys(f),g=["onPropsChange","onPropsChangeReducer","getPropsRefValues","onMount","initialActionsMarkedLoading"],p.forEach((function(e){g.includes(e)||(l[e]=f[e])})),f.onMount&&(l.onMount=function(e){var n=e.s,r=e.p,t=e.a;return f.onMount(t,r,n)}),f.getPropsRefValues&&(l.onPropsChange={getDeps:f.getPropsRefValues,effects:function(e){var n=e.s,r=e.p,t=e.indices;return f.onPropsChangeReducer?f.onPropsChangeReducer(n,r,t):null},sideEffects:function(e){var n=e.s,r=e.p,t=e.a,o=e.indices;return null==f.onPropsChange?null:f.onPropsChange(n,r,t,o)}}),f.initialActionsMarkedLoading&&(l.initialActionsMarkedLoading=f.initialActionsMarkedLoading),l));var E=r.useRef();if(null==E.current){var h=c;i.logEnabled&&h.push(s()),E.current=n.createStore(t(t({getInitialState:e,actions:v.current},y.current),{middlewares:h}))}E.current.setProps(u),r.useLayoutEffect((function(){return E.current.addStateListener((function(){d()}))}),[]),r.useLayoutEffect((function(){E.current.init(u),E.current.runMountEffects()}),[]);var O=E.current;return{state:O.state,actions:O.actions,loading:O.loading,loadingMap:O.loadingMap,loadingParallelMap:O.loadingParallelMap,abortAction:O.abortAction}},exports.isAdvancedSyncAction=c,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("promise")||e.hasOwnProperty("promiseGet"))},exports.isAsyncPromiseGetAction=function(e){return!(e instanceof Function||e.hasOwnProperty("promise")&&e.hasOwnProperty("promiseGet"))},exports.isSyncAction=i,exports.useOnMount=function(e){r.useEffect((function(){var n=e();return"function"==typeof n?n:void 0}),[e])},exports.useOnUnload=function(e){r.useEffect((function(){return document.addEventListener("beforeunload",e),function(){document.removeEventListener("beforeunload",e)}}),[e])},exports.useOnUnmount=function(e,n){void 0===n&&(n=[]),r.useEffect((function(){return e}),[n,e])};
2
2
  //# sourceMappingURL=v5.js.map