state-decorator 7.0.0-beta.0 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -54
- package/es/helpers.d.ts +48 -0
- package/es/helpers.js +2 -0
- package/es/helpers.js.map +1 -0
- package/es/impl.d.ts +4 -2
- package/es/impl.js +1 -1
- package/es/index.d.ts +7 -2
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/middlewares.js +1 -1
- package/es/test.d.ts +2 -2
- package/es/test.js +1 -1
- package/es/test.js.map +1 -1
- package/es/types.d.ts +20 -1
- package/helpers.d.ts +48 -0
- package/helpers.js +2 -0
- package/helpers.js.map +1 -0
- package/impl.d.ts +4 -2
- package/impl.js +1 -1
- package/index.d.ts +7 -2
- package/index.js +1 -1
- package/middlewares.js +1 -1
- package/package.json +2 -3
- package/test.d.ts +2 -2
- package/test.js +1 -1
- package/test.js.map +1 -1
- package/types.d.ts +20 -1
package/README.md
CHANGED
|
@@ -19,10 +19,13 @@ The StateDecorator is a set of Reacts hook that manages a complex component stat
|
|
|
19
19
|
|
|
20
20
|
# V7: Partial state and new hooks
|
|
21
21
|
|
|
22
|
+
- React 17 (upcoming V8 for React 18)
|
|
22
23
|
- All effects can now return a partial state that will be merged with current state.
|
|
23
24
|
- More documentation on global and local store use cases.
|
|
24
25
|
- **useLocalStore** and **useStore** now have a parameter to specify if the React component must re-rerender after a state change.
|
|
25
26
|
- New **useStoreContextSlice** hook was added to get a slice of a store in a context.
|
|
27
|
+
- New **onMountDeferred** to execute initialization code after initial render
|
|
28
|
+
- New effect helpers
|
|
26
29
|
- Removed useBindStore hook.
|
|
27
30
|
|
|
28
31
|
# 🏎️ V6: The Store
|
|
@@ -573,94 +576,132 @@ export const actionsAbort: StoreActions<State, Actions, Props> = {
|
|
|
573
576
|
};
|
|
574
577
|
```
|
|
575
578
|
|
|
579
|
+
Note: ongoing abortable actions will be automatically aborted on store destruction (during React component unmount for example). The list of aborted actions is available in the **onUnmount** callback in the store's options.
|
|
580
|
+
|
|
576
581
|
[](https://codesandbox.io/s/abort-v6-uvnl7)
|
|
577
582
|
|
|
578
|
-
|
|
583
|
+
## Helper effect functions
|
|
579
584
|
|
|
580
|
-
|
|
585
|
+
For common / simple use cases, some helpers functions are provided to write basic action effects and improve actions readability.
|
|
586
|
+
|
|
587
|
+
Example
|
|
581
588
|
|
|
582
589
|
```typescript
|
|
583
|
-
import {
|
|
590
|
+
import { setArgIn } from 'state-decorator/helpers';
|
|
584
591
|
|
|
585
592
|
type State = {
|
|
586
|
-
|
|
593
|
+
myProp: string;
|
|
587
594
|
};
|
|
588
595
|
|
|
589
596
|
type Actions = {
|
|
590
|
-
|
|
597
|
+
setMyProp: (v: string) => void;
|
|
591
598
|
};
|
|
592
599
|
|
|
593
|
-
|
|
594
|
-
|
|
600
|
+
const actions: StoreActions<State, Actions> = {
|
|
601
|
+
setMyProp: setArgIn('myProp'),
|
|
602
|
+
// same as
|
|
603
|
+
// setMyProp: ({ args: [v] }) => ({ myProp: v }),
|
|
595
604
|
};
|
|
605
|
+
```
|
|
596
606
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
607
|
+
| Name | Purpose | Action signature |
|
|
608
|
+
| ------------ | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
|
|
609
|
+
| setArgIn | Effect function to update a state property from action first argument | (v:T) => void |
|
|
610
|
+
| setTrueIn | Effect function to update a boolean state property to true | () => void |
|
|
611
|
+
| setFalseIn | Effect function to update a boolean state property to false | () => void |
|
|
612
|
+
| toggleProp | Effect function to toggle a boolean state property | () => void |
|
|
613
|
+
| setMapProp | Effect function to update a state property of type Record<string, T> using first action argument as key and second as value | (id: string, v:T) => void |
|
|
614
|
+
| setArrayItem | Effect function to update a state property of type T[] using first action argument as index and second as value | (index: number, v:T) => void |
|
|
615
|
+
| setResIn | Effect function of asynchronous action to update a state property with the result of the promise | () => Promise<T> |
|
|
600
616
|
|
|
601
|
-
|
|
602
|
-
() => ({ value: 0 }),
|
|
603
|
-
{
|
|
604
|
-
add1: ({ s }) => ({ ...s, value: s.value + 1 }),
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
derivedState: {
|
|
608
|
-
derivedProp: {
|
|
609
|
-
// get the list of dependencies to be checked to trigger the computation of the derived state
|
|
610
|
-
// if state.value AND/OR props.prop1 changes, derivedProp is recomputed
|
|
611
|
-
getDeps: ({ state, props }) => [state.value, props.propIn],
|
|
612
|
-
// compute derived state from state & props (use short aliases)
|
|
613
|
-
get: ({ s, p }) => s.value * p.propIn,
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
|
-
}
|
|
617
|
-
);
|
|
617
|
+
## Call actions on mount
|
|
618
618
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
619
|
+
When store is created (for example whe React component in mounted), the **onMount** option is called.
|
|
620
|
+
|
|
621
|
+
```typescript
|
|
622
|
+
import { createStore } from 'state-decorator';
|
|
623
|
+
|
|
624
|
+
const store = createStore(getInitialState, actionsImpl, {
|
|
625
|
+
onMount: ({ a }) => {
|
|
626
|
+
a.loadList();
|
|
627
|
+
},
|
|
628
|
+
});
|
|
624
629
|
```
|
|
625
630
|
|
|
626
|
-
|
|
631
|
+
After React component is mounted using _useLocalStore_, the **onMountDeferred** option is called (in a _useEffect_).
|
|
632
|
+
The **onMount** is called _during_ the render of the hooks. If the onMount code is containing a function that is changing parent state,
|
|
633
|
+
React will not update the parent state and will issue a warning.
|
|
627
634
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
- In general, do **not** compute derived values directly in state, it's error prone as you can forget some places or implement different logic.
|
|
631
|
-
- Use derived state especially if this state is shared accross several sub components
|
|
635
|
+
```typescript
|
|
636
|
+
import { createStore } from 'state-decorator';
|
|
632
637
|
|
|
633
|
-
|
|
638
|
+
const store = createStore(getInitialState, actionsImpl, {
|
|
639
|
+
onMountDeferred: ({ p }) => {
|
|
640
|
+
p.loadParentList();
|
|
641
|
+
},
|
|
642
|
+
});
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
If an initial action is launched each time a property changes, consider using the **onMount** flag of the **onPropsChange** entry.
|
|
634
646
|
|
|
635
|
-
|
|
647
|
+
## Call actions on store destruction / unmount
|
|
648
|
+
|
|
649
|
+
When the store is destroyed (for example on React component unmounted), the **onUnmount** option is called.
|
|
636
650
|
|
|
637
651
|
```typescript
|
|
638
652
|
import { createStore } from 'state-decorator';
|
|
639
653
|
|
|
640
|
-
// global store
|
|
641
654
|
const store = createStore(getInitialState, actionsImpl, {
|
|
642
|
-
|
|
643
|
-
|
|
655
|
+
onUnmount: ({ s, abortedActions }) => {
|
|
656
|
+
// ex: store s in local storage
|
|
657
|
+
// ex: clean cache of aborted actions
|
|
644
658
|
},
|
|
645
659
|
});
|
|
646
|
-
|
|
647
|
-
store.init(initialProps);
|
|
648
660
|
```
|
|
649
661
|
|
|
662
|
+
## State sharing and slices
|
|
663
|
+
|
|
664
|
+
- Declare a store and bind it to a component using _useStore_ or _useBindStore_ hooks.
|
|
665
|
+
- Deeper in the tree component, use _useStoreSlice_ to get a store slice.
|
|
666
|
+
- Component using slices will be refreshed only if their store slice changes.
|
|
667
|
+
|
|
650
668
|
```typescript
|
|
651
|
-
import
|
|
669
|
+
import React from 'react';
|
|
670
|
+
import { useStore, useStoreSlice, StoreActions } from 'state-decorator';
|
|
652
671
|
|
|
653
|
-
//
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
672
|
+
// Declare typings & actions as above
|
|
673
|
+
|
|
674
|
+
// Create a store
|
|
675
|
+
|
|
676
|
+
export const store = createStore(getInitialState, userAppActions);
|
|
677
|
+
|
|
678
|
+
// Bind to react component
|
|
679
|
+
|
|
680
|
+
export function Container(prop: Props) {
|
|
681
|
+
const { state, actions } = useStore(store, props);
|
|
682
|
+
|
|
683
|
+
// or
|
|
684
|
+
// useBindStore(store, props);
|
|
685
|
+
// if you are not interested in getting the state here
|
|
686
|
+
|
|
687
|
+
return <div />;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// Components deeper in the component tree will be refreshed if, and only if,
|
|
691
|
+
// slice is changed (here: text property)
|
|
692
|
+
|
|
693
|
+
export function SubComponent2() {
|
|
694
|
+
const s = useStoreSlice(store, ['text']);
|
|
695
|
+
return <div>{s.text}</div>;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export function SubComponent() {
|
|
699
|
+
const s = useStoreSlice(store, (s) => ({ text: s.text }));
|
|
700
|
+
return <div>{s.text}</div>;
|
|
660
701
|
}
|
|
661
702
|
```
|
|
662
703
|
|
|
663
|
-
|
|
704
|
+
[](https://codesandbox.io/s/slices-v6-eg471?file=/src/SliceView.tsx)
|
|
664
705
|
|
|
665
706
|
# Update store when props change
|
|
666
707
|
|
|
@@ -968,6 +1009,61 @@ function Subtitle(props: { subtitle: string }) {
|
|
|
968
1009
|
}
|
|
969
1010
|
```
|
|
970
1011
|
|
|
1012
|
+
# Derived state
|
|
1013
|
+
|
|
1014
|
+
A derived state is a state that can be deduced from state and props.
|
|
1015
|
+
|
|
1016
|
+
```typescript
|
|
1017
|
+
import { createStore } from 'state-decorator';
|
|
1018
|
+
|
|
1019
|
+
type State = {
|
|
1020
|
+
value: number;
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
type Actions = {
|
|
1024
|
+
add1: () => void;
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
type Props = {
|
|
1028
|
+
propIn: number;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
type DerivedState = {
|
|
1032
|
+
derivedProp: number;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
const store = createStore<State, Actions, Props, DerivedState>(
|
|
1036
|
+
() => ({ value: 0 }),
|
|
1037
|
+
{
|
|
1038
|
+
add1: ({ s }) => ({ ...s, value: s.value + 1 }),
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
derivedState: {
|
|
1042
|
+
derivedProp: {
|
|
1043
|
+
// get the list of dependencies to be checked to trigger the computation of the derived state
|
|
1044
|
+
// if state.value AND/OR props.prop1 changes, derivedProp is recomputed
|
|
1045
|
+
getDeps: ({ state, props }) => [state.value, props.propIn],
|
|
1046
|
+
// compute derived state from state & props (use short aliases)
|
|
1047
|
+
get: ({ s, p }) => s.value * p.propIn,
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
}
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
export function App(props: Props) {
|
|
1054
|
+
const { state } = useStore(store, props);
|
|
1055
|
+
// state contains the store state and derived state
|
|
1056
|
+
return <div>{state.derivedProp}</div>;
|
|
1057
|
+
}
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
## Recipes
|
|
1061
|
+
|
|
1062
|
+
- Derived state is the same as using _useMemo_ in sub component.
|
|
1063
|
+
- If the derived state is needed in one component only, it may prove better to use a _useMemo_ in this component to save memory when the component is unmounted and store not.
|
|
1064
|
+
- In general, do **not** compute derived values directly in state, it's error prone as you can forget some places or implement different logic.
|
|
1065
|
+
- Use derived state especially if this state is shared accross several sub components
|
|
1066
|
+
|
|
971
1067
|
# Global configuration
|
|
972
1068
|
|
|
973
1069
|
Overrides configuration to set properties that will be used by all stores.
|
|
@@ -1025,7 +1121,7 @@ Example:
|
|
|
1025
1121
|
|
|
1026
1122
|
```
|
|
1027
1123
|
[StateDecorator sample] loadList effects {list: Array(10), prop1: "", prop2: "", prop3: ""} loading: false
|
|
1028
|
-
|
|
1124
|
+
[StateDecorator sample] setProp1 effects {list: Array(10), prop1: "92", prop2: "", prop3: ""}
|
|
1029
1125
|
```
|
|
1030
1126
|
|
|
1031
1127
|
## Detailed Logger
|
package/es/helpers.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect function that sets the first action argument to the specified prop.
|
|
3
|
+
*/
|
|
4
|
+
export declare function setArgIn<S, K extends keyof S>(propName: K): (ctx: {
|
|
5
|
+
s: S;
|
|
6
|
+
args: [S[K]];
|
|
7
|
+
}) => Partial<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Effect function that sets <code>true</code> in the specified prop.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setTrueIn<S, K extends keyof S>(propName: K): (ctx: {
|
|
12
|
+
s: S;
|
|
13
|
+
}) => Partial<S>;
|
|
14
|
+
/**
|
|
15
|
+
* Effect function that sets <code>false</code> in the specified prop.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setFalseIn<S, K extends keyof S>(propName: K): (ctx: {
|
|
18
|
+
s: S;
|
|
19
|
+
}) => Partial<S>;
|
|
20
|
+
/**
|
|
21
|
+
* Effect function that sets toggles the boolean value of the specified prop.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toggleProp<S, K extends keyof S>(propName: K): (ctx: {
|
|
24
|
+
s: S;
|
|
25
|
+
}) => Partial<S>;
|
|
26
|
+
/**
|
|
27
|
+
* Effect function that sets the update the specifed prop as an array using first action argument as index
|
|
28
|
+
* and second as value to set.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setMapItem<S, K extends keyof S, T>(propName: K): (ctx: {
|
|
31
|
+
s: S;
|
|
32
|
+
args: [string, T];
|
|
33
|
+
}) => Partial<S>;
|
|
34
|
+
/**
|
|
35
|
+
* Effect function that sets the update the specifed prop as an array using first action argument as index
|
|
36
|
+
* and second as value to set.
|
|
37
|
+
*/
|
|
38
|
+
export declare function setArrayItem<S, K extends keyof S, T>(propName: K): (ctx: {
|
|
39
|
+
s: S;
|
|
40
|
+
args: [number, T];
|
|
41
|
+
}) => Partial<S>;
|
|
42
|
+
/**
|
|
43
|
+
* Effect function that sets the asynchronous action result to the specified prop.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setResIn<S, K extends keyof S>(propName: K): (ctx: {
|
|
46
|
+
s: S;
|
|
47
|
+
res: S[K];
|
|
48
|
+
}) => Partial<S>;
|
package/es/helpers.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=function(){return(n=Object.assign||function(n){for(var r,t=1,u=arguments.length;t<u;t++)for(var e in r=arguments[t])Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e]);return n}).apply(this,arguments)};function r(n){return function(r){var t,u=r.s,e=r.args[0];return u[n]===e?null:((t={})[n]=e,t)}}function t(n){return function(r){var t;return r.s[n]?null:((t={})[n]=!0,t)}}function u(n){return function(r){var t;return r.s[n]?((t={})[n]=!1,t):null}}function e(n){return function(r){var t,u=r.s;return(t={})[n]=!u[n],t}}function o(r){return function(t){var u,e,o=t.s,c=t.args,i=c[0],a=c[1];return(u={})[r]=n(n({},o[r]),((e={})[i]=a,e)),u}}function c(n){return function(r){var t,u=r.s,e=r.args,o=e[0],c=e[1],i=function(n,r,t){if(t||2===arguments.length)for(var u,e=0,o=r.length;e<o;e++)!u&&e in r||(u||(u=Array.prototype.slice.call(r,0,e)),u[e]=r[e]);return n.concat(u||Array.prototype.slice.call(r))}([],u[n],!0);return i[o]=c,(t={})[n]=i,t}}function i(n){return function(r){var t,u=r.res;return(t={})[n]=u,t}}export{r as setArgIn,c as setArrayItem,u as setFalseIn,o as setMapItem,i as setResIn,t as setTrueIn,e as toggleProp};
|
|
2
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["__assign","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","this","to","from","pack","ar","l","Array","slice","concat"],"mappings":"AA+BO,IAAIA,EAAW,WAQlB,OAPAA,EAAWC,OAAOC,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,IAE9E,OAAON,IAEKU,MAAMC,KAAMP,sgBA6HzB,SAAuBQ,EAAIC,EAAMC,GACpC,GAAIA,GAA6B,IAArBV,UAAUC,OAAc,IAAK,IAA4BU,EAAxBb,EAAI,EAAGc,EAAIH,EAAKR,OAAYH,EAAIc,EAAGd,KACxEa,GAAQb,KAAKW,IACRE,IAAIA,EAAKE,MAAMV,UAAUW,MAAMT,KAAKI,EAAM,EAAGX,IAClDa,EAAGb,GAAKW,EAAKX,IAGrB,OAAOU,EAAGO,OAAOJ,GAAME,MAAMV,UAAUW,MAAMT,KAAKI"}
|
package/es/impl.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
|
-
import { AsyncAction, SimpleSyncAction, SyncAction, StoreAction, AsyncActionPromise, AsyncActionPromiseGet, PromiseProvider, DecoratedActions, InternalLoadingMap, StoreOptions, InvocationContextActions, OnMountInvocationContext, OnPropsChangeEffectsContext, ContextState, Middleware, MiddlewareFactory, ContextWithDerived, PromiseIdErrorMap, ErrorMap, ErrorParallelMap } from './types';
|
|
15
|
+
import { AsyncAction, SimpleSyncAction, SyncAction, StoreAction, AsyncActionPromise, AsyncActionPromiseGet, PromiseProvider, DecoratedActions, InternalLoadingMap, StoreOptions, InvocationContextActions, OnMountInvocationContext, OnPropsChangeEffectsContext, ContextState, Middleware, MiddlewareFactory, ContextWithDerived, PromiseIdErrorMap, ErrorMap, ErrorParallelMap, OnUnMountInvocationContext, AbortedActions } from './types';
|
|
16
16
|
export declare type SetStateFunc<S, A> = (newState: S, newLoadingMap: InternalLoadingMap<A>, actionName: keyof A | 'onPropsChange', actionType: 'preEffects' | 'effects' | 'errorEffects' | null, // FIXME
|
|
17
17
|
isAsync: boolean, actionCtx: any, propsChanged: boolean, isInit?: boolean) => void;
|
|
18
18
|
/** @internal */
|
|
@@ -167,6 +167,8 @@ export declare function buildInvocationContextBase<S, DS, P>(stateRef: Ref<S>, d
|
|
|
167
167
|
/** @internal */
|
|
168
168
|
export declare function buildOnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, actionsRef: Ref<A>): OnMountInvocationContext<S, A, P>;
|
|
169
169
|
/** @internal */
|
|
170
|
+
export declare function buildOnUnMountInvocationContext<S, DS, A, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, abortedActions: AbortedActions<A>): OnUnMountInvocationContext<S, A, P>;
|
|
171
|
+
/** @internal */
|
|
170
172
|
export declare function buildOnPropChangeEffects<S, DS, P>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, indices: number[], index: number, isInit: boolean): OnPropsChangeEffectsContext<S, DS, P>;
|
|
171
173
|
/** @internal */
|
|
172
174
|
export declare function addStateToContext<T, S>(ctx: T, stateRef: Ref<S>): T & ContextState<S>;
|
|
@@ -186,7 +188,7 @@ export declare function areSameArgs(args1: any[], args2: any[]): boolean;
|
|
|
186
188
|
/** @internal */
|
|
187
189
|
export declare function computeDerivedValues<S, A, P, DS>(s: Ref<S>, p: Ref<P>, derivedStateRef: Ref<DerivedState<DS>>, options: StoreOptions<S, A, P, DS>): boolean;
|
|
188
190
|
/** @internal */
|
|
189
|
-
export declare function onPropChange<S, P, A, DS>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, oldProps: P, actionsRef: Ref<A>, options: StoreOptions<S, A, P, DS>, setState: SetStateFunc<S, A>, isInit: boolean): void;
|
|
191
|
+
export declare function onPropChange<S, P, A, DS>(stateRef: Ref<S>, derivedStateRef: Ref<DerivedState<DS>>, propsRef: Ref<P>, oldProps: P, actionsRef: Ref<A>, options: StoreOptions<S, A, P, DS>, setState: SetStateFunc<S, A>, isInit: boolean, isDeferred: boolean): void;
|
|
190
192
|
/** @internal */
|
|
191
193
|
export declare function runMiddlewares<S, A extends DecoratedActions, P>(middlewares: Middleware<S, A, P>[], oldState: S, newState: S, loading: boolean, actionName: keyof A, actionType: 'preEffects' | 'effects' | 'errorEffects' | null, isAsync: boolean, actionCtx: any): {
|
|
192
194
|
newState: S;
|
package/es/impl.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=function(r,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])})(r,n)};var r,n=function(){return(n=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function t(e,r,n,t){return new(n||(n=Promise))((function(o,i){function c(e){try{a(t.next(e))}catch(e){i(e)}}function u(e){try{a(t.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof n?r:new n((function(e){e(r)}))).then(c,u)}a((t=t.apply(e,r||[])).next())}))}function o(e,r){var n,t,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,t&&(o=2&i[0]?t.return:i[0]?t.throw||((o=t.return)&&o.call(t),0):t.next)&&!(o=o.call(t,i[1])).done)return o;switch(t=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,t=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],t=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,n){if(n||2===arguments.length)for(var t,o=0,i=r.length;o<i;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var n=Object.keys(e),t=Object.keys(r);if(n.length!==t.length)return!1;for(var o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(r,n[o])||!Object.is(e[n[o]],r[n[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))}function a(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function l(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))}function f(e){return"function"==typeof e}function s(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function d(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function v(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function p(e){return v(e)?n(n({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e}function g(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=!1,a)),u))}function y(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=void 0,a)),u))}var h=function(r){function n(e){var t=r.call(this,"Error")||this;return t.promiseIds=e,Object.setPrototypeOf(t,n.prototype),t}return function(r,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}(n,r),n}(Error);function E(e){return Object.keys(e).reduce((function(r,n){var t=e[n];if(null==t[K]);else if(t[K])r[n]=t[K];else{var o=Object.keys(t).reduce((function(e,r){return null!=t[r]&&(e.hasErr=!0,e.map[r]=t[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[n]=new h(o.map))}return r}),{})}function m(e,r,n,i){return void 0===r&&(r=1),void 0===n&&(n=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,l){return t(this,void 0,void 0,(function(){return o(this,(function(t){return null===l?[2,null]:[2,l.catch((function(t){return i(t)?a===r?Promise.reject(t):new Promise((function(r,t){setTimeout((function(){var n=e(c);u(a+1,n).then(r).catch(t)}),n*a)})):Promise.reject(t)}))]}))}))}(1,u)}}function P(e){return void 0===e&&(e=null),{current:e}}function w(e,r,n){var t,o;return{state:e.current,s:e.current,ds:null===(t=null==r?void 0:r.current)||void 0===t?void 0:t.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:n.current,p:n.current}}function S(e,r,n,t){return L(w(e,r,n),t)}function b(e,r,n,t,o,i){var c=w(e,r,n);return c.indices=t,c.index=o,c.isInit=i,c}function R(e,r,n,t,o){var i=w(e,r,n);return i.args=t,o&&(i.promiseId=o),i}function O(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.result=o,c.res=o,c}function A(e,r,n,t,o,i,c){var u=L(R(e,r,n,t,c),o);return u.abortSignal=i,u}function j(e,r){var n=e;return n.state=r.current,n.s=r.current,n}function L(e,r){var n=e;return n.actions=r.current,n.a=r.current,n}function C(e,r,n,t,o){var i,c=L(e,t);j(e,r);var u=null===(i=null==n?void 0:n.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function _(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function k(e,r){return null==r?null:n(n({},e.current),r)}function T(e,r,n,t,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var l=R(n,t,o,u),f=k(n,r(l));c(f,null,e,"effects",!1,l,!1)}else _(e)}}function M(e,r,n,t,o,i,c,u,a,l){var f,s=O(n,t,o,l,void 0),d=!1;if(null!=r.effects){var v=k(n,r.effects(s));null===v?d=!0:a(v,void 0,e,"effects",!1,s,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var p=c.current[e];p&&clearTimeout(p),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,C(s,n,t,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(f=r.sideEffects)||void 0===f||f.call(r,C(s,n,t,i,u.notifyWarning))}function x(e,r,n,t,o,i,c,u,a,l){return function(){for(var f=[],s=0;s<arguments.length;s++)f[s]=arguments[s];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],M(e,r,n,t,o,i,u,a,l,f)}),r.debounceTimeout)}else M(e,r,n,t,o,i,u,a,l,f);else _(e)}}function N(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,s=e.loadingMapRef,d=e.conflictActionsRef,v=e.actionName,p=e.options,y=e.setState;if(e.initializedRef.current){var h=null,E=O(i,u,a,t,n,r);o.effects&&(h=k(i,o.effects(E))),y(h,g(s.current,v,r,!1),v,"effects",!0,E,!1);var m=p.notifySuccess||c.notifySuccess;if(m){var P=void 0;o.getSuccessMessage&&(P=o.getSuccessMessage(E)),P&&m(P)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(C(E,i,u,f,c.notifyWarning)),z(v,f.current,d.current),n}}function I(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.loadingMapRef,s=e.errorMapRef,d=e.promisesRef,v=e.conflictActionsRef,p=e.actionName,h=e.options,E=e.setState;if(e.initializedRef.current){var m=null,P=function(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.error=o,c.err=o,c}(i,u,a,t,n,r);o.errorEffects&&(m=k(i,o.errorEffects(P))),s.current=y(s.current,p,r,n),E(m,g(f.current,p,r,!1),p,"errorEffects",!0,P,!1);var w=!1;(null!=m||o.errorSideEffects||o.isErrorManaged)&&(w=!0);var S=h.notifyError||c.notifyError;if(S){var b=void 0;o.getErrorMessage&&(b=o.getErrorMessage(P)),void 0===b&&!w&&c.getErrorMessage&&(b=c.getErrorMessage(n)),b&&(w=!0,S(b))}return c.asyncErrorHandler(n,w||o.rejectPromiseOnError,i.current,a.current,p,t),delete d.current[p][r],o.errorSideEffects&&o.errorSideEffects(C(P,i,u,l,c.notifyWarning)),z(p,l.current,v.current),!w||o.rejectPromiseOnError?Promise.reject(n):Promise.resolve()}}function D(e){var t=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.promisesRef,s=e.loadingMapRef,d=e.errorMapRef,v=e.initializedRef,p=e.conflictActionsRef,h=e.actionName,E=e.setState;return function(){for(var P,w,S,b=[],O=0;O<arguments.length;O++)b[O]=arguments[O];if(!v.current)return _(h),null;var j=f.current,L=t.conflictPolicy,C=void 0===L?r.KEEP_ALL:L,T=C===r.PARALLEL,M=null;if(T){if(!t.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");M=t.getPromiseId.apply(t,b)}else M=K;if(!T&&(null===(w=j[h])||void 0===w?void 0:w[M]))return U(j,p.current,h,C,b);var x=null,D=!1,G=R(o,u,a,b,M);t.preEffects&&(x=k(o,t.preEffects(G)))&&(D=!0,o.current=x);var W=t.abortable,z=t.retryCount,F=t.retryDelaySeed,J=t.isTriggerRetryError,H=W&&window.AbortController?new AbortController:null,V=m(t.getPromise,z?1+z:1,F,J||c.retryOnErrorFunction),q=null===(S=V(A(o,u,a,b,l,null==H?void 0:H.signal)))||void 0===S?void 0:S.then((function(r){return N(e,M,r,b)})).catch((function(r){return I(e,M,r,b)}));return null!=q&&(j[h]=n(n({},j[h]||{}),((P={})[M||K]={abortController:H,promise:q,refArgs:C===r.REUSE&&b.length>0?i([],b,!0):[]},P))),d.current=y(d.current,h,M,null),E(null!=q||D?o.current:void 0,null==q?void 0:g(s.current,h,M,!0),h,"preEffects",!0,G,!1),q}}function G(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return r.some((function(r){var n,t=null,o=K;Array.isArray(r)?(t=r[0],o=void 0===(n=r[1])?K:n):t=r;var i=e[t];return null!=i&&(null!=i[o]&&i[o])}))}var K="__def__";function W(e,r){return e.length===r.length&&-1===e.findIndex((function(e,n){return r[n]!==e}))}function U(e,n,t,o,i){var c=o;if(c===r.REUSE){if(W(e[t][K].refArgs,i))return e[t][K].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var u={resolve:e,reject:o,args:a(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(t," is already ongoing.")));break;case r.KEEP_LAST:n[t]=[u];break;case r.KEEP_ALL:var l=n[t];l||(n[t]=l=[]),l.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function z(e,r,n){var t=n[e];if(t&&t.length>0){var o=n[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?z(e,r,n):i.then((function(t){null===t&&z(e,r,n),o.resolve(t)})).catch((function(e){return o.reject(e)}))}}}function F(e,r,n,t){if(null==(null==t?void 0:t.derivedState))return!1;var o=!1,i=c.comparator,u=n.current.deps,a=w(e,null,r),l=Object.keys(t.derivedState);return n.current.state=l.reduce((function(e,r){var c=!1,l=u[r],f=t.derivedState[r].getDeps(a);return c=null==l||null!=f.find((function(e,r){return l.length<r||!i(l[r],e)})),o=o||c,u[r]=f,e[r]=c?t.derivedState[r].get(a):n.current.state[r],e}),{}),o}function J(e,r,t,o,i,u,a,l){var f=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var s;s=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=P(e.current),p=[],g=c.comparator;s.forEach((function(n,i){var c,u=n.getDeps;if(u){var f=!1,s=[];if(l){if(!n.onMount)return;f=!0}else{var y=u(o),h=u(t.current);y.length!==h.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),f=!0):y.forEach((function(e,r){g(e,h[r])||(f=!0,s.push(r))}))}if(f){var E=b(v,r,t,s,i,l),m=k(e,null===(c=n.effects)||void 0===c?void 0:c.call(n,E));null!=m&&(d=!0,v.current=m,a(v.current,void 0,"onPropsChange","effects",!1,E,!0,l)),n.sideEffects&&p.push({index:i,indices:s,ctx:E})}}})),!d&&f&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(e){s[e.index].sideEffects(n(n({},j(L(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function H(e,r,n,t,o,i,c,u){if("onPropsChange"===o&&void 0===n)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var n=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,t);return{newState:(null==n?void 0:n.state)||e.newState,oldState:(null==n?void 0:n.state)?e.newState:e.oldState,loading:null==(null==n?void 0:n.loading)?e.loading:n.loading}}),{oldState:r,newState:n,loading:t});return{newLoading:a.loading,newState:a.newState}}return{newState:n,newLoading:t}}export{K as DEFAULT_PROMISE_ID,h as ParallelActionError,L as addContextActions,j as addStateToContext,W as areSameArgs,E as buildErrorMap,w as buildInvocationContextBase,g as buildLoadingMap,S as buildOnMountInvocationContext,b as buildOnPropChangeEffects,p as computeAsyncActionInput,F as computeDerivedValues,P as createRef,D as decorateAsyncAction,T as decorateSimpleSyncAction,x as decorateSyncAction,c as globalConfig,l as isAsyncAction,d as isAsyncGetPromiseAction,v as isAsyncGetPromiseGetAction,G as isLoadingImpl,f as isSimpleSyncAction,s as isSyncAction,J as onPropChange,m as retryPromiseDecorator,H as runMiddlewares,u as setGlobalConfig,y as updateErrorMap};
|
|
1
|
+
var e=function(r,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])})(r,n)};var r,n=function(){return(n=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function t(e,r,n,t){return new(n||(n=Promise))((function(o,i){function c(e){try{a(t.next(e))}catch(e){i(e)}}function u(e){try{a(t.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof n?r:new n((function(e){e(r)}))).then(c,u)}a((t=t.apply(e,r||[])).next())}))}function o(e,r){var n,t,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,t&&(o=2&i[0]?t.return:i[0]?t.throw||((o=t.return)&&o.call(t),0):t.next)&&!(o=o.call(t,i[1])).done)return o;switch(t=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,t=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],t=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,n){if(n||2===arguments.length)for(var t,o=0,i=r.length;o<i;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var n=Object.keys(e),t=Object.keys(r);if(n.length!==t.length)return!1;for(var o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(r,n[o])||!Object.is(e[n[o]],r[n[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))}function a(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function l(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))}function f(e){return"function"==typeof e}function s(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function d(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function v(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function p(e){return v(e)?n(n({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e}function g(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=!1,a)),u))}function y(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=void 0,a)),u))}var h=function(r){function n(e){var t=r.call(this,"Error")||this;return t.promiseIds=e,Object.setPrototypeOf(t,n.prototype),t}return function(r,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}(n,r),n}(Error);function E(e){return Object.keys(e).reduce((function(r,n){var t=e[n];if(null==t[W]);else if(t[W])r[n]=t[W];else{var o=Object.keys(t).reduce((function(e,r){return null!=t[r]&&(e.hasErr=!0,e.map[r]=t[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[n]=new h(o.map))}return r}),{})}function m(e,r,n,i){return void 0===r&&(r=1),void 0===n&&(n=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,l){return t(this,void 0,void 0,(function(){return o(this,(function(t){return null===l?[2,null]:[2,l.catch((function(t){return i(t)?a===r?Promise.reject(t):new Promise((function(r,t){setTimeout((function(){var n=e(c);u(a+1,n).then(r).catch(t)}),n*a)})):Promise.reject(t)}))]}))}))}(1,u)}}function P(e){return void 0===e&&(e=null),{current:e}}function w(e,r,n){var t,o;return{state:e.current,s:e.current,ds:null===(t=null==r?void 0:r.current)||void 0===t?void 0:t.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:n.current,p:n.current}}function S(e,r,n,t){return C(w(e,r,n),t)}function b(e,r,t,o){return n(n({},w(e,r,t)),{abortedActions:o})}function R(e,r,n,t,o,i){var c=w(e,r,n);return c.indices=t,c.index=o,c.isInit=i,c}function O(e,r,n,t,o){var i=w(e,r,n);return i.args=t,o&&(i.promiseId=o),i}function A(e,r,n,t,o,i){var c=O(e,r,n,t,i);return c.result=o,c.res=o,c}function j(e,r,n,t,o,i,c){var u=C(O(e,r,n,t,c),o);return u.abortSignal=i,u}function L(e,r){var n=e;return n.state=r.current,n.s=r.current,n}function C(e,r){var n=e;return n.actions=r.current,n.a=r.current,n}function _(e,r,n,t,o){var i,c=C(e,t);L(e,r);var u=null===(i=null==n?void 0:n.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function k(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e.toString()," action was called while store is not initialized or destroyed, this is probably a leak"))}function M(e,r){return null==r?null:n(n({},e.current),r)}function T(e,r,n,t,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var l=O(n,t,o,u),f=M(n,r(l));c(f,null,e,"effects",!1,l,!1)}else k(e)}}function x(e,r,n,t,o,i,c,u,a,l){var f,s=A(n,t,o,l,void 0),d=!1;if(null!=r.effects){var v=M(n,r.effects(s));null===v?d=!0:a(v,void 0,e,"effects",!1,s,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var p=c.current[e];p&&clearTimeout(p),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,_(s,n,t,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(f=r.sideEffects)||void 0===f||f.call(r,_(s,n,t,i,u.notifyWarning))}function N(e,r,n,t,o,i,c,u,a,l){return function(){for(var f=[],s=0;s<arguments.length;s++)f[s]=arguments[s];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],x(e,r,n,t,o,i,u,a,l,f)}),r.debounceTimeout)}else x(e,r,n,t,o,i,u,a,l,f);else k(e)}}function D(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,s=e.loadingMapRef,d=e.conflictActionsRef,v=e.actionName,p=e.options,y=e.setState;if(e.initializedRef.current){var h=null,E=A(i,u,a,t,n,r);o.effects&&(h=M(i,o.effects(E))),y(h,g(s.current,v,r,!1),v,"effects",!0,E,!1);var m=p.notifySuccess||c.notifySuccess;if(m){var P=void 0;o.getSuccessMessage&&(P=o.getSuccessMessage(E)),P&&m(P)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(_(E,i,u,f,c.notifyWarning)),F(v,f.current,d.current),n}}function I(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.loadingMapRef,s=e.errorMapRef,d=e.promisesRef,v=e.conflictActionsRef,p=e.actionName,h=e.options,E=e.setState;if(e.initializedRef.current){var m=null,P=function(e,r,n,t,o,i){var c=O(e,r,n,t,i);return c.error=o,c.err=o,c}(i,u,a,t,n,r);o.errorEffects&&(m=M(i,o.errorEffects(P))),s.current=y(s.current,p,r,n),E(m,g(f.current,p,r,!1),p,"errorEffects",!0,P,!1);var w=!1;(null!=m||o.errorSideEffects||o.isErrorManaged||h.isErrorManaged)&&(w=!0);var S=h.notifyError||c.notifyError;if(S){var b=void 0;o.getErrorMessage&&(b=o.getErrorMessage(P)),void 0===b&&!w&&c.getErrorMessage&&(b=c.getErrorMessage(n)),b&&(w=!0,S(b))}return c.asyncErrorHandler(n,w||o.rejectPromiseOnError,i.current,a.current,p,t),delete d.current[p][r],o.errorSideEffects&&o.errorSideEffects(_(P,i,u,l,c.notifyWarning)),F(p,l.current,v.current),!w||o.rejectPromiseOnError?Promise.reject(n):Promise.resolve()}}function G(e){var t=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.promisesRef,s=e.loadingMapRef,d=e.errorMapRef,v=e.initializedRef,p=e.conflictActionsRef,h=e.actionName,E=e.setState;return function(){for(var P,w,S,b=[],R=0;R<arguments.length;R++)b[R]=arguments[R];if(!v.current)return k(h),null;var A=f.current,L=t.conflictPolicy,C=void 0===L?r.KEEP_ALL:L,_=C===r.PARALLEL,T=null;if(_){if(!t.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");T=t.getPromiseId.apply(t,b)}else T=W;if(!_&&(null===(w=A[h])||void 0===w?void 0:w[T]))return z(A,p.current,h,C,b);var x=null,N=!1,G=O(o,u,a,b,T);t.preEffects&&(x=M(o,t.preEffects(G)))&&(N=!0,o.current=x);var K=t.abortable,U=t.retryCount,F=t.retryDelaySeed,J=t.isTriggerRetryError,H=K&&window.AbortController?new AbortController:null,V=m(t.getPromise,U?1+U:1,F,J||c.retryOnErrorFunction),q=null===(S=V(j(o,u,a,b,l,null==H?void 0:H.signal)))||void 0===S?void 0:S.then((function(r){return D(e,T,r,b)})).catch((function(r){return I(e,T,r,b)}));return null!=q&&(A[h]=n(n({},A[h]||{}),((P={})[T||W]={abortController:H,promise:q,refArgs:C===r.REUSE&&b.length>0?i([],b,!0):[]},P))),d.current=y(d.current,h,T,null),E(null!=q||N?o.current:void 0,null==q?void 0:g(s.current,h,T,!0),h,"preEffects",!0,G,!1),q}}function K(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return r.some((function(r){var n,t=null,o=W;Array.isArray(r)?(t=r[0],o=void 0===(n=r[1])?W:n):t=r;var i=e[t];return null!=i&&(null!=i[o]&&i[o])}))}var W="__def__";function U(e,r){return e.length===r.length&&-1===e.findIndex((function(e,n){return r[n]!==e}))}function z(e,n,t,o,i){var c=o;if(c===r.REUSE){if(U(e[t][W].refArgs,i))return e[t][W].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var u={resolve:e,reject:o,args:a(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(t.toString()," is already ongoing.")));break;case r.KEEP_LAST:n[t]=[u];break;case r.KEEP_ALL:var l=n[t];l||(n[t]=l=[]),l.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function F(e,r,n){var t=n[e];if(t&&t.length>0){var o=n[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?F(e,r,n):i.then((function(t){null===t&&F(e,r,n),o.resolve(t)})).catch((function(e){return o.reject(e)}))}}}function J(e,r,n,t){if(null==(null==t?void 0:t.derivedState))return!1;var o=!1,i=c.comparator,u=n.current.deps,a=w(e,null,r),l=Object.keys(t.derivedState);return n.current.state=l.reduce((function(e,r){var c=!1,l=u[r],f=t.derivedState[r].getDeps(a);return c=null==l||null!=f.find((function(e,r){return l.length<r||!i(l[r],e)})),o=o||c,u[r]=f,e[r]=c?t.derivedState[r].get(a):n.current.state[r],e}),{}),o}function H(e,r,t,o,i,u,a,l,f){var s=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var d;d=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var v=!1,p=P(e.current),g=[],y=c.comparator;d.forEach((function(n,i){var c,u=n.getDeps;if(u){var s=!1,d=[];if(l){if(!(!f&&n.onMount||f&&n.onMountDeferred))return;s=!0}else{var h=u(o),E=u(t.current);h.length!==E.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),s=!0):h.forEach((function(e,r){y(e,E[r])||(s=!0,d.push(r))}))}if(s){var m=R(p,r,t,d,i,l),P=M(e,null===(c=n.effects)||void 0===c?void 0:c.call(n,m));null!=P&&(v=!0,p.current=P,a(p.current,void 0,"onPropsChange","effects",!1,m,!0,l)),n.sideEffects&&g.push({index:i,indices:d,ctx:m})}}})),!v&&s&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),g.length>0&&g.forEach((function(e){d[e.index].sideEffects(n(n({},L(C(e.ctx,i),p)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function V(e,r,n,t,o,i,c,u){if("onPropsChange"===o&&void 0===n)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var n=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,t);return{newState:(null==n?void 0:n.state)||e.newState,oldState:(null==n?void 0:n.state)?e.newState:e.oldState,loading:null==(null==n?void 0:n.loading)?e.loading:n.loading}}),{oldState:r,newState:n,loading:t});return{newLoading:a.loading,newState:a.newState}}return{newState:n,newLoading:t}}export{W as DEFAULT_PROMISE_ID,h as ParallelActionError,C as addContextActions,L as addStateToContext,U as areSameArgs,E as buildErrorMap,w as buildInvocationContextBase,g as buildLoadingMap,S as buildOnMountInvocationContext,R as buildOnPropChangeEffects,b as buildOnUnMountInvocationContext,p as computeAsyncActionInput,J as computeDerivedValues,P as createRef,G as decorateAsyncAction,T as decorateSimpleSyncAction,N as decorateSyncAction,c as globalConfig,l as isAsyncAction,d as isAsyncGetPromiseAction,v as isAsyncGetPromiseGetAction,K as isLoadingImpl,f as isSimpleSyncAction,s as isSyncAction,H as onPropChange,m as retryPromiseDecorator,V as runMiddlewares,u as setGlobalConfig,y as updateErrorMap};
|
|
2
2
|
//# sourceMappingURL=impl.js.map
|
package/es/index.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
import { Context } from 'react';
|
|
16
16
|
import { setGlobalConfig, GlobalConfig, ParallelActionError } from './impl';
|
|
17
|
-
import { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, ConflictPolicy, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps } from './types';
|
|
18
|
-
export { DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, ParallelActionError, StoreOptions, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, ConflictPolicy, GlobalConfig, Middleware, setGlobalConfig, LoadingProps, AbortActionCallback, };
|
|
17
|
+
import { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, ConflictPolicy, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps, ErrorProps, LoadingMapProps } from './types';
|
|
18
|
+
export { DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, ParallelActionError, StoreOptions, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, ConflictPolicy, GlobalConfig, Middleware, setGlobalConfig, LoadingProps, AbortActionCallback, ErrorProps, LoadingMapProps, };
|
|
19
19
|
export declare type IsLoadingFunc<A> = (...props: (keyof A | [keyof A, string])[]) => boolean;
|
|
20
20
|
declare type StateListenerUnregister = () => void;
|
|
21
21
|
export declare type StoreApi<S, A extends DecoratedActions, P, DS = {}> = {
|
|
@@ -76,6 +76,11 @@ export declare type StoreApi<S, A extends DecoratedActions, P, DS = {}> = {
|
|
|
76
76
|
options: StoreOptions<S, A, P, DS>;
|
|
77
77
|
actions: StoreActions<S, A, P, DS>;
|
|
78
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Invoke onMountDeferred + onPropChange flagged onMountDeferred
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
invokeOnMountDeferred: () => void;
|
|
79
84
|
};
|
|
80
85
|
export declare type StateListenerContext<S, DS, A extends DecoratedActions> = S & DS & A & Pick<StoreApi<S, A, any, DS>, 'loading' | 'loadingMap' | 'errorMap' | 'isLoading' | 'abortAction'>;
|
|
81
86
|
export declare type StateListener<S, DS, A extends DecoratedActions> = (ctx: StateListenerContext<S, DS, A>) => void;
|
package/es/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useReducer as r,useMemo as n,useRef as t,useLayoutEffect as e,useContext as u,useEffect as c}from"react";import{createRef as o,isSimpleSyncAction as i,decorateSimpleSyncAction as l,isAsyncAction as a,decorateAsyncAction as f,computeAsyncActionInput as d,isSyncAction as s,decorateSyncAction as v,globalConfig as p,onPropChange as g,DEFAULT_PROMISE_ID as y,computeDerivedValues as b,buildOnMountInvocationContext as h,isLoadingImpl as
|
|
1
|
+
import{useReducer as r,useMemo as n,useRef as t,useLayoutEffect as e,useContext as u,useEffect as c}from"react";import{createRef as o,isSimpleSyncAction as i,decorateSimpleSyncAction as l,isAsyncAction as a,decorateAsyncAction as f,computeAsyncActionInput as d,isSyncAction as s,decorateSyncAction as v,globalConfig as p,onPropChange as g,DEFAULT_PROMISE_ID as y,computeDerivedValues as b,buildOnMountInvocationContext as M,buildOnUnMountInvocationContext as h,isLoadingImpl as O,runMiddlewares as k,buildLoadingMap as E,buildErrorMap as j}from"./impl";export{ParallelActionError,setGlobalConfig}from"./impl";var L,m=function(){return(m=Object.assign||function(r){for(var n,t=1,e=arguments.length;t<e;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r}).apply(this,arguments)};function A(r,n,t){if(t||2===arguments.length)for(var e,u=0,c=n.length;u<c;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return r.concat(e||Array.prototype.slice.call(n))}function R(r,n,t,e){void 0===t&&(t={}),void 0===e&&(e=null);var u=o(),c=o(),L=o(),R=o(),S=o(),P=o(),w=o(),C=o(),D=o(),I=o(!1),x=o([]),T={},G=0;function K(r,n){var t=m(m({},r),n),e=m(m(m({},t),R.current),{isLoading:F,abortAction:J,loading:q(),loadingMap:B(),errorMap:H()});Object.keys(T).forEach((function(r){T[r](e)}))}function N(r){u.current=r,b(u,L,c,t),K(u.current,c.current.state)}function U(o){var i;if(!I.current){L.current=o,I.current=!0,u.current=r(o);var l=new Set(null==t?void 0:t.initialActionsMarkedLoading);P.current=Object.keys(n).reduce((function(r,n){var t;return r[n]=l.has(n)?((t={})[y]=!0,t):{},r}),{}),w.current=Object.keys(n).reduce((function(r,n){return r[n]={},r}),{}),S.current={},C.current={},D.current={},c.current={state:null,deps:{}},x.current=[];var a={options:t,get state(){return u.current},actions:n,setState:N},f=function(r){var n,t=r();x.current.push(t),null===(n=t.init)||void 0===n||n.call(t,a)};null===(i=p.defaultMiddlewares)||void 0===i||i.forEach(f),null==e||e.forEach(f),b(u,L,c,t),g(u,c,L,null,R,t,_,!0,!1),(null==t?void 0:t.onMount)&&t.onMount(M(u,c,L,R)),K(u.current,c.current.state)}}function _(r,n,e,o,i,l,a,f){void 0===a&&(a=!1),void 0===f&&(f=!1);var d=!1;if(I.current){var s=n,v=!!i&&O(s||P.current,[e,null==l?void 0:l.promiseId]),p=k(x.current,u.current,r,v,e,o,i,l),g=p.newState,M=p.newLoading;if(null!=g&&(d=!0,u.current=g),v!==M&&(s=E(s,e,(null==l?void 0:l.promiseId)||y,M),0===Object.keys(s).length&&(s=void 0)),null!=s&&(d=!0,P.current=s),d)b(u,L,c,t),f||K(g||u.current,c.current.state);else if(a){b(u,L,c,t)&&!f&&K(g||u.current,c.current.state)}}}var z=Object.keys(n);function F(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return O.apply(void 0,A([P.current],r,!1))}function J(r,n){var t,e;void 0===n&&(n=y);var u=null===(e=null===(t=C.current[r])||void 0===t?void 0:t[n])||void 0===e?void 0:e.abortController,c=!1;return u&&(u.abort(),c=!0),c}function q(){if(I.current){var r=P.current;return null!=Object.keys(r).find((function(n){var t=r[n];return Object.keys(t).find((function(r){return!!t[r]}))}))}return null}function B(){if(I.current){var r=P.current;return Object.keys(r).reduce((function(n,t){var e=r[t];return n[t]=null!=Object.keys(e).find((function(r){return!!e[r]})),n}),{})}return null}function H(){return I.current?j(w.current):null}return R.current=z.reduce((function(r,e){var o=n[e];return i(o)?r[e]=l(e,o,u,c,L,I,_):a(o)?r[e]=f({actionName:e,stateRef:u,derivedStateRef:c,propsRef:L,loadingMapRef:P,errorMapRef:w,actionsRef:R,promisesRef:C,conflictActionsRef:D,initializedRef:I,options:t,setState:_,action:d(o)}):s(o)&&(r[e]=v(e,o,u,c,L,R,I,S,t,_)),r}),{}),{getConfig:function(){return{getInitialState:r,options:t,actions:n}},setProps:function(r){var n=L.current;L.current=r,I.current?g(u,c,L,n,R,t,_,!1,!1):U(r)},addStateListener:function(r){var n="".concat(G++);return T[n]=r,function(){delete T[n]}},init:U,destroy:function(){var r;if(I.current){var e=Object.keys(n).reduce((function(r,t){var e=n[t];if(a(e)&&e.abortable){var u=P.current[t],c=Object.keys(u).reduce((function(r,n){return u[n]&&(J(t,n),r.push(n)),r}),[]);c.length>0&&(r[t]=c)}return r}),{});null===(r=null==t?void 0:t.onUnmount)||void 0===r||r.call(t,h(u,c,L,e)),L.current=null,u.current=null,P.current=null,w.current=null,C.current=null,D.current=null,c.current=null,Object.keys(S.current).forEach((function(r){clearTimeout(S.current[r])})),S.current=null,T={},I.current=!1,x.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),x.current=[]}},isLoading:F,abortAction:J,get actions(){return R.current},get state(){return I.current?m(m({},u.current),c.current.state):null},get loading(){return q()},get loadingMap(){return B()},get errorMap(){return H()},get loadingParallelMap(){return I.current?P.current:null},get errorParallelMap(){return I.current?w.current:null},invokeOnMountDeferred:function(){g(u,c,L,null,R,t,_,!0,!0),(null==t?void 0:t.onMountDeferred)&&t.onMountDeferred(M(u,c,L,R))}}}function S(u,c,o){var i=r((function(r){return r>100?0:r+1}),0)[1],l=n((function(){return c instanceof Function?c:function(r){return D(r,c)}}),[c]),a=n((function(){return function(r){return null!=o&&o.length>0?D(r.loadingMap,o):null}}),[o]),f=t(null),d=t(null);if(null===f.current){var s=m(m(m({},u.state),u.actions),D(u,["actions","loading","isLoading","abortAction","loadingMap","errorMap"]));f.current=l(s),d.current=a(s)}e((function(){return u.addStateListener((function(r){var n,t=l(r),e=a(r),u=f.current,c=p.comparator;n=null==u||!c(t,u)||!c(e,d.current),f.current=t,d.current=e,n&&i()}))}),[]);var v=f.current,g=d.current;return null==g?v:m(m({},v),{loadingMap:g})}function P(r,n,t){return S(u(r),n,t)}function w(n,u,c){void 0===u&&(u=null),void 0===c&&(c=!0);var o=r((function(r){return r>100?0:r+1}),0)[1],i=t(n);return n.setProps(u),e((function(){c&&i.current.addStateListener((function(){o()}))}),[c]),n}function C(r,n,e,u,o,i){void 0===i&&(i=!0);var l=t();return null==l.current&&(l.current=R(r,n,u,o)),c((function(){return l.current.invokeOnMountDeferred(),function(){var r;null===(r=l.current)||void 0===r||r.destroy()}}),[]),w(l.current,e,i)}function D(r,n){return n.reduce((function(n,t){return r.hasOwnProperty(t)&&(n[t]=r[t]),n}),{})}function I(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return D(n,r)}}!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse"}(L||(L={}));export default C;export{L as ConflictPolicy,R as createStore,D as pick,I as slice,C as useLocalStore,w as useStore,P as useStoreContextSlice,S as useStoreSlice};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["__assign","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","this","__spreadArray","to","from","pack","ar","l","Array","slice","concat"],"mappings":"4jBA+BO,MAAIA,EAAW,WAQlB,OAPAA,EAAWC,OAAOC,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,IAE9E,OAAON,IAEKU,MAAMC,KAAMP,YA6HzB,SAASQ,EAAcC,EAAIC,EAAMC,GACpC,GAAIA,GAA6B,IAArBX,UAAUC,OAAc,IAAK,IAA4BW,EAAxBd,EAAI,EAAGe,EAAIH,EAAKT,OAAYH,EAAIe,EAAGf,KACxEc,GAAQd,KAAKY,IACRE,IAAIA,EAAKE,MAAMX,UAAUY,MAAMV,KAAKK,EAAM,EAAGZ,IAClDc,EAAGd,GAAKY,EAAKZ,IAGrB,OAAOW,EAAGO,OAAOJ,GAAME,MAAMX,UAAUY,MAAMV,KAAKK"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["__assign","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","this","__spreadArray","to","from","pack","ar","l","Array","slice","concat"],"mappings":"imBA+BO,MAAIA,EAAW,WAQlB,OAPAA,EAAWC,OAAOC,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,IAE9E,OAAON,IAEKU,MAAMC,KAAMP,YA6HzB,SAASQ,EAAcC,EAAIC,EAAMC,GACpC,GAAIA,GAA6B,IAArBX,UAAUC,OAAc,IAAK,IAA4BW,EAAxBd,EAAI,EAAGe,EAAIH,EAAKT,OAAYH,EAAIe,EAAGf,KACxEc,GAAQd,KAAKY,IACRE,IAAIA,EAAKE,MAAMX,UAAUY,MAAMV,KAAKK,EAAM,EAAGZ,IAClDc,EAAGd,GAAKY,EAAKZ,IAGrB,OAAOW,EAAGO,OAAOJ,GAAME,MAAMX,UAAUY,MAAMV,KAAKK"}
|