state-decorator 6.6.1 → 6.7.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 CHANGED
@@ -76,19 +76,19 @@ type Props = {
76
76
  // Initial state & actions
77
77
 
78
78
  export const getInitialState = (): State => ({
79
- selectedUser: null,
79
+ selectedUserId: null,
80
80
  user: null,
81
81
  });
82
82
 
83
83
  export const userAppActions: StoreActions<State, Actions, Props> = {
84
84
  // synchronous action (simple form)
85
- selectUser: ({ state, args: [id] }) => ({ ...state, selectedUser: id }),
85
+ selectUser: ({ state, args: [id] }) => ({ ...state, selectedUserId: id }),
86
86
 
87
87
  // a synchronous action with side effects
88
88
  selectAndLoadUser: {
89
89
  // same as simple form, using aliases (use short context alias 's' instead of 'state')
90
90
  // effects contain only immutable state changes
91
- effects: ({ s, args: [id] }) => ({ ...s, selectedUser: id }),
91
+ effects: ({ s, args: [id] }) => ({ ...s, selectedUserId: id }),
92
92
  // side effects (ie. other effects than state changes), using "actions" alias
93
93
  sideEffects: ({ a }) => {
94
94
  a.loadUser();
@@ -571,7 +571,7 @@ setGlobalConfig({
571
571
  notifyError: undefined,
572
572
  // Notification function injected in side effects action context (success and error) to notify warning
573
573
  notifyWarning: undefined,
574
- // Function called to return common error message if error message is not provided or error not managed in action
574
+ // Function called to return common error message if error message is not provided or error not managed in action. To override locally in action, provide a function that returns _null_.
575
575
  getErrorMessage: undefined,
576
576
  });
577
577
  ```
@@ -812,81 +812,200 @@ function Container(props: Props) {
812
812
  # Unit testing
813
813
 
814
814
  - The state decorator provides a testing framework for stores.
815
- - The base principle is that a mock store is immutable. A new store is created is setting state/props. It allows to share mock store across tests.
816
- - On each test, reuse/setup store or store action and:
817
- - call the action and test state, side effect calls,...
818
- - calls have no effects on mock store
819
- - test prop changes
815
+ - The base principle is that a mock store is immutable:
816
+ - a new store is created each time state or props are set.
817
+ - it allows to share mock store across tests.
818
+ - The API is chainable: functions are returning a mock store, excepting test functions.
819
+ - On a mock store, we can test the store internals after initialiation, after inbound props have changed, after actions are called.
820
820
 
821
821
  ## Getting started
822
822
 
823
+ 1. Create and setup a mock store (_createMockFromStore_)
824
+ 2. Test store after initialization (_onInit_)
825
+ 3. Test store after props changes (_onPropsChange_)
826
+ 4. Test each action:
827
+ 1. Get mock store action (_getAction_)
828
+ 2. setup store state/prop (_setPartialState_, _setPartialProps_)
829
+ 3. if action is asynchronous, you can mock promise (_promiseResolves_, _promiseRejects_)
830
+ 4. call action with params (_call_)
831
+ 5. await response to test state/actions called...
832
+
833
+ ## Example
834
+
835
+ The store definition is available at [TodoStore.ts](https://github.com/GlobalSport/state-decorator/blob/develop/tests/fixtures/TodoStore.ts).
836
+
837
+ The test is available at [Todo.test.ts](https://github.com/GlobalSport/state-decorator/blob/develop/tests/Todo.test.ts).
838
+
823
839
  ```typescript
824
840
  import { createMockFromStore } from 'state-decorator/test';
825
841
 
826
- import { todoStore, TodoItem } from './Todos';
842
+ import todoStore from './fixtures/TodoStore';
827
843
 
828
844
  describe('Todo', () => {
829
845
  // create a mock store and setup initial state
830
- // state / props can be set in full form or partial form
831
846
  // this store can be shared accross tests because it is immutable
832
- const store = createMockFromStore(todoStore, {}).setPartialState({
833
- idCount: 3,
834
- todoIds: ['id', 'id2'],
835
- todoMap: {
836
- id: {
837
- id: 'id',
838
- completed: true,
839
- title: 'todo',
840
- },
841
- id2: {
842
- id: 'id2',
843
- completed: false,
844
- title: 'todo 2',
847
+ const store = createMockFromStore(todoStore)
848
+ // or
849
+ // const store = createMockStore(getInitialState, actions, props, options)
850
+ // initial state / props can be set in full form or partial form
851
+ .setPartialState({
852
+ idCount: 3,
853
+ todoIds: ['id', 'id2'],
854
+ todoMap: {
855
+ id: {
856
+ id: 'id',
857
+ completed: true,
858
+ title: 'todo',
859
+ },
860
+ id2: {
861
+ id: 'id2',
862
+ completed: false,
863
+ title: 'todo 2',
864
+ },
845
865
  },
846
- },
866
+ });
867
+
868
+ describe('Initialization', () => {
869
+ it('if not initial todo => load list', () => {
870
+ store
871
+ .setPartialState({
872
+ todoIds: [],
873
+ todoMap: {},
874
+ })
875
+ .onInit({ initialTodos: null })
876
+ .test(({ state, actions }) => {
877
+ // test state after initialization, ie:
878
+ // - options.onPropsChange with onMount: true
879
+ // - options.onMount
880
+ expect(state.todoIds).toEqual([]);
881
+ expect(state.todoMap).toEqual({});
882
+
883
+ // test derived state
884
+ expect(state.todos).toEqual([]);
885
+
886
+ // test side effects also
887
+ expect(actions.loadRemoteList).toHaveBeenCalled();
888
+ });
889
+ });
890
+
891
+ it('initial todos => setup state and do not load list', () => {
892
+ store
893
+ .setPartialState({
894
+ todoIds: [],
895
+ todoMap: {},
896
+ })
897
+ .onInit({
898
+ initialTodos: [
899
+ {
900
+ id: 'item1',
901
+ title: 'Item 1',
902
+ completed: false,
903
+ },
904
+ ],
905
+ })
906
+ .test(({ state, actions }) => {
907
+ // test state after initialization, ie:
908
+ // - options.onPropsChange with onMount: true
909
+ // - options.onMount
910
+ expect(state.todoIds).toEqual(['item1']);
911
+ expect(state.todoMap).toEqual({
912
+ item1: {
913
+ id: 'item1',
914
+ title: 'Item 1',
915
+ completed: false,
916
+ },
917
+ });
918
+
919
+ // test derived state
920
+ expect(state.todos).toEqual([
921
+ {
922
+ id: 'item1',
923
+ title: 'Item 1',
924
+ completed: false,
925
+ },
926
+ ]);
927
+
928
+ // test side effects also
929
+ expect(actions.loadRemoteList).not.toHaveBeenCalled();
930
+ });
931
+ });
847
932
  });
848
933
 
849
- it('onCreate', async () => {
850
- await store
851
- // set partial state and return new store, source store is untouched
852
- .setPartialState({
853
- newTitle: 'new todo',
854
- })
855
- // get a mock action that can be shared too !
856
- .getAction('onCreate')
857
- // Invokes action. It has no side effect on state of mock action
858
- .call()
859
- // always return a promise whatever if the action is asynchronous or not
860
- .then(({ state: { todoIds, todoMap } }) => {
861
- // assert state
862
- expect(todoIds).toEqual(['id', 'id2', 'id3']);
863
- expect(todoMap).toEqual({
864
- id: {
865
- id: 'id',
866
- completed: true,
867
- title: 'todo',
868
- },
869
- id2: {
870
- id: 'id2',
934
+ // Test effects and side effect when props are changing
935
+ //
936
+ // Here:
937
+ // export const todoOptions: StoreOptions<State, Actions, Props, DerivedState> = {
938
+ // onPropsChange: [
939
+ // {
940
+ // getDeps: (p) => [p.initialTodos],
941
+ // effects: ({ s, p }) => ({ ...s, ...splitList(p.initialTodos) }),
942
+ // onMount: true,
943
+ // },
944
+ // ],
945
+ // };
946
+ it('onPropsChange', () => {
947
+ store
948
+ // onPropsChange allows to test prop change, no side effect on original store
949
+ // to create a new store with new props, use setProps or setPartialProps
950
+ .onPropsChange({
951
+ initialTodos: [
952
+ {
953
+ id: 'item1',
954
+ title: 'Item 1',
871
955
  completed: false,
872
- title: 'todo 2',
873
956
  },
874
- id3: {
875
- id: 'id3',
957
+ ],
958
+ })
959
+ .test(({ state, actions }) => {
960
+ // test state after prop has changed
961
+ expect(state.todoIds).toEqual(['item1']);
962
+ expect(state.todoMap).toEqual({
963
+ item1: {
964
+ id: 'item1',
965
+ title: 'Item 1',
876
966
  completed: false,
877
- title: 'new todo',
878
967
  },
879
968
  });
969
+
970
+ // test derived state after prop has changed
971
+ expect(state.todos).toEqual([
972
+ {
973
+ id: 'item1',
974
+ title: 'Item 1',
975
+ completed: false,
976
+ },
977
+ ]);
978
+
979
+ // test side effects also
980
+ expect(actions.loadRemoteList).not.toHaveBeenCalled();
880
981
  });
881
982
  });
882
983
 
883
- it('onToggle', async () => {
884
- // this mock action is shared
885
- const onToggle = store.getAction('onToggle');
984
+ describe('actions', () => {
985
+ it('onSetNewTitle', async () => {
986
+ // always return a promise whatever if the action is asynchronous or not
987
+ const { state, prevState } = await store.getAction('onSetNewTitle').call('new Title');
886
988
 
887
- // arguments of call() depend on the Store action signature, use auto completion!
888
- await onToggle.call('id2').then(({ state: { todoIds, todoMap } }) => {
889
- expect(todoIds).toEqual(['id', 'id2']);
989
+ // previous state is available for comparison
990
+ expect(prevState.newTitle).toEqual('');
991
+ expect(state.newTitle).toEqual('new Title');
992
+ });
993
+
994
+ it('onCreate', async () => {
995
+ const {
996
+ state: { todoIds, todoMap, todos },
997
+ } = await store
998
+ // set partial state and return new store, source store is untouched
999
+ .setPartialState({
1000
+ newTitle: 'new todo',
1001
+ })
1002
+ // get a mock action that can be shared too !
1003
+ .getAction('onCreate')
1004
+ // Invokes action. It has no side effect on state of mock action
1005
+ .call();
1006
+
1007
+ // assert state
1008
+ expect(todoIds).toEqual(['id', 'id2', 'id3']);
890
1009
  expect(todoMap).toEqual({
891
1010
  id: {
892
1011
  id: 'id',
@@ -895,73 +1014,143 @@ describe('Todo', () => {
895
1014
  },
896
1015
  id2: {
897
1016
  id: 'id2',
898
- completed: true,
1017
+ completed: false,
899
1018
  title: 'todo 2',
900
1019
  },
1020
+ id3: {
1021
+ id: 'id3',
1022
+ completed: false,
1023
+ title: 'new todo',
1024
+ },
901
1025
  });
902
- });
903
1026
 
904
- await onToggle.call('id').then(({ state: { todoIds, todoMap } }) => {
905
- expect(todoIds).toEqual(['id', 'id2']);
906
- expect(todoMap).toEqual({
907
- id: {
1027
+ // assert derived state
1028
+ //
1029
+ // export const todoOptions: StoreOptions<State, Actions, Props, DerivedState> = {
1030
+ // derivedState: {
1031
+ // todos: {
1032
+ // getDeps: ({ s }) => [s.todoIds, s.todoMap],
1033
+ // get: ({ s }) => s.todoIds.map((id) => s.todoMap[id]),
1034
+ // },
1035
+ // },
1036
+ // };
1037
+
1038
+ expect(todos).toEqual([
1039
+ {
908
1040
  id: 'id',
909
- completed: false,
1041
+ completed: true,
910
1042
  title: 'todo',
911
1043
  },
912
- id2: {
1044
+ {
913
1045
  id: 'id2',
914
1046
  completed: false,
915
1047
  title: 'todo 2',
916
1048
  },
917
- });
1049
+ {
1050
+ id: 'id3',
1051
+ completed: false,
1052
+ title: 'new todo',
1053
+ },
1054
+ ]);
918
1055
  });
919
- });
920
1056
 
921
- // Another store / action
922
- it('getList', async () => {
923
- await store
924
- .getAction('getList')
925
- // override default promise result
926
- .promiseResolves([])
927
- // simulate error
928
- //.promiseRejects(new Error('boom'))
929
- .call()
930
- .then((res) => {
931
- // if there are some side effects calling store action, you test them
1057
+ describe('onToggle', () => {
1058
+ // this mock action is shared in two tests but they can run in parallel
1059
+ const onToggle = store.getAction('onToggle');
1060
+
1061
+ it('toggle false => true', async () => {
1062
+ // arguments of call() depend on the Store action signature, use auto completion!
1063
+ const {
1064
+ state: { todoIds, todoMap },
1065
+ actions,
1066
+ } = await onToggle.call('id2');
1067
+
1068
+ expect(todoIds).toEqual(['id', 'id2']);
1069
+ expect(todoMap).toEqual({
1070
+ id: {
1071
+ id: 'id',
1072
+ completed: true,
1073
+ title: 'todo',
1074
+ },
1075
+ id2: {
1076
+ id: 'id2',
1077
+ completed: true,
1078
+ title: 'todo 2',
1079
+ },
1080
+ });
1081
+
1082
+ // if there are some side effects calling store actions, you can test them
932
1083
  // as mock actions are injected instead of real actions.
933
- expect(res.actions.sideEffectAction).toHaveBeenCalledWith('sideEffect');
934
- expect(res.state).toEqual({
935
- // state...
1084
+ expect(actions.updateRemoteList).toHaveBeenCalled();
1085
+ });
1086
+
1087
+ it('toggle true => false', async () => {
1088
+ const {
1089
+ state: { todoIds, todoMap },
1090
+ actions,
1091
+ } = await onToggle.call('id');
1092
+
1093
+ expect(todoIds).toEqual(['id', 'id2']);
1094
+ expect(todoMap).toEqual({
1095
+ id: {
1096
+ id: 'id',
1097
+ completed: false,
1098
+ title: 'todo',
1099
+ },
1100
+ id2: {
1101
+ id: 'id2',
1102
+ completed: false,
1103
+ title: 'todo 2',
1104
+ },
936
1105
  });
1106
+
1107
+ // if there are some side effects calling store actions, you can test them
1108
+ // as mock actions are injected instead of real actions.
1109
+ expect(actions.updateRemoteList).toHaveBeenCalled();
937
1110
  });
938
- });
1111
+ });
939
1112
 
940
- // Another store
941
- it('onPropsChange', () => {
942
- store
943
- // onPropsChange allows to test prop change, no side effect on original store
944
- // to create a new store with new props, use setProps or setPartialProps
945
- .onPropsChange({
946
- prop: 'new_prop',
947
- })
948
- .test((res) => {
949
- // test side effects
950
- expect(res.actions.sideEffectAction).toHaveBeenCalledWith('sideEffect');
951
- // test store props
952
- expect(res.props.prop).toEqual('new_prop');
953
- //
954
- expect(res.state).toEqual({
955
- prop1: 'new_prop',
956
- derived: '', // derived state is updated
1113
+ // Another store / action
1114
+ describe('loadRemoteList', () => {
1115
+ // action is shared
1116
+ const action = store.getAction('loadRemoteList');
1117
+
1118
+ it('success', async () => {
1119
+ const { state } = await action
1120
+ // override default promise result
1121
+ .promiseResolves([
1122
+ {
1123
+ id: 'item1',
1124
+ title: 'item title',
1125
+ completed: true,
1126
+ },
1127
+ ])
1128
+ .call();
1129
+
1130
+ expect(state.error).toBeFalsy();
1131
+ expect(state.todoIds).toEqual(['item1']);
1132
+ expect(state.todoMap).toEqual({
1133
+ item1: {
1134
+ id: 'item1',
1135
+ title: 'item title',
1136
+ completed: true,
1137
+ },
957
1138
  });
958
1139
  });
1140
+
1141
+ it('error', async () => {
1142
+ const { state } = await action
1143
+ // override default promise result with error
1144
+ .promiseRejects(new Error('boom'))
1145
+ .call();
1146
+
1147
+ expect(state.error).toBeTruthy();
1148
+ });
1149
+ });
959
1150
  });
960
1151
  });
961
1152
  ```
962
1153
 
963
- [![Edit Todo](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/todo-forked-ml0z6?file=/src/TodoApp.tsx)
964
-
965
1154
  ## Error testing
966
1155
 
967
1156
  ### Managed error
@@ -1085,8 +1274,7 @@ TypeError: Cannot set property 'crash' of null
1085
1274
  | Function | Arguments | Returns | Description |
1086
1275
  | --------------- | ------------------------------------ | ------------------- | ------------------------------------------------------------------------------------------- |
1087
1276
  | getAction | actionName: keyof A | MockStoreAction | Get a mock action instance |
1088
- | init | props?: Partial<P> | MockResult | Test store initialization (onPropsChanged marked onMount + onMount) |
1089
- | onMount | props: P | MockResult | Test onMount. Does not change internal props. |
1277
+ | onInit | props?: Partial<P> | MockResult | Test store initialization (onPropsChanged marked onMount + onMount) |
1090
1278
  | onPropsChange | props: P, init?: boolean | MockResult | Test prop changes. Does not change internal props. Init allows to test onMount prop changes |
1091
1279
  | setPartialProps | props: Partial<P> | new mock store | Create a new store with the merge of current props and partial props |
1092
1280
  | setPartialState | state: Partial<S> | new mock store | Create a new store with the merge of current state and partial state |
package/impl.es.js CHANGED
@@ -1,2 +1,2 @@
1
- function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t){var e={exports:{}};return t(e,e.exports),e.exports}var r,n=e((function(t){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0})),o=e((function(t){t.exports=function(t){if(Array.isArray(t))return n(t)},t.exports.default=t.exports,t.exports.__esModule=!0})),i=e((function(t){t.exports=function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)},t.exports.default=t.exports,t.exports.__esModule=!0})),a=e((function(t){t.exports=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0})),u=e((function(t){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0})),c=t(e((function(t){t.exports=function(t){return o(t)||i(t)||a(t)||u()},t.exports.default=t.exports,t.exports.__esModule=!0}))),s=e((function(t){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0})),f=e((function(t){t.exports=function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}},t.exports.default=t.exports,t.exports.__esModule=!0})),l=e((function(t){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0})),p=t(e((function(t){t.exports=function(t,e){return s(t)||f(t,e)||a(t,e)||l()},t.exports.default=t.exports,t.exports.__esModule=!0}))),d=t(e((function(t){function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0}))),h=t(e((function(t){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.default=t.exports,t.exports.__esModule=!0}))),v=e((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof y?e:y,i=Object.create(o.prototype),a=new j(n||[]);return i._invoke=function(t,e,r){var n=l;return function(o,i){if(n===d)throw new Error("Generator is already running");if(n===h){if("throw"===o)throw i;return R()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=O(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=d;var c=f(t,e,r);if("normal"===c.type){if(n=r.done?h:p,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=h,r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l="suspendedStart",p="suspendedYield",d="executing",h="completed",v={};function y(){}function g(){}function m(){}var w={};w[i]=function(){return this};var E=Object.getPrototypeOf,x=E&&E(E(A([])));x&&x!==r&&n.call(x,i)&&(w=x);var b=m.prototype=y.prototype=Object.create(w);function S(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function A(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:R}}function R(){return{value:e,done:!0}}return g.prototype=b.constructor=m,m.constructor=g,g.displayName=c(m,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},S(P.prototype),P.prototype[a]=function(){return this},t.AsyncIterator=P,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(b),c(b,u,"Generator"),b[i]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=A,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:A(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}})),y=t(e((function(t){function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})));function g(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function m(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?g(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}!function(t){t.REJECT="reject",t.IGNORE="ignore",t.KEEP_LAST="keepLast",t.KEEP_ALL="keepAll",t.PARALLEL="parallel",t.REUSE="reuse"}(r||(r={}));var w={clone:function(t){return JSON.parse(JSON.stringify(t))},comparator:function(t,e){if(Object.is(t,e))return!0;if("object"!==y(t)||null===t||"object"!==y(e)||null===e)return!1;if(t instanceof Set||e instanceof Set)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||!Object.is(t[r[o]],e[r[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(t){return t instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function E(t){Object.keys(t).forEach((function(e){null!=t[e]&&(w[e]=t[e])}))}function x(t){try{return w.clone(t)}catch(t){var e="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(e),console.error(t.toString())),new Error(e)}}function b(t){return!(t instanceof Function)&&(t.hasOwnProperty("getPromise")||t.hasOwnProperty("getGetPromise"))}function S(t){return"function"==typeof t}function P(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function O(t){return"function"!=typeof t&&t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function _(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&t.hasOwnProperty("getGetPromise")}function L(t){return _(t)?m(m({},t),{},{getPromise:t.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):t}function j(t,e,r,n){return m(m({},t),{},h({},e,n?m(m({},t[e]||{}),{},h({},r,n)):m(m({},t[e]),{},h({},r,!1))))}function A(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){return!0};return 1===e?t:function(o){function i(t,e){return a.apply(this,arguments)}function a(){return(a=d(v.mark((function a(u,c){return v.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:if(null!==c){a.next=2;break}return a.abrupt("return",null);case 2:return a.abrupt("return",c.catch((function(a){return n(a)?u===e?Promise.reject(a):new Promise((function(e,n){setTimeout((function(){var r=t(o);i(u+1,r).then(e).catch(n)}),r*u)})):Promise.reject(a)})));case 3:case"end":return a.stop()}}),a)})))).apply(this,arguments)}var u=t(o);return null===u?null:i(1,u)}}function R(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return{current:t}}function M(t,e,r){var n,o;return{state:t.current,s:t.current,ds:null==e||null===(n=e.current)||void 0===n?void 0:n.state,derived:null==e||null===(o=e.current)||void 0===o?void 0:o.state,props:r.current,p:r.current}}function k(t,e,r,n){return D(M(t,e,r),n)}function T(t,e,r,n,o,i){var a=M(t,e,r);return a.indices=n,a.index=o,a.isInit=i,a}function C(t,e,r,n,o){var i=M(t,e,r);return i.args=n,o&&(i.promiseId=o),i}function N(t,e,r,n,o,i){var a=C(t,e,r,n,i);return a.result=o,a.res=o,a}function I(t,e,r,n,o,i,a){var u=D(C(t,e,r,n,a),o);return u.abortSignal=i,u}function G(t,e){var r=t;return r.state=e.current,r.s=e.current,r}function D(t,e){var r=t;return r.actions=e.current,r.a=e.current,r}function F(t,e,r,n,o){var i,a=D(t,n);G(t,e);var u=null==r||null===(i=r.current)||void 0===i?void 0:i.state;return a.derived=u,a.ds=u,a.notifyWarning=o,a}function K(t){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(t," action was called while store is not initialized or destroyed, this is probably a leak"))}function U(t,e,r,n,o,i,a){return function(){if(i.current){for(var u=arguments.length,c=new Array(u),s=0;s<u;s++)c[s]=arguments[s];var f=C(r,n,o,c),l=e(f);a(l,null,t,"effects",!1,f,!1)}else K(t)}}function W(t,e,r,n,o,i,a,u,c,s){var f=N(r,n,o,s,void 0),l=!1;if(null!=e.effects){var p=e.effects(f);null===p?l=!0:c(p,void 0,t,"effects",!1,f,!1)}if(!l)if(e.debounceSideEffectsTimeout>0){var d=a.current[t];d&&clearTimeout(d),a.current[t]=setTimeout((function(){e.sideEffects(F(f,r,n,i,u.notifyWarning)),delete a.current[t]}),e.debounceSideEffectsTimeout)}else e.sideEffects&&e.sideEffects(F(f,r,n,i,u.notifyWarning))}function z(t,e,r,n,o,i,a,u,c,s){return function(){for(var f=arguments.length,l=new Array(f),p=0;p<f;p++)l[p]=arguments[p];if(a.current)if(e.debounceTimeout){var d=u.current[t];d&&clearTimeout(d),u.current[t]=setTimeout((function(){delete u.current[t],W(t,e,r,n,o,i,u,c,s,l)}),e.debounceTimeout)}else W(t,e,r,n,o,i,u,c,s,l);else K(t)}}function J(t,e,r,n){var o=t.action,i=t.stateRef,a=t.derivedStateRef,u=t.propsRef,c=t.promisesRef,s=t.actionsRef,f=t.loadingMapRef,l=t.conflictActionsRef,p=t.actionName,d=t.options,h=t.setState;if(t.initializedRef.current){var v=null,y=N(i,a,u,n,r,e);o.effects&&(v=o.effects(y)),h(v,j(f.current,p,e,!1),p,"effects",!0,y,!1);var g,m=d.notifySuccess||w.notifySuccess;if(m)o.getSuccessMessage&&(g=o.getSuccessMessage(y)),g&&m(g);return delete c.current[p][e],o.sideEffects&&o.sideEffects(F(y,i,a,s,w.notifyWarning)),Q(p,s.current,l.current),r}}function H(t,e,r,n){var o=t.action,i=t.stateRef,a=t.derivedStateRef,u=t.propsRef,c=t.actionsRef,s=t.loadingMapRef,f=t.promisesRef,l=t.conflictActionsRef,p=t.actionName,d=t.options,h=t.setState;if(t.initializedRef.current){var v=null,y=function(t,e,r,n,o,i){var a=C(t,e,r,n,i);return a.error=o,a.err=o,a}(i,a,u,n,r,e);o.errorEffects&&(v=o.errorEffects(y)),h(v,j(s.current,p,e,!1),p,"errorEffects",!0,y,!1);var g=!1;(null!=v||o.errorSideEffects)&&(g=!0);var m,E=d.notifyError||w.notifyError;if(E)o.getErrorMessage&&(m=o.getErrorMessage(y)),m||g||!w.getErrorMessage||(m=w.getErrorMessage(r)),m&&(g=!0,E(m));return w.asyncErrorHandler(r,g||o.rejectPromiseOnError,i.current,u.current,p,n),delete f.current[p][e],o.errorSideEffects&&o.errorSideEffects(F(y,i,a,c,w.notifyWarning)),Q(p,c.current,l.current),!g||o.rejectPromiseOnError?Promise.reject(r):Promise.resolve()}}function V(t){var e=t.action,n=t.stateRef,o=t.derivedStateRef,i=t.propsRef,a=t.actionsRef,u=t.promisesRef,c=t.loadingMapRef,s=t.initializedRef,f=t.conflictActionsRef,l=t.actionName,p=t.setState;return function(){for(var d,v,y=arguments.length,g=new Array(y),E=0;E<y;E++)g[E]=arguments[E];if(!s.current)return K(l),null;var x=u.current,b=e.conflictPolicy,S=void 0===b?r.KEEP_ALL:b,P=S===r.PARALLEL,O=null;if(P){if(!e.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");O=e.getPromiseId.apply(e,g)}else O=$;if(!P&&null!==(d=x[l])&&void 0!==d&&d[O])return B(x,f.current,l,S,g);var _=null,L=!1,R=C(n,o,i,g,O);e.preEffects&&(_=e.preEffects(R))&&(L=!0,n.current=_);var M=e.abortable,k=e.retryCount,T=e.retryDelaySeed,N=e.isTriggerRetryError,G=M&&window.AbortController?new AbortController:null,D=A(e.getPromise,k?1+k:1,T,N||w.retryOnErrorFunction),F=null===(v=D(I(n,o,i,g,a,null==G?void 0:G.signal)))||void 0===v?void 0:v.then((function(e){return J(t,O,e,g)})).catch((function(e){return H(t,O,e,g)}));return null!=F&&(x[l]=m(m({},x[l]||{}),{},h({},O||$,{abortController:G,promise:F,refArgs:S===r.REUSE&&g.length>0?[].concat(g):[]}))),p(null!=F||L?n.current:void 0,null==F?void 0:j(c.current,l,O,!0),l,"preEffects",!0,R,!1),F}}function Y(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return r.some((function(e){var r=null,n=$;if(Array.isArray(e)){var o=p(e,2);r=o[0];var i=o[1];n=void 0===i?$:i}else r=e;var a=t[r];return null!=a&&(null!=a[n]&&a[n])}))}var $="__def__";function q(t,e){return t.length===e.length&&-1===t.findIndex((function(t,r){return e[r]!==t}))}function B(t,e,n,o,i){var a=o;if(a===r.REUSE){if(q(t[n][$].refArgs,i))return t[n][$].promise;a=r.KEEP_ALL}return new Promise((function(t,o){var u={resolve:t,reject:o,args:x(i),timestamp:Date.now()};switch(a){case r.IGNORE:t(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:e[n]=[u];break;case r.KEEP_ALL:var c=e[n];c||(e[n]=c=[]),c.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function Q(t,e,r){var n=r[t];if(n&&n.length>0){var o=r[t].shift();if(o){var i=e[t].apply(e,c(o.args));null==i?Q(t,e,r):i.then((function(n){null===n&&Q(t,e,r),o.resolve(n)})).catch((function(t){return o.reject(t)}))}}}function X(t,e,r,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=w.comparator,a=r.current.deps,u=M(t,null,e),c=Object.keys(n.derivedState);return r.current.state=c.reduce((function(t,e){var c=!1,s=a[e],f=n.derivedState[e].getDeps(u);return c=null==s||null!=f.find((function(t,e){return s.length<e||!i(s[e],t)})),o=o||c,a[e]=f,t[e]=c?n.derivedState[e].get(u):r.current.state[e],t}),{}),o}function Z(t,e,r,n,o,i,a,u){var c=null!=(null==i?void 0:i.derivedState);if(null!=i.onPropsChange){var s;s=Array.isArray(i.onPropsChange)?i.onPropsChange:[i.onPropsChange];var f=!1,l=R(t.current),p=[],d=w.comparator;s.forEach((function(t,o){var i=t.getDeps;if(i){var c=!1,s=[];if(u){if(!t.onMount)return;c=!0}else{var h=i(n),v=i(r.current);h.length!==v.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),c=!0):h.forEach((function(t,e){d(t,v[e])||(c=!0,s.push(e))}))}if(c){var y,g,m=T(l,e,r,s,o,u),w=null!==(y=null===(g=t.effects)||void 0===g?void 0:g.call(t,m))&&void 0!==y?y:null;null!=w&&(f=!0,l.current=w,a(l.current,void 0,"onPropsChange","effects",!1,m,!0,u)),t.sideEffects&&p.push({index:o,indices:s,ctx:m})}}})),!f&&c&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(t){s[t.index].sideEffects(m(m({},G(D(t.ctx,o),l)),{},{indices:t.indices}))}))}else null!=(null==i?void 0:i.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function tt(t,e,r,n,o,i,a,u){if("onPropsChange"===o&&void 0===r)return{newState:null,newLoading:!1};if(t&&t.length>0){var c=t.reduce((function(t,e){var r=e.effects({isAsync:a,name:o,type:i,context:u},t.oldState,t.newState,n);return{newState:(null==r?void 0:r.state)||t.newState,oldState:null!=r&&r.state?t.newState:t.oldState,loading:null==(null==r?void 0:r.loading)?t.loading:r.loading}}),{oldState:e,newState:r,loading:n});return{newLoading:c.loading,newState:c.newState}}return{newState:r,newLoading:n}}export{$ as DEFAULT_PROMISE_ID,D as addContextActions,G as addStateToContext,q as areSameArgs,M as buildInvocationContextBase,j as buildLoadingMap,k as buildOnMountInvocationContext,T as buildOnPropChangeEffects,L as computeAsyncActionInput,X as computeDerivedValues,R as createRef,V as decorateAsyncAction,U as decorateSimpleSyncAction,z as decorateSyncAction,w as globalConfig,b as isAsyncAction,O as isAsyncGetPromiseAction,_ as isAsyncGetPromiseGetAction,Y as isLoadingImpl,S as isSimpleSyncAction,P as isSyncAction,Z as onPropChange,A as retryPromiseDecorator,tt as runMiddlewares,E as setGlobalConfig};
1
+ function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t){var e={exports:{}};return t(e,e.exports),e.exports}var r,n=e((function(t){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0})),o=e((function(t){t.exports=function(t){if(Array.isArray(t))return n(t)},t.exports.default=t.exports,t.exports.__esModule=!0})),i=e((function(t){t.exports=function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)},t.exports.default=t.exports,t.exports.__esModule=!0})),a=e((function(t){t.exports=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0})),u=e((function(t){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0})),c=t(e((function(t){t.exports=function(t){return o(t)||i(t)||a(t)||u()},t.exports.default=t.exports,t.exports.__esModule=!0}))),s=e((function(t){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0})),f=e((function(t){t.exports=function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}},t.exports.default=t.exports,t.exports.__esModule=!0})),l=e((function(t){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0})),p=t(e((function(t){t.exports=function(t,e){return s(t)||f(t,e)||a(t,e)||l()},t.exports.default=t.exports,t.exports.__esModule=!0}))),d=t(e((function(t){function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0}))),h=t(e((function(t){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.default=t.exports,t.exports.__esModule=!0}))),v=e((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof y?e:y,i=Object.create(o.prototype),a=new j(n||[]);return i._invoke=function(t,e,r){var n=l;return function(o,i){if(n===d)throw new Error("Generator is already running");if(n===h){if("throw"===o)throw i;return R()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=O(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=d;var c=f(t,e,r);if("normal"===c.type){if(n=r.done?h:p,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=h,r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l="suspendedStart",p="suspendedYield",d="executing",h="completed",v={};function y(){}function g(){}function m(){}var w={};w[i]=function(){return this};var E=Object.getPrototypeOf,x=E&&E(E(A([])));x&&x!==r&&n.call(x,i)&&(w=x);var b=m.prototype=y.prototype=Object.create(w);function S(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function A(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:R}}function R(){return{value:e,done:!0}}return g.prototype=b.constructor=m,m.constructor=g,g.displayName=c(m,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},S(P.prototype),P.prototype[a]=function(){return this},t.AsyncIterator=P,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(b),c(b,u,"Generator"),b[i]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=A,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:A(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}})),y=t(e((function(t){function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})));function g(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function m(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?g(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}!function(t){t.REJECT="reject",t.IGNORE="ignore",t.KEEP_LAST="keepLast",t.KEEP_ALL="keepAll",t.PARALLEL="parallel",t.REUSE="reuse"}(r||(r={}));var w={clone:function(t){return JSON.parse(JSON.stringify(t))},comparator:function(t,e){if(Object.is(t,e))return!0;if("object"!==y(t)||null===t||"object"!==y(e)||null===e)return!1;if(t instanceof Set||e instanceof Set)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||!Object.is(t[r[o]],e[r[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(t){return t instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function E(t){Object.keys(t).forEach((function(e){null!=t[e]&&(w[e]=t[e])}))}function x(t){try{return w.clone(t)}catch(t){var e="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(e),console.error(t.toString())),new Error(e)}}function b(t){return!(t instanceof Function)&&(t.hasOwnProperty("getPromise")||t.hasOwnProperty("getGetPromise"))}function S(t){return"function"==typeof t}function P(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function O(t){return"function"!=typeof t&&t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function _(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&t.hasOwnProperty("getGetPromise")}function L(t){return _(t)?m(m({},t),{},{getPromise:t.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):t}function j(t,e,r,n){return m(m({},t),{},h({},e,n?m(m({},t[e]||{}),{},h({},r,n)):m(m({},t[e]),{},h({},r,!1))))}function A(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e3,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){return!0};return 1===e?t:function(o){function i(t,e){return a.apply(this,arguments)}function a(){return(a=d(v.mark((function a(u,c){return v.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:if(null!==c){a.next=2;break}return a.abrupt("return",null);case 2:return a.abrupt("return",c.catch((function(a){return n(a)?u===e?Promise.reject(a):new Promise((function(e,n){setTimeout((function(){var r=t(o);i(u+1,r).then(e).catch(n)}),r*u)})):Promise.reject(a)})));case 3:case"end":return a.stop()}}),a)})))).apply(this,arguments)}var u=t(o);return null===u?null:i(1,u)}}function R(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return{current:t}}function M(t,e,r){var n,o;return{state:t.current,s:t.current,ds:null==e||null===(n=e.current)||void 0===n?void 0:n.state,derived:null==e||null===(o=e.current)||void 0===o?void 0:o.state,props:r.current,p:r.current}}function k(t,e,r,n){return D(M(t,e,r),n)}function T(t,e,r,n,o,i){var a=M(t,e,r);return a.indices=n,a.index=o,a.isInit=i,a}function C(t,e,r,n,o){var i=M(t,e,r);return i.args=n,o&&(i.promiseId=o),i}function N(t,e,r,n,o,i){var a=C(t,e,r,n,i);return a.result=o,a.res=o,a}function I(t,e,r,n,o,i,a){var u=D(C(t,e,r,n,a),o);return u.abortSignal=i,u}function G(t,e){var r=t;return r.state=e.current,r.s=e.current,r}function D(t,e){var r=t;return r.actions=e.current,r.a=e.current,r}function F(t,e,r,n,o){var i,a=D(t,n);G(t,e);var u=null==r||null===(i=r.current)||void 0===i?void 0:i.state;return a.derived=u,a.ds=u,a.notifyWarning=o,a}function K(t){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(t," action was called while store is not initialized or destroyed, this is probably a leak"))}function U(t,e,r,n,o,i,a){return function(){if(i.current){for(var u=arguments.length,c=new Array(u),s=0;s<u;s++)c[s]=arguments[s];var f=C(r,n,o,c),l=e(f);a(l,null,t,"effects",!1,f,!1)}else K(t)}}function W(t,e,r,n,o,i,a,u,c,s){var f=N(r,n,o,s,void 0),l=!1;if(null!=e.effects){var p=e.effects(f);null===p?l=!0:c(p,void 0,t,"effects",!1,f,!1)}if(!l)if(e.debounceSideEffectsTimeout>0){var d=a.current[t];d&&clearTimeout(d),a.current[t]=setTimeout((function(){e.sideEffects(F(f,r,n,i,u.notifyWarning)),delete a.current[t]}),e.debounceSideEffectsTimeout)}else e.sideEffects&&e.sideEffects(F(f,r,n,i,u.notifyWarning))}function z(t,e,r,n,o,i,a,u,c,s){return function(){for(var f=arguments.length,l=new Array(f),p=0;p<f;p++)l[p]=arguments[p];if(a.current)if(e.debounceTimeout){var d=u.current[t];d&&clearTimeout(d),u.current[t]=setTimeout((function(){delete u.current[t],W(t,e,r,n,o,i,u,c,s,l)}),e.debounceTimeout)}else W(t,e,r,n,o,i,u,c,s,l);else K(t)}}function J(t,e,r,n){var o=t.action,i=t.stateRef,a=t.derivedStateRef,u=t.propsRef,c=t.promisesRef,s=t.actionsRef,f=t.loadingMapRef,l=t.conflictActionsRef,p=t.actionName,d=t.options,h=t.setState;if(t.initializedRef.current){var v=null,y=N(i,a,u,n,r,e);o.effects&&(v=o.effects(y)),h(v,j(f.current,p,e,!1),p,"effects",!0,y,!1);var g,m=d.notifySuccess||w.notifySuccess;if(m)o.getSuccessMessage&&(g=o.getSuccessMessage(y)),g&&m(g);return delete c.current[p][e],o.sideEffects&&o.sideEffects(F(y,i,a,s,w.notifyWarning)),Q(p,s.current,l.current),r}}function H(t,e,r,n){var o=t.action,i=t.stateRef,a=t.derivedStateRef,u=t.propsRef,c=t.actionsRef,s=t.loadingMapRef,f=t.promisesRef,l=t.conflictActionsRef,p=t.actionName,d=t.options,h=t.setState;if(t.initializedRef.current){var v=null,y=function(t,e,r,n,o,i){var a=C(t,e,r,n,i);return a.error=o,a.err=o,a}(i,a,u,n,r,e);o.errorEffects&&(v=o.errorEffects(y)),h(v,j(s.current,p,e,!1),p,"errorEffects",!0,y,!1);var g=!1;(null!=v||o.errorSideEffects)&&(g=!0);var m,E=d.notifyError||w.notifyError;if(E)o.getErrorMessage&&(m=o.getErrorMessage(y)),void 0===m&&!g&&w.getErrorMessage&&(m=w.getErrorMessage(r)),m&&(g=!0,E(m));return w.asyncErrorHandler(r,g||o.rejectPromiseOnError,i.current,u.current,p,n),delete f.current[p][e],o.errorSideEffects&&o.errorSideEffects(F(y,i,a,c,w.notifyWarning)),Q(p,c.current,l.current),!g||o.rejectPromiseOnError?Promise.reject(r):Promise.resolve()}}function V(t){var e=t.action,n=t.stateRef,o=t.derivedStateRef,i=t.propsRef,a=t.actionsRef,u=t.promisesRef,c=t.loadingMapRef,s=t.initializedRef,f=t.conflictActionsRef,l=t.actionName,p=t.setState;return function(){for(var d,v,y=arguments.length,g=new Array(y),E=0;E<y;E++)g[E]=arguments[E];if(!s.current)return K(l),null;var x=u.current,b=e.conflictPolicy,S=void 0===b?r.KEEP_ALL:b,P=S===r.PARALLEL,O=null;if(P){if(!e.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");O=e.getPromiseId.apply(e,g)}else O=$;if(!P&&null!==(d=x[l])&&void 0!==d&&d[O])return B(x,f.current,l,S,g);var _=null,L=!1,R=C(n,o,i,g,O);e.preEffects&&(_=e.preEffects(R))&&(L=!0,n.current=_);var M=e.abortable,k=e.retryCount,T=e.retryDelaySeed,N=e.isTriggerRetryError,G=M&&window.AbortController?new AbortController:null,D=A(e.getPromise,k?1+k:1,T,N||w.retryOnErrorFunction),F=null===(v=D(I(n,o,i,g,a,null==G?void 0:G.signal)))||void 0===v?void 0:v.then((function(e){return J(t,O,e,g)})).catch((function(e){return H(t,O,e,g)}));return null!=F&&(x[l]=m(m({},x[l]||{}),{},h({},O||$,{abortController:G,promise:F,refArgs:S===r.REUSE&&g.length>0?[].concat(g):[]}))),p(null!=F||L?n.current:void 0,null==F?void 0:j(c.current,l,O,!0),l,"preEffects",!0,R,!1),F}}function Y(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];return r.some((function(e){var r=null,n=$;if(Array.isArray(e)){var o=p(e,2);r=o[0];var i=o[1];n=void 0===i?$:i}else r=e;var a=t[r];return null!=a&&(null!=a[n]&&a[n])}))}var $="__def__";function q(t,e){return t.length===e.length&&-1===t.findIndex((function(t,r){return e[r]!==t}))}function B(t,e,n,o,i){var a=o;if(a===r.REUSE){if(q(t[n][$].refArgs,i))return t[n][$].promise;a=r.KEEP_ALL}return new Promise((function(t,o){var u={resolve:t,reject:o,args:x(i),timestamp:Date.now()};switch(a){case r.IGNORE:t(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:e[n]=[u];break;case r.KEEP_ALL:var c=e[n];c||(e[n]=c=[]),c.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function Q(t,e,r){var n=r[t];if(n&&n.length>0){var o=r[t].shift();if(o){var i=e[t].apply(e,c(o.args));null==i?Q(t,e,r):i.then((function(n){null===n&&Q(t,e,r),o.resolve(n)})).catch((function(t){return o.reject(t)}))}}}function X(t,e,r,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=w.comparator,a=r.current.deps,u=M(t,null,e),c=Object.keys(n.derivedState);return r.current.state=c.reduce((function(t,e){var c=!1,s=a[e],f=n.derivedState[e].getDeps(u);return c=null==s||null!=f.find((function(t,e){return s.length<e||!i(s[e],t)})),o=o||c,a[e]=f,t[e]=c?n.derivedState[e].get(u):r.current.state[e],t}),{}),o}function Z(t,e,r,n,o,i,a,u){var c=null!=(null==i?void 0:i.derivedState);if(null!=i.onPropsChange){var s;s=Array.isArray(i.onPropsChange)?i.onPropsChange:[i.onPropsChange];var f=!1,l=R(t.current),p=[],d=w.comparator;s.forEach((function(t,o){var i=t.getDeps;if(i){var c=!1,s=[];if(u){if(!t.onMount)return;c=!0}else{var h=i(n),v=i(r.current);h.length!==v.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),c=!0):h.forEach((function(t,e){d(t,v[e])||(c=!0,s.push(e))}))}if(c){var y,g,m=T(l,e,r,s,o,u),w=null!==(y=null===(g=t.effects)||void 0===g?void 0:g.call(t,m))&&void 0!==y?y:null;null!=w&&(f=!0,l.current=w,a(l.current,void 0,"onPropsChange","effects",!1,m,!0,u)),t.sideEffects&&p.push({index:o,indices:s,ctx:m})}}})),!f&&c&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(t){s[t.index].sideEffects(m(m({},G(D(t.ctx,o),l)),{},{indices:t.indices}))}))}else null!=(null==i?void 0:i.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function tt(t,e,r,n,o,i,a,u){if("onPropsChange"===o&&void 0===r)return{newState:null,newLoading:!1};if(t&&t.length>0){var c=t.reduce((function(t,e){var r=e.effects({isAsync:a,name:o,type:i,context:u},t.oldState,t.newState,n);return{newState:(null==r?void 0:r.state)||t.newState,oldState:null!=r&&r.state?t.newState:t.oldState,loading:null==(null==r?void 0:r.loading)?t.loading:r.loading}}),{oldState:e,newState:r,loading:n});return{newLoading:c.loading,newState:c.newState}}return{newState:r,newLoading:n}}export{$ as DEFAULT_PROMISE_ID,D as addContextActions,G as addStateToContext,q as areSameArgs,M as buildInvocationContextBase,j as buildLoadingMap,k as buildOnMountInvocationContext,T as buildOnPropChangeEffects,L as computeAsyncActionInput,X as computeDerivedValues,R as createRef,V as decorateAsyncAction,U as decorateSimpleSyncAction,z as decorateSyncAction,w as globalConfig,b as isAsyncAction,O as isAsyncGetPromiseAction,_ as isAsyncGetPromiseGetAction,Y as isLoadingImpl,S as isSimpleSyncAction,P as isSyncAction,Z as onPropChange,A as retryPromiseDecorator,tt as runMiddlewares,E as setGlobalConfig};
2
2
  //# sourceMappingURL=impl.es.js.map