state-decorator 6.8.0 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -237,12 +237,12 @@ const actions: StoreActions<State, Actions> = {
237
237
 
238
238
  ## Recipes
239
239
 
240
- - If the effects function returns **null**, the side effects, if any, are not executed when the action is called.
240
+ - If the effects function returns `null`, the side effects, if any, are not executed when the action is called.
241
241
  - If not effects function is defined by side effects function is provided, the side effects will be executed when the action is called.
242
242
 
243
243
  ## Cancel action
244
244
 
245
- To cancel effects/side effects just return **null** instead of new state in **effects**.
245
+ To cancel effects/side effects just return `null` instead of new state in **effects**.
246
246
 
247
247
  # Asynchronous actions
248
248
 
@@ -281,16 +281,36 @@ const actions: StoreActions<State, Actions> = {
281
281
  };
282
282
  ```
283
283
 
284
- - If **null** is returned by **getPromise**, the action is not executed. It allows to cancel an action depending on state or props etc.
284
+ - If `null` is returned by **getPromise**, the action is not executed. It allows to cancel an action depending on state or props etc.
285
285
 
286
286
  - **getGetPromise** is a shortcut that sets the conflict policy to **ConflictPolicy.REUSE** and **retryCount** to 3.
287
287
 
288
- - To cancel any effects just return **null** instead of new state in **xxxEffects**.
288
+ - To cancel any effects just return `null` instead of new state in **xxxEffects**.
289
289
 
290
290
  ## Asynchronous action lifecycle
291
291
 
292
292
  <!-- ![Lifecycle](https://raw.githubusercontent.com/GlobalSport/state-decorator/develop/doc/StateDecoratorDiagram.png) -->
293
293
 
294
+ ```mermaid
295
+ graph TD
296
+ A(Call action) --> preEffects
297
+ preEffects --> optimisticEffects
298
+ optimisticEffects --> getPromise
299
+ getPromise --> promiseSuccess{Success?}
300
+ promiseSuccess -->|Yes| effects[effects]
301
+ effects --> notifySuccess[notifySuccess]
302
+ notifySuccess --> sideEffects[sideEffects]
303
+ sideEffects --> promiseResolved[Promise is resolved]
304
+ promiseResolved --> Z(End)
305
+ promiseSuccess -->|No| errorEffects[errorEffects]
306
+ errorEffects --> notifyError[notifyError]
307
+ notifyError --> errSideEffetcs[errorSideEffects]
308
+ errSideEffetcs --> errorManaged{Error managed?}
309
+ errorManaged --> |Yes| promiseResolved
310
+ errorManaged --> |No| promiseRejected
311
+ promiseRejected --> Z
312
+ ```
313
+
294
314
  - check if a previous call to this action is ongoing,
295
315
  - if yes, check if the conflict policy is parallel,
296
316
  - if yes, let the flow continue.
@@ -308,6 +328,7 @@ const actions: StoreActions<State, Actions> = {
308
328
  - **errorEffects**: change state from promise arguments and returned error.
309
329
  - if **notifyError** is set, call it with **getErrorMessage()**.
310
330
  - **errorSideEffects**: trigger a side effect with no change on state.
331
+ - Global **asyncErrorHandler** is called (with a flag indicating that the error was managed or not, see [Error management](#ErrorManagement) for more details).
311
332
 
312
333
  - If a conflicting action is stored, process it.
313
334
 
@@ -326,24 +347,6 @@ const { isLoading, loading, loadingMap } = useLocalStore(getInitialState, action
326
347
  const isOneLoading = isLoading('action1', 'action2', ['parallelAction', 'promiseId']);
327
348
  ```
328
349
 
329
- ## Error state
330
-
331
- The last error of each asynchronous actions is available on the errorMap.
332
-
333
- ```typescript
334
- const { errorMap } = useLocalStore(getInitialState, actionsImpl);
335
-
336
-
337
- if (errorMap.action1)) {
338
- // show retry action
339
- }
340
-
341
- if (errorMap.action1 instanceof MyCustomError ){
342
- // show retry action with custom error handling
343
- }
344
-
345
- ```
346
-
347
350
  ## Success / error notifications
348
351
 
349
352
  A notification function can be called when the asynchronous action succeeded or failed.
@@ -355,9 +358,38 @@ A notification function can be called when the asynchronous action succeeded or
355
358
  1. _getErrorMessage_ (message built from the error and action context).
356
359
  2. _getSuccessMessage_ (message built from the action context)
357
360
 
361
+ ```typescript
362
+ // global notification functions
363
+ setGlobalConfig({
364
+ notifySuccess: (msg) => console.log(msg),
365
+ notifyError: (msg) => console.log(msg),
366
+ });
367
+
368
+ // local notification functions
369
+ const store = useLocalStore(getInitialState, actionsImpl, props, {
370
+ notifySuccess: (msg) => console.log(msg),
371
+ notifyError: (msg) => console.log(msg),
372
+ });
373
+ ```
374
+
375
+ ```typescript
376
+ // action implementation
377
+ const actions: StoreActions<State, Actions> = {
378
+ loadList: {
379
+ getPromise: () => new Promise((_, reject) => setTimeout(reject, 500, new Error('Too bad'))),
380
+ getSuccessMessage: () => 'success!',
381
+ getErrorMessage: ({ err }) => `Error: ${err.message}`,
382
+ },
383
+ };
384
+ ```
385
+
358
386
  ## <a name="ErrorManagement"></a>Error management
359
387
 
360
- When an asynchronous action fails, if the state needs to be updated, set the _errorEffects_ property of the asynchronous action.
388
+ ### Effects and side effects
389
+
390
+ When an asynchronous action fails, if the state needs to be updated, set the **errorEffects** property of the asynchronous action.
391
+
392
+ If some actions need to be triggered, set **errorSideEffects**.
361
393
 
362
394
  ```typescript
363
395
  const actions: StoreActions<State, Actions> = {
@@ -372,7 +404,40 @@ const actions: StoreActions<State, Actions> = {
372
404
  };
373
405
  ```
374
406
 
375
- **Note:** If an error message or an error reducer is defined, the error will be trapped to prevent other error management (console traces...). If, for any reason, you need to have the promise to be rejected, set **rejectPromiseOnError** to _true_.
407
+ ### Promise result
408
+
409
+ If **getPromise** is failing and the error is _managed_, the action promise will be returned as **resolved** to prevent other error managements (console traces…) to be executed, otherwise it will be returned as **rejected**.
410
+
411
+ An error is _managed_ if:
412
+
413
+ - **errorEffects** is defined and is not returning `null`.
414
+ - or **errorSideEffects** is defined,
415
+ - or **notifyError** is defined and **getErrorMessage** is not returning `null`,
416
+ - or **isErrorManaged** is set to `true`.
417
+
418
+ If the error is managed but you need to have the promise to be rejected, set **rejectPromiseOnError** to `true`.
419
+
420
+ Global **asyncErrorHandler** is called for each error with this _managed_ flag for global error management (logging).
421
+
422
+ ### Error state
423
+
424
+ In order to display UI after an error, the last error of each asynchronous action is available on **errorMap**.
425
+
426
+ ```typescript
427
+ const { errorMap } = useLocalStore(getInitialState, actionsImpl);
428
+
429
+
430
+ if (errorMap.action1)) {
431
+ // show retry action
432
+ }
433
+
434
+ if (errorMap.action1 instanceof MyCustomError){
435
+ // show retry action with custom error handling
436
+ }
437
+
438
+ ```
439
+
440
+ Recipe: When only using the **errorMap** to manage errors (ie. there's no effects nor message and so on), the error is considered _not managed_ resulting in a rejected promise and global **asyncErrorHandler** called with _managed_ flag set to false. In that case, set **isErrorManaged** to `true` to specify that the error is _managed_ externally.
376
441
 
377
442
  ## <a name="ConflictingActions"></a>Conflicting actions
378
443
 
@@ -1324,7 +1389,7 @@ TypeError: Cannot set property 'crash' of null
1324
1389
 
1325
1390
  # Immutability
1326
1391
 
1327
- - Immutability: each effects **must** return a new state instance (or **null** if there's no change).
1392
+ - Immutability: each effects **must** return a new state instance (or `null` if there's no change).
1328
1393
  - I recommend using [Immer](https://github.com/immerjs/immer) to manage complex cases (deep nesting). A **immerizeActions** action decorator is provided to decorate each effect with Immer.
1329
1394
 
1330
1395
  # Limitations
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})),u=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})),c=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})),a=t(e((function(t){t.exports=function(t){return o(t)||i(t)||u(t)||c()},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 u,c=t[Symbol.iterator]();!(n=(u=c.next()).done)&&(r.push(u.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.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)||u(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,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var u=t.apply(r,n);function c(t){e(u,o,i,c,a,"next",t)}function a(t){e(u,o,i,c,a,"throw",t)}c(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0}))),h=t(e((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0}))),v=e((function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0})),y=t(v),g=e((function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),x=t(e((function(t){t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e)},t.exports.default=t.exports,t.exports.__esModule=!0}))),m=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})),b=t(m),w=t(e((function(t){var e=m.default;t.exports=function(t,r){return!r||"object"!==e(r)&&"function"!=typeof r?v(t):r},t.exports.default=t.exports,t.exports.__esModule=!0}))),E=e((function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),_=t(E),O=e((function(t){t.exports=function(t){return-1!==Function.toString.call(t).indexOf("[native code]")},t.exports.default=t.exports,t.exports.__esModule=!0})),P=e((function(t){t.exports=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}},t.exports.default=t.exports,t.exports.__esModule=!0})),S=e((function(t){function e(r,n,o){return P()?(t.exports=e=Reflect.construct,t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&g(o,r.prototype),o},t.exports.default=t.exports,t.exports.__esModule=!0),e.apply(null,arguments)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),j=t(e((function(t){function e(r){var n="function"==typeof Map?new Map:void 0;return t.exports=e=function(t){if(null===t||!O(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,e)}function e(){return S(t,arguments,E(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),g(e,t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}))),L=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}))),R=e((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=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),u=new L(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 M()}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var c=P(u,r);if(c){if(c===v)continue;return c}}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 a=f(t,e,r);if("normal"===a.type){if(n=r.done?h:p,a.arg===v)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n=h,r.method="throw",r.arg=a.arg)}}}(t,r,u),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 x(){}var m={};m[i]=function(){return this};var b=Object.getPrototypeOf,w=b&&b(b(R([])));w&&w!==r&&n.call(w,i)&&(m=w);var E=x.prototype=y.prototype=Object.create(m);function _(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,u,c){var a=f(t[o],t,i);if("throw"!==a.type){var s=a.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):e.resolve(l).then((function(t){s.value=t,u(s)}),(function(t){return r("throw",t,u,c)}))}c(a.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 P(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,P(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 S(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 j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function R(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,u=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 u.next=u}}return{next:M}}function M(){return{value:e,done:!0}}return g.prototype=E.constructor=x,x.constructor=g,g.displayName=a(x,c,"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,x):(t.__proto__=x,a(t,c,"GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},_(O.prototype),O.prototype[u]=function(){return this},t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new O(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},_(E),a(E,c,"Generator"),E[i]=function(){return this},E.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=R,L.prototype={constructor:L,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(j),!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 c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var u=this.tryEntries[i],c=u.completion;if("root"===u.tryLoc)return o("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(a&&s){if(this.prev<u.catchLoc)return o(u.catchLoc,!0);if(this.prev<u.finallyLoc)return o(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return o(u.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return o(u.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 u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(u)},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),j(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;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:R(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)}}));function M(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=_(t);if(e){var o=_(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return w(this,r)}}function A(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 k(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?A(Object(r),!0).forEach((function(e){L(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):A(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 T={clone:function(t){return JSON.parse(JSON.stringify(t))},comparator:function(t,e){if(Object.is(t,e))return!0;if("object"!==b(t)||null===t||"object"!==b(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 C(t){Object.keys(t).forEach((function(e){null!=t[e]&&(T[e]=t[e])}))}function I(t){try{return T.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 N(t){return!(t instanceof Function)&&(t.hasOwnProperty("getPromise")||t.hasOwnProperty("getGetPromise"))}function G(t){return"function"==typeof t}function D(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function F(t){return"function"!=typeof t&&t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function K(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&t.hasOwnProperty("getGetPromise")}function U(t){return K(t)?k(k({},t),{},{getPromise:t.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):t}function W(t,e,r,n){return k(k({},t),{},L({},e,n?k(k({},t[e]||{}),{},L({},r,n)):k(k({},t[e]),{},L({},r,!1))))}function z(t,e,r,n){return k(k({},t),{},L({},e,n?k(k({},t[e]||{}),{},L({},r,n)):k(k({},t[e]),{},L({},r,void 0))))}var B=function(t){x(r,t);var e=M(r);function r(t){var n;return h(this,r),n=e.call(this,"Error"),L(y(n),"promiseIds",void 0),n.promiseIds=t,Object.setPrototypeOf(y(n),r.prototype),n}return r}(j(Error));function J(t){return Object.keys(t).reduce((function(e,r){var n=t[r];if(null==n[lt]);else if(n[lt])e[r]=n[lt];else{var o=Object.keys(n).reduce((function(t,e){return null!=n[e]&&(t.hasErr=!0,t.map[e]=n[e]),t}),{hasErr:!1,map:{}});o.hasErr&&(e[r]=new B(o.map))}return e}),{})}function H(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 u.apply(this,arguments)}function u(){return(u=d(R.mark((function u(c,a){return R.wrap((function(u){for(;;)switch(u.prev=u.next){case 0:if(null!==a){u.next=2;break}return u.abrupt("return",null);case 2:return u.abrupt("return",a.catch((function(u){return n(u)?c===e?Promise.reject(u):new Promise((function(e,n){setTimeout((function(){var r=t(o);i(c+1,r).then(e).catch(n)}),r*c)})):Promise.reject(u)})));case 3:case"end":return u.stop()}}),u)})))).apply(this,arguments)}var c=t(o);return null===c?null:i(1,c)}}function V(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return{current:t}}function Y(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 $(t,e,r,n){return et(Y(t,e,r),n)}function q(t,e,r,n,o,i){var u=Y(t,e,r);return u.indices=n,u.index=o,u.isInit=i,u}function Q(t,e,r,n,o){var i=Y(t,e,r);return i.args=n,o&&(i.promiseId=o),i}function X(t,e,r,n,o,i){var u=Q(t,e,r,n,i);return u.result=o,u.res=o,u}function Z(t,e,r,n,o,i,u){var c=et(Q(t,e,r,n,u),o);return c.abortSignal=i,c}function tt(t,e){var r=t;return r.state=e.current,r.s=e.current,r}function et(t,e){var r=t;return r.actions=e.current,r.a=e.current,r}function rt(t,e,r,n,o){var i,u=et(t,n);tt(t,e);var c=null==r||null===(i=r.current)||void 0===i?void 0:i.state;return u.derived=c,u.ds=c,u.notifyWarning=o,u}function nt(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 ot(t,e,r,n,o,i,u){return function(){if(i.current){for(var c=arguments.length,a=new Array(c),s=0;s<c;s++)a[s]=arguments[s];var f=Q(r,n,o,a),l=e(f);u(l,null,t,"effects",!1,f,!1)}else nt(t)}}function it(t,e,r,n,o,i,u,c,a,s){var f=X(r,n,o,s,void 0),l=!1;if(null!=e.effects){var p=e.effects(f);null===p?l=!0:a(p,void 0,t,"effects",!1,f,!1)}if(!l)if(e.debounceSideEffectsTimeout>0){var d=u.current[t];d&&clearTimeout(d),u.current[t]=setTimeout((function(){var o;null===(o=e.sideEffects)||void 0===o||o.call(e,rt(f,r,n,i,c.notifyWarning)),delete u.current[t]}),e.debounceSideEffectsTimeout)}else{var h;null===(h=e.sideEffects)||void 0===h||h.call(e,rt(f,r,n,i,c.notifyWarning))}}function ut(t,e,r,n,o,i,u,c,a,s){return function(){for(var f=arguments.length,l=new Array(f),p=0;p<f;p++)l[p]=arguments[p];if(u.current)if(e.debounceTimeout){var d=c.current[t];d&&clearTimeout(d),c.current[t]=setTimeout((function(){delete c.current[t],it(t,e,r,n,o,i,c,a,s,l)}),e.debounceTimeout)}else it(t,e,r,n,o,i,c,a,s,l);else nt(t)}}function ct(t,e,r,n){var o=t.action,i=t.stateRef,u=t.derivedStateRef,c=t.propsRef,a=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=X(i,u,c,n,r,e);o.effects&&(v=o.effects(y)),h(v,W(f.current,p,e,!1),p,"effects",!0,y,!1);var g,x=d.notifySuccess||T.notifySuccess;if(x)o.getSuccessMessage&&(g=o.getSuccessMessage(y)),g&&x(g);return delete a.current[p][e],o.sideEffects&&o.sideEffects(rt(y,i,u,s,T.notifyWarning)),ht(p,s.current,l.current),r}}function at(t,e,r,n){var o=t.action,i=t.stateRef,u=t.derivedStateRef,c=t.propsRef,a=t.actionsRef,s=t.loadingMapRef,f=t.errorMapRef,l=t.promisesRef,p=t.conflictActionsRef,d=t.actionName,h=t.options,v=t.setState;if(t.initializedRef.current){var y=null,g=function(t,e,r,n,o,i){var u=Q(t,e,r,n,i);return u.error=o,u.err=o,u}(i,u,c,n,r,e);o.errorEffects&&(y=o.errorEffects(g)),f.current=z(f.current,d,e,r),v(y,W(s.current,d,e,!1),d,"errorEffects",!0,g,!1);var x=!1;(null!=y||o.errorSideEffects)&&(x=!0);var m,b=h.notifyError||T.notifyError;if(b)o.getErrorMessage&&(m=o.getErrorMessage(g)),void 0===m&&!x&&T.getErrorMessage&&(m=T.getErrorMessage(r)),m&&(x=!0,b(m));return T.asyncErrorHandler(r,x||o.rejectPromiseOnError,i.current,c.current,d,n),delete l.current[d][e],o.errorSideEffects&&o.errorSideEffects(rt(g,i,u,a,T.notifyWarning)),ht(d,a.current,p.current),!x||o.rejectPromiseOnError?Promise.reject(r):Promise.resolve()}}function st(t){var e=t.action,n=t.stateRef,o=t.derivedStateRef,i=t.propsRef,u=t.actionsRef,c=t.promisesRef,a=t.loadingMapRef,s=t.errorMapRef,f=t.initializedRef,l=t.conflictActionsRef,p=t.actionName,d=t.setState;return function(){for(var h,v,y=arguments.length,g=new Array(y),x=0;x<y;x++)g[x]=arguments[x];if(!f.current)return nt(p),null;var m=c.current,b=e.conflictPolicy,w=void 0===b?r.KEEP_ALL:b,E=w===r.PARALLEL,_=null;if(E){if(!e.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");_=e.getPromiseId.apply(e,g)}else _=lt;if(!E&&null!==(h=m[p])&&void 0!==h&&h[_])return dt(m,l.current,p,w,g);var O=null,P=!1,S=Q(n,o,i,g,_);e.preEffects&&(O=e.preEffects(S))&&(P=!0,n.current=O);var j=e.abortable,R=e.retryCount,M=e.retryDelaySeed,A=e.isTriggerRetryError,C=j&&window.AbortController?new AbortController:null,I=H(e.getPromise,R?1+R:1,M,A||T.retryOnErrorFunction),N=null===(v=I(Z(n,o,i,g,u,null==C?void 0:C.signal)))||void 0===v?void 0:v.then((function(e){return ct(t,_,e,g)})).catch((function(e){return at(t,_,e,g)}));return null!=N&&(m[p]=k(k({},m[p]||{}),{},L({},_||lt,{abortController:C,promise:N,refArgs:w===r.REUSE&&g.length>0?[].concat(g):[]}))),s.current=z(s.current,p,_,null),d(null!=N||P?n.current:void 0,null==N?void 0:W(a.current,p,_,!0),p,"preEffects",!0,S,!1),N}}function ft(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=lt;if(Array.isArray(e)){var o=p(e,2);r=o[0];var i=o[1];n=void 0===i?lt:i}else r=e;var u=t[r];return null!=u&&(null!=u[n]&&u[n])}))}var lt="__def__";function pt(t,e){return t.length===e.length&&-1===t.findIndex((function(t,r){return e[r]!==t}))}function dt(t,e,n,o,i){var u=o;if(u===r.REUSE){if(pt(t[n][lt].refArgs,i))return t[n][lt].promise;u=r.KEEP_ALL}return new Promise((function(t,o){var c={resolve:t,reject:o,args:I(i),timestamp:Date.now()};switch(u){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]=[c];break;case r.KEEP_ALL:var a=e[n];a||(e[n]=a=[]),a.push(c);break;case r.PARALLEL:case r.REUSE:}}))}function ht(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,a(o.args));null==i?ht(t,e,r):i.then((function(n){null===n&&ht(t,e,r),o.resolve(n)})).catch((function(t){return o.reject(t)}))}}}function vt(t,e,r,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=T.comparator,u=r.current.deps,c=Y(t,null,e),a=Object.keys(n.derivedState);return r.current.state=a.reduce((function(t,e){var a=!1,s=u[e],f=n.derivedState[e].getDeps(c);return a=null==s||null!=f.find((function(t,e){return s.length<e||!i(s[e],t)})),o=o||a,u[e]=f,t[e]=a?n.derivedState[e].get(c):r.current.state[e],t}),{}),o}function yt(t,e,r,n,o,i,u,c){var a=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=V(t.current),p=[],d=T.comparator;s.forEach((function(t,o){var i=t.getDeps;if(i){var a=!1,s=[];if(c){if(!t.onMount)return;a=!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)"),a=!0):h.forEach((function(t,e){d(t,v[e])||(a=!0,s.push(e))}))}if(a){var y,g,x=q(l,e,r,s,o,c),m=null!==(y=null===(g=t.effects)||void 0===g?void 0:g.call(t,x))&&void 0!==y?y:null;null!=m&&(f=!0,l.current=m,u(l.current,void 0,"onPropsChange","effects",!1,x,!0,c)),t.sideEffects&&p.push({index:o,indices:s,ctx:x})}}})),!f&&a&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(t){s[t.index].sideEffects(k(k({},tt(et(t.ctx,o),l)),{},{indices:t.indices}))}))}else null!=(null==i?void 0:i.derivedState)&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function gt(t,e,r,n,o,i,u,c){if("onPropsChange"===o&&void 0===r)return{newState:null,newLoading:!1};if(t&&t.length>0){var a=t.reduce((function(t,e){var r=e.effects({isAsync:u,name:o,type:i,context:c},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:a.loading,newState:a.newState}}return{newState:r,newLoading:n}}export{lt as DEFAULT_PROMISE_ID,B as ParallelActionError,et as addContextActions,tt as addStateToContext,pt as areSameArgs,J as buildErrorMap,Y as buildInvocationContextBase,W as buildLoadingMap,$ as buildOnMountInvocationContext,q as buildOnPropChangeEffects,U as computeAsyncActionInput,vt as computeDerivedValues,V as createRef,st as decorateAsyncAction,ot as decorateSimpleSyncAction,ut as decorateSyncAction,T as globalConfig,N as isAsyncAction,F as isAsyncGetPromiseAction,K as isAsyncGetPromiseGetAction,ft as isLoadingImpl,G as isSimpleSyncAction,D as isSyncAction,yt as onPropChange,H as retryPromiseDecorator,gt as runMiddlewares,C as setGlobalConfig,z as updateErrorMap};
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})),u=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})),c=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})),a=t(e((function(t){t.exports=function(t){return o(t)||i(t)||u(t)||c()},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 u,c=t[Symbol.iterator]();!(n=(u=c.next()).done)&&(r.push(u.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.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)||u(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,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var u=t.apply(r,n);function c(t){e(u,o,i,c,a,"next",t)}function a(t){e(u,o,i,c,a,"throw",t)}c(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0}))),h=t(e((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0}))),v=e((function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0})),y=t(v),g=e((function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),x=t(e((function(t){t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e)},t.exports.default=t.exports,t.exports.__esModule=!0}))),m=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})),b=t(m),w=t(e((function(t){var e=m.default;t.exports=function(t,r){return!r||"object"!==e(r)&&"function"!=typeof r?v(t):r},t.exports.default=t.exports,t.exports.__esModule=!0}))),E=e((function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),_=t(E),O=e((function(t){t.exports=function(t){return-1!==Function.toString.call(t).indexOf("[native code]")},t.exports.default=t.exports,t.exports.__esModule=!0})),P=e((function(t){t.exports=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}},t.exports.default=t.exports,t.exports.__esModule=!0})),S=e((function(t){function e(r,n,o){return P()?(t.exports=e=Reflect.construct,t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&g(o,r.prototype),o},t.exports.default=t.exports,t.exports.__esModule=!0),e.apply(null,arguments)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),j=t(e((function(t){function e(r){var n="function"==typeof Map?new Map:void 0;return t.exports=e=function(t){if(null===t||!O(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,e)}function e(){return S(t,arguments,E(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),g(e,t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}))),L=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}))),R=e((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=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),u=new L(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 M()}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var c=P(u,r);if(c){if(c===v)continue;return c}}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 a=f(t,e,r);if("normal"===a.type){if(n=r.done?h:p,a.arg===v)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n=h,r.method="throw",r.arg=a.arg)}}}(t,r,u),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 x(){}var m={};m[i]=function(){return this};var b=Object.getPrototypeOf,w=b&&b(b(R([])));w&&w!==r&&n.call(w,i)&&(m=w);var E=x.prototype=y.prototype=Object.create(m);function _(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,u,c){var a=f(t[o],t,i);if("throw"!==a.type){var s=a.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):e.resolve(l).then((function(t){s.value=t,u(s)}),(function(t){return r("throw",t,u,c)}))}c(a.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 P(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,P(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 S(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 j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function R(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,u=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 u.next=u}}return{next:M}}function M(){return{value:e,done:!0}}return g.prototype=E.constructor=x,x.constructor=g,g.displayName=a(x,c,"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,x):(t.__proto__=x,a(t,c,"GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},_(O.prototype),O.prototype[u]=function(){return this},t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new O(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},_(E),a(E,c,"Generator"),E[i]=function(){return this},E.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=R,L.prototype={constructor:L,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(j),!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 c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var u=this.tryEntries[i],c=u.completion;if("root"===u.tryLoc)return o("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(a&&s){if(this.prev<u.catchLoc)return o(u.catchLoc,!0);if(this.prev<u.finallyLoc)return o(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return o(u.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return o(u.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 u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(u)},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),j(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;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:R(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)}}));function M(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=_(t);if(e){var o=_(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return w(this,r)}}function A(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 k(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?A(Object(r),!0).forEach((function(e){L(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):A(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 T={clone:function(t){return JSON.parse(JSON.stringify(t))},comparator:function(t,e){if(Object.is(t,e))return!0;if("object"!==b(t)||null===t||"object"!==b(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 C(t){Object.keys(t).forEach((function(e){null!=t[e]&&(T[e]=t[e])}))}function I(t){try{return T.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 N(t){return!(t instanceof Function)&&(t.hasOwnProperty("getPromise")||t.hasOwnProperty("getGetPromise"))}function G(t){return"function"==typeof t}function D(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function F(t){return"function"!=typeof t&&t.hasOwnProperty("getPromise")&&!t.hasOwnProperty("getGetPromise")}function K(t){return"function"!=typeof t&&!t.hasOwnProperty("getPromise")&&t.hasOwnProperty("getGetPromise")}function U(t){return K(t)?k(k({},t),{},{getPromise:t.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):t}function W(t,e,r,n){return k(k({},t),{},L({},e,n?k(k({},t[e]||{}),{},L({},r,n)):k(k({},t[e]),{},L({},r,!1))))}function z(t,e,r,n){return k(k({},t),{},L({},e,n?k(k({},t[e]||{}),{},L({},r,n)):k(k({},t[e]),{},L({},r,void 0))))}var B=function(t){x(r,t);var e=M(r);function r(t){var n;return h(this,r),n=e.call(this,"Error"),L(y(n),"promiseIds",void 0),n.promiseIds=t,Object.setPrototypeOf(y(n),r.prototype),n}return r}(j(Error));function J(t){return Object.keys(t).reduce((function(e,r){var n=t[r];if(null==n[lt]);else if(n[lt])e[r]=n[lt];else{var o=Object.keys(n).reduce((function(t,e){return null!=n[e]&&(t.hasErr=!0,t.map[e]=n[e]),t}),{hasErr:!1,map:{}});o.hasErr&&(e[r]=new B(o.map))}return e}),{})}function H(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 u.apply(this,arguments)}function u(){return(u=d(R.mark((function u(c,a){return R.wrap((function(u){for(;;)switch(u.prev=u.next){case 0:if(null!==a){u.next=2;break}return u.abrupt("return",null);case 2:return u.abrupt("return",a.catch((function(u){return n(u)?c===e?Promise.reject(u):new Promise((function(e,n){setTimeout((function(){var r=t(o);i(c+1,r).then(e).catch(n)}),r*c)})):Promise.reject(u)})));case 3:case"end":return u.stop()}}),u)})))).apply(this,arguments)}var c=t(o);return null===c?null:i(1,c)}}function V(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return{current:t}}function Y(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 $(t,e,r,n){return et(Y(t,e,r),n)}function q(t,e,r,n,o,i){var u=Y(t,e,r);return u.indices=n,u.index=o,u.isInit=i,u}function Q(t,e,r,n,o){var i=Y(t,e,r);return i.args=n,o&&(i.promiseId=o),i}function X(t,e,r,n,o,i){var u=Q(t,e,r,n,i);return u.result=o,u.res=o,u}function Z(t,e,r,n,o,i,u){var c=et(Q(t,e,r,n,u),o);return c.abortSignal=i,c}function tt(t,e){var r=t;return r.state=e.current,r.s=e.current,r}function et(t,e){var r=t;return r.actions=e.current,r.a=e.current,r}function rt(t,e,r,n,o){var i,u=et(t,n);tt(t,e);var c=null==r||null===(i=r.current)||void 0===i?void 0:i.state;return u.derived=c,u.ds=c,u.notifyWarning=o,u}function nt(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 ot(t,e,r,n,o,i,u){return function(){if(i.current){for(var c=arguments.length,a=new Array(c),s=0;s<c;s++)a[s]=arguments[s];var f=Q(r,n,o,a),l=e(f);u(l,null,t,"effects",!1,f,!1)}else nt(t)}}function it(t,e,r,n,o,i,u,c,a,s){var f=X(r,n,o,s,void 0),l=!1;if(null!=e.effects){var p=e.effects(f);null===p?l=!0:a(p,void 0,t,"effects",!1,f,!1)}if(!l)if(e.debounceSideEffectsTimeout>0){var d=u.current[t];d&&clearTimeout(d),u.current[t]=setTimeout((function(){var o;null===(o=e.sideEffects)||void 0===o||o.call(e,rt(f,r,n,i,c.notifyWarning)),delete u.current[t]}),e.debounceSideEffectsTimeout)}else{var h;null===(h=e.sideEffects)||void 0===h||h.call(e,rt(f,r,n,i,c.notifyWarning))}}function ut(t,e,r,n,o,i,u,c,a,s){return function(){for(var f=arguments.length,l=new Array(f),p=0;p<f;p++)l[p]=arguments[p];if(u.current)if(e.debounceTimeout){var d=c.current[t];d&&clearTimeout(d),c.current[t]=setTimeout((function(){delete c.current[t],it(t,e,r,n,o,i,c,a,s,l)}),e.debounceTimeout)}else it(t,e,r,n,o,i,c,a,s,l);else nt(t)}}function ct(t,e,r,n){var o=t.action,i=t.stateRef,u=t.derivedStateRef,c=t.propsRef,a=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=X(i,u,c,n,r,e);o.effects&&(v=o.effects(y)),h(v,W(f.current,p,e,!1),p,"effects",!0,y,!1);var g,x=d.notifySuccess||T.notifySuccess;if(x)o.getSuccessMessage&&(g=o.getSuccessMessage(y)),g&&x(g);return delete a.current[p][e],o.sideEffects&&o.sideEffects(rt(y,i,u,s,T.notifyWarning)),ht(p,s.current,l.current),r}}function at(t,e,r,n){var o=t.action,i=t.stateRef,u=t.derivedStateRef,c=t.propsRef,a=t.actionsRef,s=t.loadingMapRef,f=t.errorMapRef,l=t.promisesRef,p=t.conflictActionsRef,d=t.actionName,h=t.options,v=t.setState;if(t.initializedRef.current){var y=null,g=function(t,e,r,n,o,i){var u=Q(t,e,r,n,i);return u.error=o,u.err=o,u}(i,u,c,n,r,e);o.errorEffects&&(y=o.errorEffects(g)),f.current=z(f.current,d,e,r),v(y,W(s.current,d,e,!1),d,"errorEffects",!0,g,!1);var x=!1;(null!=y||o.errorSideEffects||o.isErrorManaged)&&(x=!0);var m,b=h.notifyError||T.notifyError;if(b)o.getErrorMessage&&(m=o.getErrorMessage(g)),void 0===m&&!x&&T.getErrorMessage&&(m=T.getErrorMessage(r)),m&&(x=!0,b(m));return T.asyncErrorHandler(r,x||o.rejectPromiseOnError,i.current,c.current,d,n),delete l.current[d][e],o.errorSideEffects&&o.errorSideEffects(rt(g,i,u,a,T.notifyWarning)),ht(d,a.current,p.current),!x||o.rejectPromiseOnError?Promise.reject(r):Promise.resolve()}}function st(t){var e=t.action,n=t.stateRef,o=t.derivedStateRef,i=t.propsRef,u=t.actionsRef,c=t.promisesRef,a=t.loadingMapRef,s=t.errorMapRef,f=t.initializedRef,l=t.conflictActionsRef,p=t.actionName,d=t.setState;return function(){for(var h,v,y=arguments.length,g=new Array(y),x=0;x<y;x++)g[x]=arguments[x];if(!f.current)return nt(p),null;var m=c.current,b=e.conflictPolicy,w=void 0===b?r.KEEP_ALL:b,E=w===r.PARALLEL,_=null;if(E){if(!e.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");_=e.getPromiseId.apply(e,g)}else _=lt;if(!E&&null!==(h=m[p])&&void 0!==h&&h[_])return dt(m,l.current,p,w,g);var O=null,P=!1,S=Q(n,o,i,g,_);e.preEffects&&(O=e.preEffects(S))&&(P=!0,n.current=O);var j=e.abortable,R=e.retryCount,M=e.retryDelaySeed,A=e.isTriggerRetryError,C=j&&window.AbortController?new AbortController:null,I=H(e.getPromise,R?1+R:1,M,A||T.retryOnErrorFunction),N=null===(v=I(Z(n,o,i,g,u,null==C?void 0:C.signal)))||void 0===v?void 0:v.then((function(e){return ct(t,_,e,g)})).catch((function(e){return at(t,_,e,g)}));return null!=N&&(m[p]=k(k({},m[p]||{}),{},L({},_||lt,{abortController:C,promise:N,refArgs:w===r.REUSE&&g.length>0?[].concat(g):[]}))),s.current=z(s.current,p,_,null),d(null!=N||P?n.current:void 0,null==N?void 0:W(a.current,p,_,!0),p,"preEffects",!0,S,!1),N}}function ft(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=lt;if(Array.isArray(e)){var o=p(e,2);r=o[0];var i=o[1];n=void 0===i?lt:i}else r=e;var u=t[r];return null!=u&&(null!=u[n]&&u[n])}))}var lt="__def__";function pt(t,e){return t.length===e.length&&-1===t.findIndex((function(t,r){return e[r]!==t}))}function dt(t,e,n,o,i){var u=o;if(u===r.REUSE){if(pt(t[n][lt].refArgs,i))return t[n][lt].promise;u=r.KEEP_ALL}return new Promise((function(t,o){var c={resolve:t,reject:o,args:I(i),timestamp:Date.now()};switch(u){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]=[c];break;case r.KEEP_ALL:var a=e[n];a||(e[n]=a=[]),a.push(c);break;case r.PARALLEL:case r.REUSE:}}))}function ht(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,a(o.args));null==i?ht(t,e,r):i.then((function(n){null===n&&ht(t,e,r),o.resolve(n)})).catch((function(t){return o.reject(t)}))}}}function vt(t,e,r,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=T.comparator,u=r.current.deps,c=Y(t,null,e),a=Object.keys(n.derivedState);return r.current.state=a.reduce((function(t,e){var a=!1,s=u[e],f=n.derivedState[e].getDeps(c);return a=null==s||null!=f.find((function(t,e){return s.length<e||!i(s[e],t)})),o=o||a,u[e]=f,t[e]=a?n.derivedState[e].get(c):r.current.state[e],t}),{}),o}function yt(t,e,r,n,o,i,u,c){var a=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=V(t.current),p=[],d=T.comparator;s.forEach((function(t,o){var i=t.getDeps;if(i){var a=!1,s=[];if(c){if(!t.onMount)return;a=!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)"),a=!0):h.forEach((function(t,e){d(t,v[e])||(a=!0,s.push(e))}))}if(a){var y,g,x=q(l,e,r,s,o,c),m=null!==(y=null===(g=t.effects)||void 0===g?void 0:g.call(t,x))&&void 0!==y?y:null;null!=m&&(f=!0,l.current=m,u(l.current,void 0,"onPropsChange","effects",!1,x,!0,c)),t.sideEffects&&p.push({index:o,indices:s,ctx:x})}}})),!f&&a&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(t){s[t.index].sideEffects(k(k({},tt(et(t.ctx,o),l)),{},{indices:t.indices}))}))}else null!=(null==i?void 0:i.derivedState)&&u(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function gt(t,e,r,n,o,i,u,c){if("onPropsChange"===o&&void 0===r)return{newState:null,newLoading:!1};if(t&&t.length>0){var a=t.reduce((function(t,e){var r=e.effects({isAsync:u,name:o,type:i,context:c},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:a.loading,newState:a.newState}}return{newState:r,newLoading:n}}export{lt as DEFAULT_PROMISE_ID,B as ParallelActionError,et as addContextActions,tt as addStateToContext,pt as areSameArgs,J as buildErrorMap,Y as buildInvocationContextBase,W as buildLoadingMap,$ as buildOnMountInvocationContext,q as buildOnPropChangeEffects,U as computeAsyncActionInput,vt as computeDerivedValues,V as createRef,st as decorateAsyncAction,ot as decorateSimpleSyncAction,ut as decorateSyncAction,T as globalConfig,N as isAsyncAction,F as isAsyncGetPromiseAction,K as isAsyncGetPromiseGetAction,ft as isLoadingImpl,G as isSimpleSyncAction,D as isSyncAction,yt as onPropChange,H as retryPromiseDecorator,gt as runMiddlewares,C as setGlobalConfig,z as updateErrorMap};
2
2
  //# sourceMappingURL=impl.es.js.map