state-decorator 6.10.0 → 7.0.0-beta.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 +317 -140
- package/es/impl.js +1 -1
- package/es/index.d.ts +35 -37
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/middlewares.js +1 -1
- package/es/types.d.ts +9 -9
- package/es/v5_test.js +1 -1
- package/impl.js +1 -1
- package/index.d.ts +35 -37
- package/index.js +1 -1
- package/middlewares.js +1 -1
- package/package.json +1 -1
- package/types.d.ts +9 -9
- package/v5_test.js +1 -1
package/es/impl.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=function(r,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])})(r,n)};var r,n=function(){return(n=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function t(e,r,n,t){return new(n||(n=Promise))((function(o,i){function c(e){try{a(t.next(e))}catch(e){i(e)}}function u(e){try{a(t.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof n?r:new n((function(e){e(r)}))).then(c,u)}a((t=t.apply(e,r||[])).next())}))}function o(e,r){var n,t,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,t&&(o=2&i[0]?t.return:i[0]?t.throw||((o=t.return)&&o.call(t),0):t.next)&&!(o=o.call(t,i[1])).done)return o;switch(t=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,t=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],t=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,n){if(n||2===arguments.length)for(var t,o=0,i=r.length;o<i;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var n=Object.keys(e),t=Object.keys(r);if(n.length!==t.length)return!1;for(var o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(r,n[o])||!Object.is(e[n[o]],r[n[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))}function a(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function l(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))}function f(e){return"function"==typeof e}function s(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function d(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function v(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function p(e){return v(e)?n(n({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e}function g(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=!1,a)),u))}function y(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=void 0,a)),u))}var h=function(r){function n(e){var t=r.call(this,"Error")||this;return t.promiseIds=e,Object.setPrototypeOf(t,n.prototype),t}return function(r,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}(n,r),n}(Error);function E(e){return Object.keys(e).reduce((function(r,n){var t=e[n];if(null==t[G]);else if(t[G])r[n]=t[G];else{var o=Object.keys(t).reduce((function(e,r){return null!=t[r]&&(e.hasErr=!0,e.map[r]=t[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[n]=new h(o.map))}return r}),{})}function m(e,r,n,i){return void 0===r&&(r=1),void 0===n&&(n=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,l){return t(this,void 0,void 0,(function(){return o(this,(function(t){return null===l?[2,null]:[2,l.catch((function(t){return i(t)?a===r?Promise.reject(t):new Promise((function(r,t){setTimeout((function(){var n=e(c);u(a+1,n).then(r).catch(t)}),n*a)})):Promise.reject(t)}))]}))}))}(1,u)}}function P(e){return void 0===e&&(e=null),{current:e}}function w(e,r,n){var t,o;return{state:e.current,s:e.current,ds:null===(t=null==r?void 0:r.current)||void 0===t?void 0:t.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:n.current,p:n.current}}function S(e,r,n,t){return L(w(e,r,n),t)}function b(e,r,n,t,o,i){var c=w(e,r,n);return c.indices=t,c.index=o,c.isInit=i,c}function R(e,r,n,t,o){var i=w(e,r,n);return i.args=t,o&&(i.promiseId=o),i}function O(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.result=o,c.res=o,c}function A(e,r,n,t,o,i,c){var u=L(R(e,r,n,t,c),o);return u.abortSignal=i,u}function j(e,r){var n=e;return n.state=r.current,n.s=r.current,n}function L(e,r){var n=e;return n.actions=r.current,n.a=r.current,n}function C(e,r,n,t,o){var i,c=L(e,t);j(e,r);var u=null===(i=null==n?void 0:n.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function _(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function k(e,r,n,t,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var l=R(n,t,o,u),f=r(l);c(f,null,e,"effects",!1,l,!1)}else _(e)}}function T(e,r,n,t,o,i,c,u,a,l){var f,s=O(n,t,o,l,void 0),d=!1;if(null!=r.effects){var v=r.effects(s);null===v?d=!0:a(v,void 0,e,"effects",!1,s,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var p=c.current[e];p&&clearTimeout(p),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,C(s,n,t,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(f=r.sideEffects)||void 0===f||f.call(r,C(s,n,t,i,u.notifyWarning))}function M(e,r,n,t,o,i,c,u,a,l){return function(){for(var f=[],s=0;s<arguments.length;s++)f[s]=arguments[s];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],T(e,r,n,t,o,i,u,a,l,f)}),r.debounceTimeout)}else T(e,r,n,t,o,i,u,a,l,f);else _(e)}}function x(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,s=e.loadingMapRef,d=e.conflictActionsRef,v=e.actionName,p=e.options,y=e.setState;if(e.initializedRef.current){var h=null,E=O(i,u,a,t,n,r);o.effects&&(h=o.effects(E)),y(h,g(s.current,v,r,!1),v,"effects",!0,E,!1);var m=p.notifySuccess||c.notifySuccess;if(m){var P=void 0;o.getSuccessMessage&&(P=o.getSuccessMessage(E)),P&&m(P)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(C(E,i,u,f,c.notifyWarning)),U(v,f.current,d.current),n}}function N(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.loadingMapRef,s=e.errorMapRef,d=e.promisesRef,v=e.conflictActionsRef,p=e.actionName,h=e.options,E=e.setState;if(e.initializedRef.current){var m=null,P=function(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.error=o,c.err=o,c}(i,u,a,t,n,r);o.errorEffects&&(m=o.errorEffects(P)),s.current=y(s.current,p,r,n),E(m,g(f.current,p,r,!1),p,"errorEffects",!0,P,!1);var w=!1;(null!=m||o.errorSideEffects||o.isErrorManaged)&&(w=!0);var S=h.notifyError||c.notifyError;if(S){var b=void 0;o.getErrorMessage&&(b=o.getErrorMessage(P)),void 0===b&&!w&&c.getErrorMessage&&(b=c.getErrorMessage(n)),b&&(w=!0,S(b))}return c.asyncErrorHandler(n,w||o.rejectPromiseOnError,i.current,a.current,p,t),delete d.current[p][r],o.errorSideEffects&&o.errorSideEffects(C(P,i,u,l,c.notifyWarning)),U(p,l.current,v.current),!w||o.rejectPromiseOnError?Promise.reject(n):Promise.resolve()}}function I(e){var t=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.promisesRef,s=e.loadingMapRef,d=e.errorMapRef,v=e.initializedRef,p=e.conflictActionsRef,h=e.actionName,E=e.setState;return function(){for(var P,w,S,b=[],O=0;O<arguments.length;O++)b[O]=arguments[O];if(!v.current)return _(h),null;var j=f.current,L=t.conflictPolicy,C=void 0===L?r.KEEP_ALL:L,k=C===r.PARALLEL,T=null;if(k){if(!t.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");T=t.getPromiseId.apply(t,b)}else T=G;if(!k&&(null===(w=j[h])||void 0===w?void 0:w[T]))return W(j,p.current,h,C,b);var M=null,I=!1,D=R(o,u,a,b,T);t.preEffects&&(M=t.preEffects(D))&&(I=!0,o.current=M);var K=t.abortable,U=t.retryCount,z=t.retryDelaySeed,F=t.isTriggerRetryError,J=K&&window.AbortController?new AbortController:null,H=m(t.getPromise,U?1+U:1,z,F||c.retryOnErrorFunction),V=null===(S=H(A(o,u,a,b,l,null==J?void 0:J.signal)))||void 0===S?void 0:S.then((function(r){return x(e,T,r,b)})).catch((function(r){return N(e,T,r,b)}));return null!=V&&(j[h]=n(n({},j[h]||{}),((P={})[T||G]={abortController:J,promise:V,refArgs:C===r.REUSE&&b.length>0?i([],b,!0):[]},P))),d.current=y(d.current,h,T,null),E(null!=V||I?o.current:void 0,null==V?void 0:g(s.current,h,T,!0),h,"preEffects",!0,D,!1),V}}function D(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return r.some((function(r){var n,t=null,o=G;Array.isArray(r)?(t=r[0],o=void 0===(n=r[1])?G:n):t=r;var i=e[t];return null!=i&&(null!=i[o]&&i[o])}))}var G="__def__";function K(e,r){return e.length===r.length&&-1===e.findIndex((function(e,n){return r[n]!==e}))}function W(e,n,t,o,i){var c=o;if(c===r.REUSE){if(K(e[t][G].refArgs,i))return e[t][G].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var u={resolve:e,reject:o,args:a(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(t," is already ongoing.")));break;case r.KEEP_LAST:n[t]=[u];break;case r.KEEP_ALL:var l=n[t];l||(n[t]=l=[]),l.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function U(e,r,n){var t=n[e];if(t&&t.length>0){var o=n[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?U(e,r,n):i.then((function(t){null===t&&U(e,r,n),o.resolve(t)})).catch((function(e){return o.reject(e)}))}}}function z(e,r,n,t){if(null==(null==t?void 0:t.derivedState))return!1;var o=!1,i=c.comparator,u=n.current.deps,a=w(e,null,r),l=Object.keys(t.derivedState);return n.current.state=l.reduce((function(e,r){var c=!1,l=u[r],f=t.derivedState[r].getDeps(a);return c=null==l||null!=f.find((function(e,r){return l.length<r||!i(l[r],e)})),o=o||c,u[r]=f,e[r]=c?t.derivedState[r].get(a):n.current.state[r],e}),{}),o}function F(e,r,t,o,i,u,a,l){var f=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var s;s=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=P(e.current),p=[],g=c.comparator;s.forEach((function(e,n){var i,c,u=e.getDeps;if(u){var f=!1,s=[];if(l){if(!e.onMount)return;f=!0}else{var y=u(o),h=u(t.current);y.length!==h.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),f=!0):y.forEach((function(e,r){g(e,h[r])||(f=!0,s.push(r))}))}if(f){var E=b(v,r,t,s,n,l),m=null!==(c=null===(i=e.effects)||void 0===i?void 0:i.call(e,E))&&void 0!==c?c:null;null!=m&&(d=!0,v.current=m,a(v.current,void 0,"onPropsChange","effects",!1,E,!0,l)),e.sideEffects&&p.push({index:n,indices:s,ctx:E})}}})),!d&&f&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(e){s[e.index].sideEffects(n(n({},j(L(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function J(e,r,n,t,o,i,c,u){if("onPropsChange"===o&&void 0===n)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var n=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,t);return{newState:(null==n?void 0:n.state)||e.newState,oldState:(null==n?void 0:n.state)?e.newState:e.oldState,loading:null==(null==n?void 0:n.loading)?e.loading:n.loading}}),{oldState:r,newState:n,loading:t});return{newLoading:a.loading,newState:a.newState}}return{newState:n,newLoading:t}}export{G as DEFAULT_PROMISE_ID,h as ParallelActionError,L as addContextActions,j as addStateToContext,K as areSameArgs,E as buildErrorMap,w as buildInvocationContextBase,g as buildLoadingMap,S as buildOnMountInvocationContext,b as buildOnPropChangeEffects,p as computeAsyncActionInput,z as computeDerivedValues,P as createRef,I as decorateAsyncAction,k as decorateSimpleSyncAction,M as decorateSyncAction,c as globalConfig,l as isAsyncAction,d as isAsyncGetPromiseAction,v as isAsyncGetPromiseGetAction,D as isLoadingImpl,f as isSimpleSyncAction,s as isSyncAction,F as onPropChange,m as retryPromiseDecorator,J as runMiddlewares,u as setGlobalConfig,y as updateErrorMap};
|
|
1
|
+
var e=function(r,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])})(r,n)};var r,n=function(){return(n=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function t(e,r,n,t){return new(n||(n=Promise))((function(o,i){function c(e){try{a(t.next(e))}catch(e){i(e)}}function u(e){try{a(t.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof n?r:new n((function(e){e(r)}))).then(c,u)}a((t=t.apply(e,r||[])).next())}))}function o(e,r){var n,t,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,t&&(o=2&i[0]?t.return:i[0]?t.throw||((o=t.return)&&o.call(t),0):t.next)&&!(o=o.call(t,i[1])).done)return o;switch(t=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,t=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],t=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,n){if(n||2===arguments.length)for(var t,o=0,i=r.length;o<i;o++)!t&&o in r||(t||(t=Array.prototype.slice.call(r,0,o)),t[o]=r[o]);return e.concat(t||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var n=Object.keys(e),t=Object.keys(r);if(n.length!==t.length)return!1;for(var o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(r,n[o])||!Object.is(e[n[o]],r[n[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))}function a(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function l(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))}function f(e){return"function"==typeof e}function s(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function d(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")}function v(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function p(e){return v(e)?n(n({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e}function g(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=!1,a)),u))}function y(e,r,t,o){var i,c,u,a;return n(n({},e),o?((i={})[r]=n(n({},e[r]||{}),((c={})[t]=o,c)),i):((u={})[r]=n(n({},e[r]),((a={})[t]=void 0,a)),u))}var h=function(r){function n(e){var t=r.call(this,"Error")||this;return t.promiseIds=e,Object.setPrototypeOf(t,n.prototype),t}return function(r,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}(n,r),n}(Error);function E(e){return Object.keys(e).reduce((function(r,n){var t=e[n];if(null==t[K]);else if(t[K])r[n]=t[K];else{var o=Object.keys(t).reduce((function(e,r){return null!=t[r]&&(e.hasErr=!0,e.map[r]=t[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[n]=new h(o.map))}return r}),{})}function m(e,r,n,i){return void 0===r&&(r=1),void 0===n&&(n=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,l){return t(this,void 0,void 0,(function(){return o(this,(function(t){return null===l?[2,null]:[2,l.catch((function(t){return i(t)?a===r?Promise.reject(t):new Promise((function(r,t){setTimeout((function(){var n=e(c);u(a+1,n).then(r).catch(t)}),n*a)})):Promise.reject(t)}))]}))}))}(1,u)}}function P(e){return void 0===e&&(e=null),{current:e}}function w(e,r,n){var t,o;return{state:e.current,s:e.current,ds:null===(t=null==r?void 0:r.current)||void 0===t?void 0:t.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:n.current,p:n.current}}function S(e,r,n,t){return L(w(e,r,n),t)}function b(e,r,n,t,o,i){var c=w(e,r,n);return c.indices=t,c.index=o,c.isInit=i,c}function R(e,r,n,t,o){var i=w(e,r,n);return i.args=t,o&&(i.promiseId=o),i}function O(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.result=o,c.res=o,c}function A(e,r,n,t,o,i,c){var u=L(R(e,r,n,t,c),o);return u.abortSignal=i,u}function j(e,r){var n=e;return n.state=r.current,n.s=r.current,n}function L(e,r){var n=e;return n.actions=r.current,n.a=r.current,n}function C(e,r,n,t,o){var i,c=L(e,t);j(e,r);var u=null===(i=null==n?void 0:n.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function _(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function k(e,r){return null==r?null:n(n({},e.current),r)}function T(e,r,n,t,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var l=R(n,t,o,u),f=k(n,r(l));c(f,null,e,"effects",!1,l,!1)}else _(e)}}function M(e,r,n,t,o,i,c,u,a,l){var f,s=O(n,t,o,l,void 0),d=!1;if(null!=r.effects){var v=k(n,r.effects(s));null===v?d=!0:a(v,void 0,e,"effects",!1,s,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var p=c.current[e];p&&clearTimeout(p),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,C(s,n,t,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(f=r.sideEffects)||void 0===f||f.call(r,C(s,n,t,i,u.notifyWarning))}function x(e,r,n,t,o,i,c,u,a,l){return function(){for(var f=[],s=0;s<arguments.length;s++)f[s]=arguments[s];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],M(e,r,n,t,o,i,u,a,l,f)}),r.debounceTimeout)}else M(e,r,n,t,o,i,u,a,l,f);else _(e)}}function N(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,s=e.loadingMapRef,d=e.conflictActionsRef,v=e.actionName,p=e.options,y=e.setState;if(e.initializedRef.current){var h=null,E=O(i,u,a,t,n,r);o.effects&&(h=k(i,o.effects(E))),y(h,g(s.current,v,r,!1),v,"effects",!0,E,!1);var m=p.notifySuccess||c.notifySuccess;if(m){var P=void 0;o.getSuccessMessage&&(P=o.getSuccessMessage(E)),P&&m(P)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(C(E,i,u,f,c.notifyWarning)),z(v,f.current,d.current),n}}function I(e,r,n,t){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.loadingMapRef,s=e.errorMapRef,d=e.promisesRef,v=e.conflictActionsRef,p=e.actionName,h=e.options,E=e.setState;if(e.initializedRef.current){var m=null,P=function(e,r,n,t,o,i){var c=R(e,r,n,t,i);return c.error=o,c.err=o,c}(i,u,a,t,n,r);o.errorEffects&&(m=k(i,o.errorEffects(P))),s.current=y(s.current,p,r,n),E(m,g(f.current,p,r,!1),p,"errorEffects",!0,P,!1);var w=!1;(null!=m||o.errorSideEffects||o.isErrorManaged)&&(w=!0);var S=h.notifyError||c.notifyError;if(S){var b=void 0;o.getErrorMessage&&(b=o.getErrorMessage(P)),void 0===b&&!w&&c.getErrorMessage&&(b=c.getErrorMessage(n)),b&&(w=!0,S(b))}return c.asyncErrorHandler(n,w||o.rejectPromiseOnError,i.current,a.current,p,t),delete d.current[p][r],o.errorSideEffects&&o.errorSideEffects(C(P,i,u,l,c.notifyWarning)),z(p,l.current,v.current),!w||o.rejectPromiseOnError?Promise.reject(n):Promise.resolve()}}function D(e){var t=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.actionsRef,f=e.promisesRef,s=e.loadingMapRef,d=e.errorMapRef,v=e.initializedRef,p=e.conflictActionsRef,h=e.actionName,E=e.setState;return function(){for(var P,w,S,b=[],O=0;O<arguments.length;O++)b[O]=arguments[O];if(!v.current)return _(h),null;var j=f.current,L=t.conflictPolicy,C=void 0===L?r.KEEP_ALL:L,T=C===r.PARALLEL,M=null;if(T){if(!t.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");M=t.getPromiseId.apply(t,b)}else M=K;if(!T&&(null===(w=j[h])||void 0===w?void 0:w[M]))return U(j,p.current,h,C,b);var x=null,D=!1,G=R(o,u,a,b,M);t.preEffects&&(x=k(o,t.preEffects(G)))&&(D=!0,o.current=x);var W=t.abortable,z=t.retryCount,F=t.retryDelaySeed,J=t.isTriggerRetryError,H=W&&window.AbortController?new AbortController:null,V=m(t.getPromise,z?1+z:1,F,J||c.retryOnErrorFunction),q=null===(S=V(A(o,u,a,b,l,null==H?void 0:H.signal)))||void 0===S?void 0:S.then((function(r){return N(e,M,r,b)})).catch((function(r){return I(e,M,r,b)}));return null!=q&&(j[h]=n(n({},j[h]||{}),((P={})[M||K]={abortController:H,promise:q,refArgs:C===r.REUSE&&b.length>0?i([],b,!0):[]},P))),d.current=y(d.current,h,M,null),E(null!=q||D?o.current:void 0,null==q?void 0:g(s.current,h,M,!0),h,"preEffects",!0,G,!1),q}}function G(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return r.some((function(r){var n,t=null,o=K;Array.isArray(r)?(t=r[0],o=void 0===(n=r[1])?K:n):t=r;var i=e[t];return null!=i&&(null!=i[o]&&i[o])}))}var K="__def__";function W(e,r){return e.length===r.length&&-1===e.findIndex((function(e,n){return r[n]!==e}))}function U(e,n,t,o,i){var c=o;if(c===r.REUSE){if(W(e[t][K].refArgs,i))return e[t][K].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var u={resolve:e,reject:o,args:a(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(t," is already ongoing.")));break;case r.KEEP_LAST:n[t]=[u];break;case r.KEEP_ALL:var l=n[t];l||(n[t]=l=[]),l.push(u);break;case r.PARALLEL:case r.REUSE:}}))}function z(e,r,n){var t=n[e];if(t&&t.length>0){var o=n[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?z(e,r,n):i.then((function(t){null===t&&z(e,r,n),o.resolve(t)})).catch((function(e){return o.reject(e)}))}}}function F(e,r,n,t){if(null==(null==t?void 0:t.derivedState))return!1;var o=!1,i=c.comparator,u=n.current.deps,a=w(e,null,r),l=Object.keys(t.derivedState);return n.current.state=l.reduce((function(e,r){var c=!1,l=u[r],f=t.derivedState[r].getDeps(a);return c=null==l||null!=f.find((function(e,r){return l.length<r||!i(l[r],e)})),o=o||c,u[r]=f,e[r]=c?t.derivedState[r].get(a):n.current.state[r],e}),{}),o}function J(e,r,t,o,i,u,a,l){var f=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var s;s=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=P(e.current),p=[],g=c.comparator;s.forEach((function(n,i){var c,u=n.getDeps;if(u){var f=!1,s=[];if(l){if(!n.onMount)return;f=!0}else{var y=u(o),h=u(t.current);y.length!==h.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),f=!0):y.forEach((function(e,r){g(e,h[r])||(f=!0,s.push(r))}))}if(f){var E=b(v,r,t,s,i,l),m=k(e,null===(c=n.effects)||void 0===c?void 0:c.call(n,E));null!=m&&(d=!0,v.current=m,a(v.current,void 0,"onPropsChange","effects",!1,E,!0,l)),n.sideEffects&&p.push({index:i,indices:s,ctx:E})}}})),!d&&f&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),p.length>0&&p.forEach((function(e){s[e.index].sideEffects(n(n({},j(L(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)}function H(e,r,n,t,o,i,c,u){if("onPropsChange"===o&&void 0===n)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var n=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,t);return{newState:(null==n?void 0:n.state)||e.newState,oldState:(null==n?void 0:n.state)?e.newState:e.oldState,loading:null==(null==n?void 0:n.loading)?e.loading:n.loading}}),{oldState:r,newState:n,loading:t});return{newLoading:a.loading,newState:a.newState}}return{newState:n,newLoading:t}}export{K as DEFAULT_PROMISE_ID,h as ParallelActionError,L as addContextActions,j as addStateToContext,W as areSameArgs,E as buildErrorMap,w as buildInvocationContextBase,g as buildLoadingMap,S as buildOnMountInvocationContext,b as buildOnPropChangeEffects,p as computeAsyncActionInput,F as computeDerivedValues,P as createRef,D as decorateAsyncAction,T as decorateSimpleSyncAction,x as decorateSyncAction,c as globalConfig,l as isAsyncAction,d as isAsyncGetPromiseAction,v as isAsyncGetPromiseGetAction,G as isLoadingImpl,f as isSimpleSyncAction,s as isSyncAction,J as onPropChange,m as retryPromiseDecorator,H as runMiddlewares,u as setGlobalConfig,y as updateErrorMap};
|
|
2
2
|
//# sourceMappingURL=impl.js.map
|
package/es/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
|
+
import { Context } from 'react';
|
|
15
16
|
import { setGlobalConfig, GlobalConfig, ParallelActionError } from './impl';
|
|
16
17
|
import { DecoratedActions, StoreActions, AsyncAction, SyncAction, SimpleSyncAction, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, StoreOptions, AsyncActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, ContextState, ConflictPolicy, Middleware, AbortActionCallback, MiddlewareFactory, LoadingProps } from './types';
|
|
17
18
|
export { DecoratedActions, StoreActions, LoadingMap, ErrorMap, LoadingParallelMap, ErrorParallelMap, ParallelActionError, StoreOptions, AsyncActionPromise as AsynchActionPromise, InvocationContext, GetPromiseInvocationContext, EffectsInvocationContext, InvocationContextActions, WarningNotifyFunc, ErrorEffectsInvocationContext, OnMountInvocationContext, ContextBase, OnPropsChangeEffectsContext, SyncAction, AsyncAction, SimpleSyncAction, ContextState, ConflictPolicy, GlobalConfig, Middleware, setGlobalConfig, LoadingProps, AbortActionCallback, };
|
|
@@ -90,66 +91,63 @@ export declare function createStore<S, A extends DecoratedActions, P, DS = {}>(g
|
|
|
90
91
|
* A react hook to get a state slice. Will be refresh if, and only if, one property of the slice has changed
|
|
91
92
|
* @param store The store to listen to.
|
|
92
93
|
* @param slicerFunc A function that returns a state slice
|
|
93
|
-
* @param comparator An optional function to compare if slice property has changed (shallow test by default)
|
|
94
94
|
* @returns The state slice.
|
|
95
95
|
*/
|
|
96
96
|
export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, SLICE>(store: StoreApi<S, A, P, DS>, slicerFunc: (ctx: StateListenerContext<S, DS, A>) => SLICE): SLICE;
|
|
97
|
-
export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>>(store: StoreApi<S, A, P, DS>, properties: K[]): Pick<StateListenerContext<S, DS, A>, K>;
|
|
98
97
|
/**
|
|
99
|
-
*
|
|
100
|
-
* Store will be destroyed when component is unmouted.
|
|
101
|
-
* Props passed to actions will come from this components.
|
|
102
|
-
* If store is configured to react of props changes, it will used passed props.
|
|
103
|
-
* A store must be bound to only one React component.
|
|
104
|
-
* This component will be refreshed for every change in the store.
|
|
105
|
-
*
|
|
98
|
+
* A react hook to get a state slice. Will be refresh if, and only if, one property of the slice has changed
|
|
106
99
|
* @param store The store to listen to.
|
|
107
|
-
* @param
|
|
108
|
-
* @returns The state
|
|
100
|
+
* @param properties list of properties to extract from store
|
|
101
|
+
* @returns The state slice.
|
|
109
102
|
*/
|
|
110
|
-
export declare function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
export declare function useStoreSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>, KL extends keyof A>(store: StoreApi<S, A, P, DS>, properties: K[], loadingProps?: KL[]): Pick<StateListenerContext<S, DS, A>, K> & {
|
|
104
|
+
loadingMap: LoadingMap<Pick<A, KL>>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* A react hook to get a state slice from a store context.
|
|
108
|
+
* The component be refreshed if, and only if, one property of the slice has changed.
|
|
109
|
+
* @param store The store to listen to.
|
|
110
|
+
* @param slicerFunc A function that returns a state slice
|
|
111
|
+
* @returns The state slice.
|
|
112
|
+
*/
|
|
113
|
+
export declare function useStoreContextSlice<S, A extends DecoratedActions, P, DS, SLICE>(storeContext: Context<StoreApi<S, A, P, DS>>, slicerFunc: (ctx: StateListenerContext<S, DS, A>) => SLICE): SLICE;
|
|
114
|
+
/**
|
|
115
|
+
* A react hook to get a state slice from a store context.
|
|
116
|
+
* The component will be refreshed if, and only if, one property of the slice has changed.
|
|
117
|
+
* @param store The store to listen to.
|
|
118
|
+
* @param properties list of properties to extract from store
|
|
119
|
+
* @param loadingFlags list of action names to extract their loading state from store (available in loadingMap).
|
|
120
|
+
* @returns The state slice.
|
|
121
|
+
*/
|
|
122
|
+
export declare function useStoreContextSlice<S, A extends DecoratedActions, P, DS, K extends keyof StateListenerContext<S, DS, A>, KL extends keyof A>(storeContext: Context<StoreApi<S, A, P, DS>>, properties: K[], loadingProps?: KL[]): Pick<StateListenerContext<S, DS, A>, K> & {
|
|
123
|
+
loadingMap: LoadingMap<Pick<A, KL>>;
|
|
120
124
|
};
|
|
121
125
|
/**
|
|
122
126
|
* Binds the store to this component.
|
|
123
|
-
* Store will be destroyed when component is unmouted.
|
|
127
|
+
* Store will NOT be destroyed when component is unmouted.
|
|
124
128
|
* Props passed to actions will come from this components.
|
|
125
129
|
* If store is configured to react of props changes, it will used passed props.
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* This component will NOT be refreshed for any change in the store.
|
|
130
|
+
* The component will be refreshed for every change in the store.
|
|
129
131
|
*
|
|
130
132
|
* @param store The store to listen to.
|
|
131
133
|
* @param props The parent component props
|
|
134
|
+
* @param refreshOnUpdate Whether refresh the component if store state changes.
|
|
135
|
+
* @returns The store.
|
|
132
136
|
*/
|
|
133
|
-
export declare function
|
|
137
|
+
export declare function useStore<S, A extends DecoratedActions, P, DS = {}>(store: StoreApi<S, A, P, DS>, props?: P, refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
|
|
134
138
|
/**
|
|
135
139
|
* Creates and manages a local store.
|
|
140
|
+
* The component will be refreshed for every change in the store.
|
|
141
|
+
* Store will NOT be destroyed when component is unmouted.
|
|
142
|
+
*
|
|
136
143
|
* @param getInitialState Function to compute initial state from props.
|
|
137
144
|
* @param actionImpl Actions implementation.
|
|
138
145
|
* @param props Owner component props to update state or react on prop changes
|
|
139
146
|
* @param options The store options.
|
|
147
|
+
* @param refreshOnUpdate Whether refresh the component if store state changes.
|
|
140
148
|
* @returns The state, actions and isLoading function.
|
|
141
149
|
*/
|
|
142
|
-
export declare function useLocalStore<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[]):
|
|
143
|
-
state: S & DS;
|
|
144
|
-
actions: A;
|
|
145
|
-
loading: boolean;
|
|
146
|
-
isLoading: IsLoadingFunc<A>;
|
|
147
|
-
abortAction: (actionName: keyof A, promiseId?: string) => boolean;
|
|
148
|
-
loadingMap: LoadingMap<A>;
|
|
149
|
-
errorMap: ErrorMap<A>;
|
|
150
|
-
loadingParallelMap: LoadingParallelMap<A>;
|
|
151
|
-
errorParallelMap: ErrorParallelMap<A>;
|
|
152
|
-
};
|
|
150
|
+
export declare function useLocalStore<S, A extends DecoratedActions, P, DS = {}>(getInitialState: (p: P) => S, actionImpl: StoreActions<S, A, P, DS>, props?: P, options?: StoreOptions<S, A, P, DS>, middlewares?: MiddlewareFactory<S, A, P>[], refreshOnUpdate?: boolean): StoreApi<S, A, P, DS>;
|
|
153
151
|
export default useLocalStore;
|
|
154
152
|
/**
|
|
155
153
|
* Creates a new object by picking properties to the object passed a first parameter
|
package/es/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useReducer as r,useMemo as n,useRef as t,useLayoutEffect as e,useEffect as
|
|
1
|
+
import{useReducer as r,useMemo as n,useRef as t,useLayoutEffect as e,useContext as u,useEffect as c}from"react";import{createRef as o,isSimpleSyncAction as i,decorateSimpleSyncAction as l,isAsyncAction as a,decorateAsyncAction as f,computeAsyncActionInput as d,isSyncAction as s,decorateSyncAction as v,globalConfig as p,onPropChange as g,DEFAULT_PROMISE_ID as y,computeDerivedValues as b,buildOnMountInvocationContext as h,isLoadingImpl as E,runMiddlewares as M,buildLoadingMap as L,buildErrorMap as O}from"./impl";export{ParallelActionError,setGlobalConfig}from"./impl";var m,j=function(){return(j=Object.assign||function(r){for(var n,t=1,e=arguments.length;t<e;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r}).apply(this,arguments)};function k(r,n,t){if(t||2===arguments.length)for(var e,u=0,c=n.length;u<c;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return r.concat(e||Array.prototype.slice.call(n))}function A(r,n,t,e){void 0===t&&(t={}),void 0===e&&(e=null);var u=o(),c=o(),m=o(),A=o(),R=o(),S=o(),P=o(),w=o(),C=o(),I=o(!1),x=o([]),T={},G=0;function K(r,n){var t=j(j({},r),n),e=j(j(j({},t),A.current),{isLoading:F,abortAction:J,loading:q(),loadingMap:B(),errorMap:D()});Object.keys(T).forEach((function(r){T[r](e)}))}function N(r){u.current=r,b(u,m,c,t),K(u.current,c.current.state)}function U(o){var i;if(!I.current){m.current=o,I.current=!0,u.current=r(o);var l=new Set(null==t?void 0:t.initialActionsMarkedLoading);S.current=Object.keys(n).reduce((function(r,n){var t;return r[n]=l.has(n)?((t={})[y]=!0,t):{},r}),{}),P.current=Object.keys(n).reduce((function(r,n){return r[n]={},r}),{}),R.current={},w.current={},C.current={},c.current={state:null,deps:{}},x.current=[];var a={options:t,get state(){return u.current},actions:n,setState:N},f=function(r){var n,t=r();x.current.push(t),null===(n=t.init)||void 0===n||n.call(t,a)};null===(i=p.defaultMiddlewares)||void 0===i||i.forEach(f),null==e||e.forEach(f),b(u,m,c,t),g(u,c,m,null,A,t,_,!0),(null==t?void 0:t.onMount)&&t.onMount(h(u,c,m,A)),K(u.current,c.current.state)}}function _(r,n,e,o,i,l,a,f){void 0===a&&(a=!1),void 0===f&&(f=!1);var d=!1;if(I.current){var s=n,v=!!i&&E(s||S.current,[e,null==l?void 0:l.promiseId]),p=M(x.current,u.current,r,v,e,o,i,l),g=p.newState,h=p.newLoading;if(null!=g&&(d=!0,u.current=g),v!==h&&(s=L(s,e,(null==l?void 0:l.promiseId)||y,h),0===Object.keys(s).length&&(s=void 0)),null!=s&&(d=!0,S.current=s),d)b(u,m,c,t),f||K(g||u.current,c.current.state);else if(a){b(u,m,c,t)&&!f&&K(g||u.current,c.current.state)}}}var z=Object.keys(n);function F(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return E.apply(void 0,k([S.current],r,!1))}function J(r,n){var t,e;void 0===n&&(n=y);var u=null===(e=null===(t=w.current[r])||void 0===t?void 0:t[n])||void 0===e?void 0:e.abortController,c=!1;return u&&(u.abort(),c=!0),c}function q(){if(I.current){var r=S.current;return null!=Object.keys(r).find((function(n){var t=r[n];return Object.keys(t).find((function(r){return!!t[r]}))}))}return null}function B(){if(I.current){var r=S.current;return Object.keys(r).reduce((function(n,t){var e=r[t];return n[t]=null!=Object.keys(e).find((function(r){return!!e[r]})),n}),{})}return null}function D(){return I.current?O(P.current):null}return A.current=z.reduce((function(r,e){var o=n[e];return i(o)?r[e]=l(e,o,u,c,m,I,_):a(o)?r[e]=f({actionName:e,stateRef:u,derivedStateRef:c,propsRef:m,loadingMapRef:S,errorMapRef:P,actionsRef:A,promisesRef:w,conflictActionsRef:C,initializedRef:I,options:t,setState:_,action:d(o)}):s(o)&&(r[e]=v(e,o,u,c,m,A,I,R,t,_)),r}),{}),{getConfig:function(){return{getInitialState:r,options:t,actions:n}},setProps:function(r){var n=m.current;m.current=r,I.current?g(u,c,m,n,A,t,_,!1):U(r)},addStateListener:function(r){var n="".concat(G++);return T[n]=r,function(){delete T[n]}},init:U,destroy:function(){var r;I.current&&(null===(r=null==t?void 0:t.onUnmount)||void 0===r||r.call(t,h(u,c,m,A)),m.current=null,u.current=null,S.current=null,P.current=null,w.current=null,C.current=null,c.current=null,Object.keys(R.current).forEach((function(r){clearTimeout(R.current[r])})),R.current=null,T={},I.current=!1,x.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),x.current=[])},isLoading:F,abortAction:J,get actions(){return A.current},get state(){return I.current?j(j({},u.current),c.current.state):null},get loading(){return q()},get loadingMap(){return B()},get errorMap(){return D()},get loadingParallelMap(){return I.current?S.current:null},get errorParallelMap(){return I.current?P.current:null}}}function R(u,c,o){var i=r((function(r){return r>100?0:r+1}),0)[1],l=n((function(){return c instanceof Function?c:function(r){return C(r,c)}}),[c]),a=n((function(){return function(r){return null!=o&&o.length>0?C(r.loadingMap,o):null}}),[o]),f=t(null),d=t(null);if(null===f.current){var s=j(j(j({},u.state),u.actions),C(u,["actions","loading","isLoading","abortAction","loadingMap","errorMap"]));f.current=l(s),d.current=a(s)}e((function(){return u.addStateListener((function(r){var n,t=l(r),e=a(r),u=f.current,c=p.comparator;n=null==u||!c(t,u)||!c(e,d.current),f.current=t,d.current=e,n&&i()}))}),[]);var v=f.current,g=d.current;return null==g?v:j(j({},v),{loadingMap:g})}function S(r,n,t){return R(u(r),n,t)}function P(n,u,c){void 0===u&&(u=null),void 0===c&&(c=!0);var o=r((function(r){return r>100?0:r+1}),0)[1],i=t(n);return n.setProps(u),e((function(){c&&i.current.addStateListener((function(){o()}))}),[c]),n}function w(r,n,e,u,o,i){void 0===i&&(i=!0);var l=t();return null==l.current&&(l.current=A(r,n,u,o)),c((function(){return function(){var r;null===(r=l.current)||void 0===r||r.destroy()}}),[]),P(l.current,e,i)}function C(r,n){return n.reduce((function(n,t){return r.hasOwnProperty(t)&&(n[t]=r[t]),n}),{})}function I(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return C(n,r)}}!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse"}(m||(m={}));export default w;export{m as ConflictPolicy,A as createStore,C as pick,I as slice,w as useLocalStore,P as useStore,S as useStoreContextSlice,R as useStoreSlice};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["__assign","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","this","__spreadArray","to","from","pack","ar","l","Array","slice","concat"],"mappings":"4iBA+BO,MAAIA,EAAW,WAQlB,OAPAA,EAAWC,OAAOC,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,IAE9E,OAAON,IAEKU,MAAMC,KAAMP,YA6HzB,SAASQ,EAAcC,EAAIC,EAAMC,GACpC,GAAIA,GAA6B,IAArBX,UAAUC,OAAc,IAAK,IAA4BW,EAAxBd,EAAI,EAAGe,EAAIH,EAAKT,OAAYH,EAAIe,EAAGf,KACxEc,GAAQd,KAAKY,IACRE,IAAIA,EAAKE,MAAMX,UAAUY,MAAMV,KAAKK,EAAM,EAAGZ,IAClDc,EAAGd,GAAKY,EAAKZ,IAGrB,OAAOW,EAAGO,OAAOJ,GAAME,MAAMX,UAAUY,MAAMV,KAAKK"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n"],"names":["__assign","Object","assign","t","s","i","n","arguments","length","p","prototype","hasOwnProperty","call","apply","this","__spreadArray","to","from","pack","ar","l","Array","slice","concat"],"mappings":"4jBA+BO,MAAIA,EAAW,WAQlB,OAPAA,EAAWC,OAAOC,QAAU,SAAkBC,GAC1C,IAAK,IAAIC,EAAGC,EAAI,EAAGC,EAAIC,UAAUC,OAAQH,EAAIC,EAAGD,IAE5C,IAAK,IAAII,KADTL,EAAIG,UAAUF,GACOJ,OAAOS,UAAUC,eAAeC,KAAKR,EAAGK,KAAIN,EAAEM,GAAKL,EAAEK,IAE9E,OAAON,IAEKU,MAAMC,KAAMP,YA6HzB,SAASQ,EAAcC,EAAIC,EAAMC,GACpC,GAAIA,GAA6B,IAArBX,UAAUC,OAAc,IAAK,IAA4BW,EAAxBd,EAAI,EAAGe,EAAIH,EAAKT,OAAYH,EAAIe,EAAGf,KACxEc,GAAQd,KAAKY,IACRE,IAAIA,EAAKE,MAAMX,UAAUY,MAAMV,KAAKK,EAAM,EAAGZ,IAClDc,EAAGd,GAAKY,EAAKZ,IAGrB,OAAOW,EAAGO,OAAOJ,GAAME,MAAMX,UAAUY,MAAMV,KAAKK"}
|
package/es/middlewares.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isSimpleSyncAction as e,globalConfig as t}from"./impl";var n=function(){return(n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},o=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var
|
|
1
|
+
import{isSimpleSyncAction as e,globalConfig as t}from"./impl";var n=function(){return(n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},o=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var l=i[r];if(!e(t[l],n[l]))return!1}return!0}return t!=t&&n!=n};function r(e){void 0===e&&(e=console.log);return function(){var t=e,n="";return{init:function(e){var o,r;if("development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV){n=(null===(o=e.options)||void 0===o?void 0:o.name)?"[".concat(null===(r=e.options)||void 0===r?void 0:r.name,"]"):"";var i=e.state;t(n,"initialState",i)}},destroy:null,effects:function(e,o,r,i){return"development"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV||t(n,e.name,e.type,null===r?"no effect":r,e.isAsync?"preEffects"!==e.type||i?"loading: ".concat(i):"Promise cancelled":""),null}}}}function i(e){return void 0===e&&(e=console),function(){var t="",n=e;if("development"===process.env.NODE_ENV||"test"===process.env.NODE_ENV){var r=function(e,t){var n;if(t!==e){var r=null!=e?typeof e:typeof t;if("number"===r||"string"===r||"boolean"===r)n="".concat(e," => ").concat(""===t?'""':t);else if(e&&e.length||t&&t.length)if(null==e)n="was ".concat(e,", now contains ").concat(t.length," element(s)");else if(null==t)n="contained ".concat(e.length," element(s), now is ").concat(t);else if(0===e.length)n="was empty, now contains ".concat(t.length," elements");else if(0===t.length)n="contained ".concat(e.length," elements, now is empty");else{var i=t.filter((function(t){return!e.find((function(e){return o(t,e)}))})),l=e.filter((function(e){return!t.find((function(t){return o(e,t)}))}));i.length>10&&(i="".concat(i.length," element(s) added")),l.length>10&&(l="".concat(l.length," element(s) removed")),n={added:i,removed:l}}else n=t}return n},i=function(e){return"string"==typeof e?'"'.concat(e,'"'):e};return{init:function(o){var r,l;t=(null===(r=o.options)||void 0===r?void 0:r.name)?"[".concat(null===(l=o.options)||void 0===l?void 0:l.name,"]"):"";var c=o.state;e.group(t,"initialState"),Object.keys(c).forEach((function(e){n.log(e,":",i(c[e]))})),e.groupEnd()},destroy:null,effects:function(e,o,l,c){var s,f=null===(s=e.context)||void 0===s?void 0:s.args,a=[t,e.name.toString()];if(e.isAsync&&("preEffects"===e.type?a.push(c?"START":"CANCELLED"):"effects"===e.type?a.push("DONE"):a.push("FAILED")),null!=l||f&&0!==Object.keys(f).length?n.group.apply(n,a):n.log.apply(n,a),f&&Object.keys(f).length>0&&(n.group("Arguments"),f.forEach((function(e){n.log(e,":",i(e))})),n.groupEnd()),null!=l){if(n.groupCollapsed("Before"),null==o)n.log("was null");else Object.keys(o).forEach((function(e){n.log(e,":",i(o[e]))}));if(n.groupEnd(),n.groupCollapsed("After"),null==l)n.log("was null");else Object.keys(l).forEach((function(e){n.log(e,":",i(l[e]))}));if(n.groupEnd(),null!=l){n.group("Diff");var u=function(e,t){var n={};"development"===process.env.NODE_ENV&&(e&&Object.keys(e).forEach((function(o){if(t.hasOwnProperty(o)){var i=e[o],l=t[o],c=r(i,l);c&&(n[o]=c)}else n[o]="was deleted"})),Object.keys(t).forEach((function(o){if(null==e||!e.hasOwnProperty(o)){var i=t[o];n[o]=r(void 0,i)}})));return n}(o,l);Object.keys(u).forEach((function(e){return n.log(e,":",u[e])})),n.groupEnd()}}return n.groupEnd(),null}}}return{init:function(){},destroy:null,effects:function(){return null}}}}function l(o){return function(){var r=null,i={history:null,optimisticActions:{},shouldRecordHistory:!1},l=function(e){return(o||t.clone)(e)},c=function(e,t){return"".concat(e,"_").concat(t)};function s(e,t,n,o){void 0===o&&(o=null);var r=i.shouldRecordHistory,c=i.history;if(r){null===c&&(i.history=[]);var s=l(n);delete s.state,delete s.s,delete s.abortSignal,s.error=n.err,s.err=n.err;var f={effectType:t,actionName:e,promiseId:n.promiseId,ctx:s,beforeEffectState:o?l(o):null};i.history.push(f)}}function f(e,t,n){void 0===n&&(n=void 0);var o=i.optimisticActions,r=i.history,l=c(e,t);if(delete o[l],0===Object.keys(o).length)i.history=null,i.shouldRecordHistory=!1;else{var s=void 0===n?r.findIndex((function(e){return c(e.actionName,e.promiseId)===l})):n;if(0===s){var f=r.slice(1).findIndex((function(e){return null!=e.beforeEffectState}))+1;r.splice(0,f)}else void 0===n&&(r[s].beforeEffectState=null)}}return{init:function(e){r=e},destroy:function(){r=null,i.history=null,i.optimisticActions={},i.shouldRecordHistory=!1},effects:function(t,o,l,a){var u=t.name,p=t.type,d=t.context,v=t.isAsync;if((null!=l&&e(r.actions[u])||"onPropsChange"===u||null!=r.actions[u][p])&&s(u,p,d,null),v){var y,g=r.actions[u];if(a&&null!=g.optimisticEffects&&"preEffects"===p)return i.shouldRecordHistory=!0,i.optimisticActions[c(u,d.promiseId)]=!0,s(u,"optimisticEffects",d,y=l||o),{loading:!1,state:n(n({},y),g.optimisticEffects(n(n({},d),{state:y,s:y})))};if(null!=g.optimisticEffects&&"effects"===p)return f(u,d.promiseId),{loading:a,state:l};if(null!=g.optimisticEffects&&"errorEffects"===p)return{state:y=function(t,o){for(var l=i.history,c=l.findIndex((function(e){return"optimisticEffects"===e.effectType&&e.actionName===t&&e.promiseId===o})),s=l[c].beforeEffectState,a=c+1;a<l.length;a++){var u=l[a];u.beforeEffectState&&(u.beforeEffectState=s);var p=n(n({},u.ctx),{state:s,s:s});if("onPropsChange"===u.actionName){var d=Array.isArray(r.options.onPropsChange)?r.options.onPropsChange:[r.options.onPropsChange];s=n(n({},s),d[p.index].effects(p))}else s=e(r.actions[u.actionName])?n(n({},s),r.actions[u.actionName](p)):n(n({},s),r.actions[u.actionName][u.effectType](p))}return f(t,o,c),s}(u,d.promiseId),loading:a}}return null}}}}function c(){return function(){var e,t,o;try{e=window.__REDUX_DEVTOOLS_EXTENSION__||window.top.__REDUX_DEVTOOLS_EXTENSION__}catch(e){}return e?{init:function(n){var r,i;(t=e.connect({name:null!==(i=null===(r=n.options)||void 0===r?void 0:r.name)&&void 0!==i?i:"StateDecorator"})).init(n.state);var l=null,c=n.state;o=t.subscribe((function(e){var t,o,r,i;if("DISPATCH"===e.type&&e.state&&"ROLLBACK"!==(null===(t=e.payload)||void 0===t?void 0:t.type)){var s=JSON.parse(e.state);n.setState(s)}else"COMMIT"===(null===(o=e.payload)||void 0===o?void 0:o.type)?l=n.state:"ROLLBACK"===(null===(r=e.payload)||void 0===r?void 0:r.type)?null!=l&&n.setState(l):"RESET"===(null===(i=e.payload)||void 0===i?void 0:i.type)&&n.setState(c)}))},effects:function(e,o,r){if(null!=r){var i=n({},e.context);delete i.a,delete i.s,delete i.p,delete i.res,delete i.err,delete i.ds,t.send({type:"".concat(e.name," ").concat(e.type),args:i.args,context:i},r)}return null},destroy:function(){o(),t=null}}:{init:function(){},destroy:null,effects:function(){return null}}}}export{c as devtools,i as logDetailedEffects,r as logEffects,l as optimisticActions};
|
|
2
2
|
//# sourceMappingURL=middlewares.js.map
|
package/es/types.d.ts
CHANGED
|
@@ -76,8 +76,8 @@ export declare type PromiseProvider<S, DS, F extends (...args: any[]) => any, A,
|
|
|
76
76
|
/**
|
|
77
77
|
* Simple form of a synchronous action.
|
|
78
78
|
*/
|
|
79
|
-
export declare type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = S
|
|
80
|
-
export declare type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S
|
|
79
|
+
export declare type SimpleSyncAction<S, F extends (...args: any[]) => any, P, DS, FxRes = Partial<S>> = (ctx: InvocationContext<S, DS, F, P>) => FxRes | null;
|
|
80
|
+
export declare type SyncAction<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
81
81
|
/**
|
|
82
82
|
* Function that update the state when the action is called.
|
|
83
83
|
*/
|
|
@@ -178,7 +178,7 @@ export declare type Middleware<S, A extends DecoratedActions, P> = {
|
|
|
178
178
|
*/
|
|
179
179
|
destroy: () => void;
|
|
180
180
|
};
|
|
181
|
-
export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S
|
|
181
|
+
export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = {
|
|
182
182
|
/**
|
|
183
183
|
* This action can be aborted. An abortSignal will be injected to the <code>promise</code> / <code>promiseGet</code>.
|
|
184
184
|
*/
|
|
@@ -264,13 +264,13 @@ export declare type AsyncActionBase<S, F extends (...args: any[]) => any, A, P,
|
|
|
264
264
|
*/
|
|
265
265
|
isTriggerRetryError?: (e: Error) => boolean;
|
|
266
266
|
};
|
|
267
|
-
export declare type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S
|
|
267
|
+
export declare type AsyncActionPromise<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
268
268
|
/**
|
|
269
269
|
* The request, returns a promise
|
|
270
270
|
*/
|
|
271
271
|
getPromise: PromiseProvider<S, DS, F, A, P>;
|
|
272
272
|
};
|
|
273
|
-
export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = S
|
|
273
|
+
export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any, A, P, DS, FxRes = Partial<S>> = AsyncActionBase<S, F, A, P, DS, FxRes> & {
|
|
274
274
|
/**
|
|
275
275
|
* The request, returns a promise that is a GET request.
|
|
276
276
|
* A shortcut to set:
|
|
@@ -279,13 +279,13 @@ export declare type AsyncActionPromiseGet<S, F extends (...args: any[]) => any,
|
|
|
279
279
|
*/
|
|
280
280
|
getGetPromise: PromiseProvider<S, DS, F, A, P>;
|
|
281
281
|
};
|
|
282
|
-
export declare type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S
|
|
283
|
-
export declare type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = S
|
|
282
|
+
export declare type AsyncAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncActionPromise<S, F, A, P, DS, FxRes> | AsyncActionPromiseGet<S, F, A, P, DS, FxRes>;
|
|
283
|
+
export declare type StoreAction<S, F extends (...args: any[]) => any, A, P, DS = {}, FxRes = Partial<S>> = AsyncAction<S, F, A, P, DS, FxRes> | SimpleSyncAction<S, F, P, DS, FxRes> | SyncAction<S, F, A, P, DS, FxRes>;
|
|
284
284
|
/**
|
|
285
285
|
* S: The type of the state
|
|
286
286
|
* A: The type of the actions to pass to the children (used to check keys only).
|
|
287
287
|
*/
|
|
288
|
-
export declare type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = S
|
|
288
|
+
export declare type StoreActions<S, A extends DecoratedActions, P = {}, DS = {}, FxRes = Partial<S>> = {
|
|
289
289
|
[Prop in keyof A]: StoreAction<S, A[Prop], A, P, DS, FxRes>;
|
|
290
290
|
};
|
|
291
291
|
export declare type OnPropsChangeEffectsContext<S, DS, P> = ContextWithDerived<S, DS, P> & {
|
|
@@ -306,7 +306,7 @@ declare type DerivedStateOption<S, P, DS> = {
|
|
|
306
306
|
export declare type OnPropsChangeOptions<S, DS, A, P> = {
|
|
307
307
|
onMount?: boolean;
|
|
308
308
|
getDeps: (p: P) => any[];
|
|
309
|
-
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => S
|
|
309
|
+
effects?: (ctx: OnPropsChangeEffectsContext<S, DS, P>) => Partial<S>;
|
|
310
310
|
sideEffects?: (ctx: OnPropsChangeSideEffectsContext<S, P, A>) => void;
|
|
311
311
|
};
|
|
312
312
|
export declare type StoreOptions<S, A, P = {}, DS = {}> = {
|
package/es/v5_test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ConflictPolicy as r}from"./index";export{ConflictPolicy,setGlobalConfig}from"./index";import{isSimpleSyncAction as e,isSyncAction as n,isAsyncAction as o,isAsyncGetPromiseAction as t,isAsyncGetPromiseGetAction as s}from"./impl";var i=function(){return(i=Object.assign||function(r){for(var e,n=1,o=arguments.length;n<o;n++)for(var t in e=arguments[n])Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r}).apply(this,arguments)};function l(r,e,n){if(n||2===arguments.length)for(var o,t=0,s=e.length;t<s;t++)!o&&t in e||(o||(o=Array.prototype.slice.call(e,0,t)),o[t]=e[t]);return r.concat(o||Array.prototype.slice.call(e))}function u(r){return!(r instanceof Function)&&(r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function a(r){return!(r instanceof Function||r.hasOwnProperty("promise")&&r.hasOwnProperty("promiseGet"))}function c(r){return r instanceof Function}function p(r){return!(r instanceof Function||r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function d(e,n){return u(e)?n(function(e){return"promiseGet"in e?i(i({},e),{promise:e.promiseGet,retryCount:3,conflictPolicy:r.REUSE}):e}(e)):Promise.reject(new Error("This action is not an asynchronous action"))}function f(r,e){return c(r)?e(r):Promise.reject(new Error("This action is not a synchronous action"))}function m(r,e){return p(r)?e(r):Promise.reject(new Error("This action is not a synchronous advanced action"))}function g(r,n){if(e(r)){return n((function(e,n,o){return r({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null})})),Promise.resolve()}return Promise.reject(new Error("This action is not a synchronous action"))}function v(r,e){return n(r)?(e({action:function(e,n,o){return r.effects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,res:null,result:null,promiseId:null})},onActionDone:function(e,n,o,t,s){r.sideEffects({s:e,args:n,p:o,a:t,notifyWarning:s,ds:null,derived:null,state:e,props:o,actions:t,res:null,result:null,promiseId:null})}}),Promise.resolve()):Promise.reject(new Error("This action is not a synchronous action"))}function
|
|
1
|
+
import{ConflictPolicy as r}from"./index";export{ConflictPolicy,setGlobalConfig}from"./index";import{isSimpleSyncAction as e,isSyncAction as n,isAsyncAction as o,isAsyncGetPromiseAction as t,isAsyncGetPromiseGetAction as s}from"./impl";var i=function(){return(i=Object.assign||function(r){for(var e,n=1,o=arguments.length;n<o;n++)for(var t in e=arguments[n])Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r}).apply(this,arguments)};function l(r,e,n){if(n||2===arguments.length)for(var o,t=0,s=e.length;t<s;t++)!o&&t in e||(o||(o=Array.prototype.slice.call(e,0,t)),o[t]=e[t]);return r.concat(o||Array.prototype.slice.call(e))}function u(r){return!(r instanceof Function)&&(r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function a(r){return!(r instanceof Function||r.hasOwnProperty("promise")&&r.hasOwnProperty("promiseGet"))}function c(r){return r instanceof Function}function p(r){return!(r instanceof Function||r.hasOwnProperty("promise")||r.hasOwnProperty("promiseGet"))}function d(e,n){return u(e)?n(function(e){return"promiseGet"in e?i(i({},e),{promise:e.promiseGet,retryCount:3,conflictPolicy:r.REUSE}):e}(e)):Promise.reject(new Error("This action is not an asynchronous action"))}function f(r,e){return c(r)?e(r):Promise.reject(new Error("This action is not a synchronous action"))}function m(r,e){return p(r)?e(r):Promise.reject(new Error("This action is not a synchronous advanced action"))}function g(r,n){if(e(r)){return n((function(e,n,o){return v(e,r({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null}))})),Promise.resolve()}return Promise.reject(new Error("This action is not a synchronous action"))}function v(r,e){return null==e?null:i(i({},r),e)}function y(r,e){return n(r)?(e({action:function(e,n,o){return v(e,r.effects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,res:null,result:null,promiseId:null}))},onActionDone:function(e,n,o,t,s){r.sideEffects({s:e,args:n,p:o,a:t,notifyWarning:s,ds:null,derived:null,state:e,props:o,actions:t,res:null,result:null,promiseId:null})}}),Promise.resolve()):Promise.reject(new Error("This action is not a synchronous action"))}function P(r,e){return o(r)?e({abortable:r.abortable,rejectPromiseOnError:r.rejectPromiseOnError,retryCount:r.retryCount,retryDelaySeed:r.retryDelaySeed,isTriggerRetryError:r.isTriggerRetryError,conflictPolicy:r.conflictPolicy,getPromiseId:r.getPromiseId,promise:function(e,n,o,s,i){return t(r)?r.getPromise({s:n,args:e,p:o,a:s,abortSignal:i,ds:null,derived:null,state:n,props:o,actions:s,promiseId:null}):r.getGetPromise({s:n,args:e,p:o,a:s,abortSignal:i,ds:null,derived:null,state:n,props:o,actions:s,promiseId:null})},promiseGet:function(e,n,o,t,i){return s(r)?r.getGetPromise({s:n,args:e,p:o,a:t,abortSignal:i,ds:null,derived:null,state:n,props:o,actions:t,promiseId:null}):null},reducer:function(e,n,o,t){return r.effects?v(e,r.effects({s:e,args:o,p:t,res:n,ds:null,derived:null,state:e,props:t,result:n,promiseId:null})):null},preReducer:function(e,n,o){return r.preEffects?v(e,r.preEffects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null})):null},optimisticReducer:function(e,n,o){var t;return r.optimisticEffects?v(e,r.optimisticEffects({s:e,args:n,p:o,ds:null,derived:null,state:e,props:o,promiseId:null===(t=r.getPromiseId)||void 0===t?void 0:t.call.apply(t,l([r],n,!1))})):null},errorReducer:function(e,n,o,t){var s;return r.errorEffects?v(e,r.errorEffects({s:e,args:o,p:t,err:n,ds:null,derived:null,state:e,props:t,error:n,promiseId:null===(s=r.getPromiseId)||void 0===s?void 0:s.call.apply(s,l([r],o,!1))})):null},onDone:function(e,n,o,t,s,i){var u,a;null===(u=r.sideEffects)||void 0===u||u.call(r,{s:e,args:o,p:t,a:s,res:n,notifyWarning:i,ds:null,derived:null,state:e,props:t,actions:s,result:n,promiseId:null===(a=r.getPromiseId)||void 0===a?void 0:a.call.apply(a,l([r],o,!1))})},onFail:function(e,n,o,t,s,i){var u,a;null===(u=r.errorSideEffects)||void 0===u||u.call(r,{s:e,args:o,p:t,a:s,err:n,notifyWarning:i,ds:null,derived:null,state:e,props:t,actions:s,error:n,promiseId:null===(a=r.getPromiseId)||void 0===a?void 0:a.call.apply(a,l([r],o,!1))})},getErrorMessage:function(e,n,o){var t,s;return null===(t=r.getErrorMessage)||void 0===t?void 0:t.call(r,{err:e,p:o,args:n,ds:null,derived:null,state:null,s:null,error:e,props:o,promiseId:null===(s=r.getPromiseId)||void 0===s?void 0:s.call.apply(s,l([r],n,!1))})},getSuccessMessage:function(e,n,o){var t,s;return null===(t=r.getSuccessMessage)||void 0===t?void 0:t.call(r,{res:e,args:n,p:o,ds:null,derived:null,state:null,s:null,result:e,props:o,promiseId:null===(s=r.getPromiseId)||void 0===s?void 0:s.call.apply(s,l([r],n,!1))})}}):Promise.reject(new Error("This action is not a synchronous action"))}export{p as isAdvancedSyncAction,u as isAsyncAction,a as isAsyncPromiseGetAction,c as isSyncAction,m as testAdvancedSyncAction,d as testAsyncAction,f as testSyncAction,y as testV6AdvancedSyncAction,P as testV6AsyncAction,g as testV6SyncAction};
|
|
2
2
|
//# sourceMappingURL=v5_test.js.map
|
package/impl.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(r,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(r,t)};var r,t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(c,u)}a((n=n.apply(e,r||[])).next())}))}function o(e,r){var t,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,n=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(var o=0;o<t.length;o++)if(!Object.prototype.hasOwnProperty.call(r,t[o])||!Object.is(e[t[o]],r[t[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function a(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function s(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=!1,a)),u))}function l(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=void 0,a)),u))}var f=function(r){function t(e){var n=r.call(this,"Error")||this;return n.promiseIds=e,Object.setPrototypeOf(n,t.prototype),n}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,r),t}(Error);function d(e,r,t,i){return void 0===r&&(r=1),void 0===t&&(t=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,s){return n(this,void 0,void 0,(function(){return o(this,(function(n){return null===s?[2,null]:[2,s.catch((function(n){return i(n)?a===r?Promise.reject(n):new Promise((function(r,n){setTimeout((function(){var t=e(c);u(a+1,t).then(r).catch(n)}),t*a)})):Promise.reject(n)}))]}))}))}(1,u)}}function p(e){return void 0===e&&(e=null),{current:e}}function v(e,r,t){var n,o;return{state:e.current,s:e.current,ds:null===(n=null==r?void 0:r.current)||void 0===n?void 0:n.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:t.current,p:t.current}}function g(e,r,t,n,o,i){var c=v(e,r,t);return c.indices=n,c.index=o,c.isInit=i,c}function y(e,r,t,n,o){var i=v(e,r,t);return i.args=n,o&&(i.promiseId=o),i}function h(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.result=o,c.res=o,c}function E(e,r,t,n,o,i,c){var u=P(y(e,r,t,n,c),o);return u.abortSignal=i,u}function m(e,r){var t=e;return t.state=r.current,t.s=r.current,t}function P(e,r){var t=e;return t.actions=r.current,t.a=r.current,t}function S(e,r,t,n,o){var i,c=P(e,n);m(e,r);var u=null===(i=null==t?void 0:t.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function b(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function w(e,r,t,n,o,i,c,u,a,s){var l,f=h(t,n,o,s,void 0),d=!1;if(null!=r.effects){var p=r.effects(f);null===p?d=!0:a(p,void 0,e,"effects",!1,f,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var v=c.current[e];v&&clearTimeout(v),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,S(f,t,n,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(l=r.sideEffects)||void 0===l||l.call(r,S(f,t,n,i,u.notifyWarning))}function A(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,d=e.loadingMapRef,p=e.conflictActionsRef,v=e.actionName,g=e.options,y=e.setState;if(e.initializedRef.current){var E=null,m=h(i,u,a,n,t,r);o.effects&&(E=o.effects(m)),y(E,s(d.current,v,r,!1),v,"effects",!0,m,!1);var P=g.notifySuccess||c.notifySuccess;if(P){var b=void 0;o.getSuccessMessage&&(b=o.getSuccessMessage(m)),b&&P(b)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(S(m,i,u,f,c.notifyWarning)),L(v,f.current,p.current),t}}function x(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,d=e.loadingMapRef,p=e.errorMapRef,v=e.promisesRef,g=e.conflictActionsRef,h=e.actionName,E=e.options,m=e.setState;if(e.initializedRef.current){var P=null,b=function(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.error=o,c.err=o,c}(i,u,a,n,t,r);o.errorEffects&&(P=o.errorEffects(b)),p.current=l(p.current,h,r,t),m(P,s(d.current,h,r,!1),h,"errorEffects",!0,b,!1);var w=!1;(null!=P||o.errorSideEffects||o.isErrorManaged)&&(w=!0);var A=E.notifyError||c.notifyError;if(A){var x=void 0;o.getErrorMessage&&(x=o.getErrorMessage(b)),void 0===x&&!w&&c.getErrorMessage&&(x=c.getErrorMessage(t)),x&&(w=!0,A(x))}return c.asyncErrorHandler(t,w||o.rejectPromiseOnError,i.current,a.current,h,n),delete v.current[h][r],o.errorSideEffects&&o.errorSideEffects(S(b,i,u,f,c.notifyWarning)),L(h,f.current,g.current),!w||o.rejectPromiseOnError?Promise.reject(t):Promise.resolve()}}var O="__def__";function R(e,r){return e.length===r.length&&-1===e.findIndex((function(e,t){return r[t]!==e}))}function C(e,t,n,o,i){var c=o;if(c===r.REUSE){if(R(e[n][O].refArgs,i))return e[n][O].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var a={resolve:e,reject:o,args:u(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:t[n]=[a];break;case r.KEEP_ALL:var s=t[n];s||(t[n]=s=[]),s.push(a);break;case r.PARALLEL:case r.REUSE:}}))}function L(e,r,t){var n=t[e];if(n&&n.length>0){var o=t[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?L(e,r,t):i.then((function(n){null===n&&L(e,r,t),o.resolve(n)})).catch((function(e){return o.reject(e)}))}}}exports.DEFAULT_PROMISE_ID=O,exports.ParallelActionError=f,exports.addContextActions=P,exports.addStateToContext=m,exports.areSameArgs=R,exports.buildErrorMap=function(e){return Object.keys(e).reduce((function(r,t){var n=e[t];if(null==n[O]);else if(n[O])r[t]=n[O];else{var o=Object.keys(n).reduce((function(e,r){return null!=n[r]&&(e.hasErr=!0,e.map[r]=n[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[t]=new f(o.map))}return r}),{})},exports.buildInvocationContextBase=v,exports.buildLoadingMap=s,exports.buildOnMountInvocationContext=function(e,r,t,n){return P(v(e,r,t),n)},exports.buildOnPropChangeEffects=g,exports.computeAsyncActionInput=function(e){return a(e)?t(t({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e},exports.computeDerivedValues=function(e,r,t,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=c.comparator,u=t.current.deps,a=v(e,null,r),s=Object.keys(n.derivedState);return t.current.state=s.reduce((function(e,r){var c=!1,s=u[r],l=n.derivedState[r].getDeps(a);return c=null==s||null!=l.find((function(e,r){return s.length<r||!i(s[r],e)})),o=o||c,u[r]=l,e[r]=c?n.derivedState[r].get(a):t.current.state[r],e}),{}),o},exports.createRef=p,exports.decorateAsyncAction=function(e){var n=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,p=e.promisesRef,v=e.loadingMapRef,g=e.errorMapRef,h=e.initializedRef,m=e.conflictActionsRef,P=e.actionName,S=e.setState;return function(){for(var w,R,L,j=[],_=0;_<arguments.length;_++)j[_]=arguments[_];if(!h.current)return b(P),null;var M=p.current,T=n.conflictPolicy,k=void 0===T?r.KEEP_ALL:T,I=k===r.PARALLEL,D=null;if(I){if(!n.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");D=n.getPromiseId.apply(n,j)}else D=O;if(!I&&(null===(R=M[P])||void 0===R?void 0:R[D]))return C(M,m.current,P,k,j);var G=null,N=!1,K=y(o,u,a,j,D);n.preEffects&&(G=n.preEffects(K))&&(N=!0,o.current=G);var U=n.abortable,W=n.retryCount,F=n.retryDelaySeed,z=n.isTriggerRetryError,J=U&&window.AbortController?new AbortController:null,V=d(n.getPromise,W?1+W:1,F,z||c.retryOnErrorFunction),H=null===(L=V(E(o,u,a,j,f,null==J?void 0:J.signal)))||void 0===L?void 0:L.then((function(r){return A(e,D,r,j)})).catch((function(r){return x(e,D,r,j)}));return null!=H&&(M[P]=t(t({},M[P]||{}),((w={})[D||O]={abortController:J,promise:H,refArgs:k===r.REUSE&&j.length>0?i([],j,!0):[]},w))),g.current=l(g.current,P,D,null),S(null!=H||N?o.current:void 0,null==H?void 0:s(v.current,P,D,!0),P,"preEffects",!0,K,!1),H}},exports.decorateSimpleSyncAction=function(e,r,t,n,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var s=y(t,n,o,u),l=r(s);c(l,null,e,"effects",!1,s,!1)}else b(e)}},exports.decorateSyncAction=function(e,r,t,n,o,i,c,u,a,s){return function(){for(var l=[],f=0;f<arguments.length;f++)l[f]=arguments[f];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],w(e,r,t,n,o,i,u,a,s,l)}),r.debounceTimeout)}else w(e,r,t,n,o,i,u,a,s,l);else b(e)}},exports.globalConfig=c,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))},exports.isAsyncGetPromiseAction=function(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.isAsyncGetPromiseGetAction=a,exports.isLoadingImpl=function(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];return r.some((function(r){var t,n=null,o=O;Array.isArray(r)?(n=r[0],o=void 0===(t=r[1])?O:t):n=r;var i=e[n];return null!=i&&(null!=i[o]&&i[o])}))},exports.isSimpleSyncAction=function(e){return"function"==typeof e},exports.isSyncAction=function(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.onPropChange=function(e,r,n,o,i,u,a,s){var l=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var f;f=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=p(e.current),y=[],h=c.comparator;f.forEach((function(e,t){var i,c,u=e.getDeps;if(u){var l=!1,f=[];if(s){if(!e.onMount)return;l=!0}else{var p=u(o),E=u(n.current);p.length!==E.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),l=!0):p.forEach((function(e,r){h(e,E[r])||(l=!0,f.push(r))}))}if(l){var m=g(v,r,n,f,t,s),P=null!==(c=null===(i=e.effects)||void 0===i?void 0:i.call(e,m))&&void 0!==c?c:null;null!=P&&(d=!0,v.current=P,a(v.current,void 0,"onPropsChange","effects",!1,m,!0,s)),e.sideEffects&&y.push({index:t,indices:f,ctx:m})}}})),!d&&l&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),y.length>0&&y.forEach((function(e){f[e.index].sideEffects(t(t({},m(P(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)},exports.retryPromiseDecorator=d,exports.runMiddlewares=function(e,r,t,n,o,i,c,u){if("onPropsChange"===o&&void 0===t)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var t=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,n);return{newState:(null==t?void 0:t.state)||e.newState,oldState:(null==t?void 0:t.state)?e.newState:e.oldState,loading:null==(null==t?void 0:t.loading)?e.loading:t.loading}}),{oldState:r,newState:t,loading:n});return{newLoading:a.loading,newState:a.newState}}return{newState:t,newLoading:n}},exports.setGlobalConfig=function(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))},exports.updateErrorMap=l;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(r,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(r,t)};var r,t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(c,u)}a((n=n.apply(e,r||[])).next())}))}function o(e,r){var t,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,n=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=r.call(e,c)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function i(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}!function(e){e.REJECT="reject",e.IGNORE="ignore",e.KEEP_LAST="keepLast",e.KEEP_ALL="keepAll",e.PARALLEL="parallel",e.REUSE="reuse"}(r||(r={}));var c={clone:function(e){return JSON.parse(JSON.stringify(e))},comparator:function(e,r){if(Object.is(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;if(e instanceof Set||r instanceof Set)return!1;var t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(var o=0;o<t.length;o++)if(!Object.prototype.hasOwnProperty.call(r,t[o])||!Object.is(e[t[o]],r[t[o]]))return!1;return!0},asyncErrorHandler:function(){},retryOnErrorFunction:function(e){return e instanceof TypeError},notifySuccess:void 0,notifyError:void 0,notifyWarning:void 0,getErrorMessage:void 0,defaultMiddlewares:[]};function u(e){try{return c.clone(e)}catch(e){var r="StateDecorator: Cannot clone object. Call setCloneFunction with another implementation like lodash/cloneDeep.";throw"development"===process.env.NODE_ENV&&(console.error(r),console.error(e.toString())),new Error(r)}}function a(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&e.hasOwnProperty("getGetPromise")}function s(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=!1,a)),u))}function l(e,r,n,o){var i,c,u,a;return t(t({},e),o?((i={})[r]=t(t({},e[r]||{}),((c={})[n]=o,c)),i):((u={})[r]=t(t({},e[r]),((a={})[n]=void 0,a)),u))}var f=function(r){function t(e){var n=r.call(this,"Error")||this;return n.promiseIds=e,Object.setPrototypeOf(n,t.prototype),n}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,r),t}(Error);function d(e,r,t,i){return void 0===r&&(r=1),void 0===t&&(t=1e3),void 0===i&&(i=function(){return!0}),1===r?e:function(c){var u=e(c);return null===u?null:function u(a,s){return n(this,void 0,void 0,(function(){return o(this,(function(n){return null===s?[2,null]:[2,s.catch((function(n){return i(n)?a===r?Promise.reject(n):new Promise((function(r,n){setTimeout((function(){var t=e(c);u(a+1,t).then(r).catch(n)}),t*a)})):Promise.reject(n)}))]}))}))}(1,u)}}function p(e){return void 0===e&&(e=null),{current:e}}function v(e,r,t){var n,o;return{state:e.current,s:e.current,ds:null===(n=null==r?void 0:r.current)||void 0===n?void 0:n.state,derived:null===(o=null==r?void 0:r.current)||void 0===o?void 0:o.state,props:t.current,p:t.current}}function g(e,r,t,n,o,i){var c=v(e,r,t);return c.indices=n,c.index=o,c.isInit=i,c}function y(e,r,t,n,o){var i=v(e,r,t);return i.args=n,o&&(i.promiseId=o),i}function h(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.result=o,c.res=o,c}function E(e,r,t,n,o,i,c){var u=P(y(e,r,t,n,c),o);return u.abortSignal=i,u}function m(e,r){var t=e;return t.state=r.current,t.s=r.current,t}function P(e,r){var t=e;return t.actions=r.current,t.a=r.current,t}function S(e,r,t,n,o){var i,c=P(e,n);m(e,r);var u=null===(i=null==t?void 0:t.current)||void 0===i?void 0:i.state;return c.derived=u,c.ds=u,c.notifyWarning=o,c}function b(e){"development"===process.env.NODE_ENV&&console.warn("[state-decorator] ".concat(e," action was called while store is not initialized or destroyed, this is probably a leak"))}function w(e,r){return null==r?null:t(t({},e.current),r)}function A(e,r,t,n,o,i,c,u,a,s){var l,f=h(t,n,o,s,void 0),d=!1;if(null!=r.effects){var p=w(t,r.effects(f));null===p?d=!0:a(p,void 0,e,"effects",!1,f,!1)}if(!d)if(r.debounceSideEffectsTimeout>0){var v=c.current[e];v&&clearTimeout(v),c.current[e]=setTimeout((function(){var o;null===(o=r.sideEffects)||void 0===o||o.call(r,S(f,t,n,i,u.notifyWarning)),delete c.current[e]}),r.debounceSideEffectsTimeout)}else null===(l=r.sideEffects)||void 0===l||l.call(r,S(f,t,n,i,u.notifyWarning))}function x(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,l=e.promisesRef,f=e.actionsRef,d=e.loadingMapRef,p=e.conflictActionsRef,v=e.actionName,g=e.options,y=e.setState;if(e.initializedRef.current){var E=null,m=h(i,u,a,n,t,r);o.effects&&(E=w(i,o.effects(m))),y(E,s(d.current,v,r,!1),v,"effects",!0,m,!1);var P=g.notifySuccess||c.notifySuccess;if(P){var b=void 0;o.getSuccessMessage&&(b=o.getSuccessMessage(m)),b&&P(b)}return delete l.current[v][r],o.sideEffects&&o.sideEffects(S(m,i,u,f,c.notifyWarning)),j(v,f.current,p.current),t}}function O(e,r,t,n){var o=e.action,i=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,d=e.loadingMapRef,p=e.errorMapRef,v=e.promisesRef,g=e.conflictActionsRef,h=e.actionName,E=e.options,m=e.setState;if(e.initializedRef.current){var P=null,b=function(e,r,t,n,o,i){var c=y(e,r,t,n,i);return c.error=o,c.err=o,c}(i,u,a,n,t,r);o.errorEffects&&(P=w(i,o.errorEffects(b))),p.current=l(p.current,h,r,t),m(P,s(d.current,h,r,!1),h,"errorEffects",!0,b,!1);var A=!1;(null!=P||o.errorSideEffects||o.isErrorManaged)&&(A=!0);var x=E.notifyError||c.notifyError;if(x){var O=void 0;o.getErrorMessage&&(O=o.getErrorMessage(b)),void 0===O&&!A&&c.getErrorMessage&&(O=c.getErrorMessage(t)),O&&(A=!0,x(O))}return c.asyncErrorHandler(t,A||o.rejectPromiseOnError,i.current,a.current,h,n),delete v.current[h][r],o.errorSideEffects&&o.errorSideEffects(S(b,i,u,f,c.notifyWarning)),j(h,f.current,g.current),!A||o.rejectPromiseOnError?Promise.reject(t):Promise.resolve()}}var R="__def__";function C(e,r){return e.length===r.length&&-1===e.findIndex((function(e,t){return r[t]!==e}))}function L(e,t,n,o,i){var c=o;if(c===r.REUSE){if(C(e[n][R].refArgs,i))return e[n][R].promise;c=r.KEEP_ALL}return new Promise((function(e,o){var a={resolve:e,reject:o,args:u(i),timestamp:Date.now()};switch(c){case r.IGNORE:e(void 0);break;case r.REJECT:o(new Error("An asynchronous action ".concat(n," is already ongoing.")));break;case r.KEEP_LAST:t[n]=[a];break;case r.KEEP_ALL:var s=t[n];s||(t[n]=s=[]),s.push(a);break;case r.PARALLEL:case r.REUSE:}}))}function j(e,r,t){var n=t[e];if(n&&n.length>0){var o=t[e].shift();if(o){var i=r[e].apply(r,o.args);null==i?j(e,r,t):i.then((function(n){null===n&&j(e,r,t),o.resolve(n)})).catch((function(e){return o.reject(e)}))}}}exports.DEFAULT_PROMISE_ID=R,exports.ParallelActionError=f,exports.addContextActions=P,exports.addStateToContext=m,exports.areSameArgs=C,exports.buildErrorMap=function(e){return Object.keys(e).reduce((function(r,t){var n=e[t];if(null==n[R]);else if(n[R])r[t]=n[R];else{var o=Object.keys(n).reduce((function(e,r){return null!=n[r]&&(e.hasErr=!0,e.map[r]=n[r]),e}),{hasErr:!1,map:{}});o.hasErr&&(r[t]=new f(o.map))}return r}),{})},exports.buildInvocationContextBase=v,exports.buildLoadingMap=s,exports.buildOnMountInvocationContext=function(e,r,t,n){return P(v(e,r,t),n)},exports.buildOnPropChangeEffects=g,exports.computeAsyncActionInput=function(e){return a(e)?t(t({},e),{getPromise:e.getGetPromise,retryCount:3,conflictPolicy:r.REUSE}):e},exports.computeDerivedValues=function(e,r,t,n){if(null==(null==n?void 0:n.derivedState))return!1;var o=!1,i=c.comparator,u=t.current.deps,a=v(e,null,r),s=Object.keys(n.derivedState);return t.current.state=s.reduce((function(e,r){var c=!1,s=u[r],l=n.derivedState[r].getDeps(a);return c=null==s||null!=l.find((function(e,r){return s.length<r||!i(s[r],e)})),o=o||c,u[r]=l,e[r]=c?n.derivedState[r].get(a):t.current.state[r],e}),{}),o},exports.createRef=p,exports.decorateAsyncAction=function(e){var n=e.action,o=e.stateRef,u=e.derivedStateRef,a=e.propsRef,f=e.actionsRef,p=e.promisesRef,v=e.loadingMapRef,g=e.errorMapRef,h=e.initializedRef,m=e.conflictActionsRef,P=e.actionName,S=e.setState;return function(){for(var A,C,j,_=[],M=0;M<arguments.length;M++)_[M]=arguments[M];if(!h.current)return b(P),null;var T=p.current,k=n.conflictPolicy,I=void 0===k?r.KEEP_ALL:k,D=I===r.PARALLEL,G=null;if(D){if(!n.getPromiseId)throw new Error("If conflict policy is set to ConflictPolicy.PARALLEL, getPromiseId must be set and return a string.");G=n.getPromiseId.apply(n,_)}else G=R;if(!D&&(null===(C=T[P])||void 0===C?void 0:C[G]))return L(T,m.current,P,I,_);var N=null,K=!1,U=y(o,u,a,_,G);n.preEffects&&(N=w(o,n.preEffects(U)))&&(K=!0,o.current=N);var W=n.abortable,F=n.retryCount,z=n.retryDelaySeed,J=n.isTriggerRetryError,V=W&&window.AbortController?new AbortController:null,H=d(n.getPromise,F?1+F:1,z,J||c.retryOnErrorFunction),B=null===(j=H(E(o,u,a,_,f,null==V?void 0:V.signal)))||void 0===j?void 0:j.then((function(r){return x(e,G,r,_)})).catch((function(r){return O(e,G,r,_)}));return null!=B&&(T[P]=t(t({},T[P]||{}),((A={})[G||R]={abortController:V,promise:B,refArgs:I===r.REUSE&&_.length>0?i([],_,!0):[]},A))),g.current=l(g.current,P,G,null),S(null!=B||K?o.current:void 0,null==B?void 0:s(v.current,P,G,!0),P,"preEffects",!0,U,!1),B}},exports.decorateSimpleSyncAction=function(e,r,t,n,o,i,c){return function(){for(var u=[],a=0;a<arguments.length;a++)u[a]=arguments[a];if(i.current){var s=y(t,n,o,u),l=w(t,r(s));c(l,null,e,"effects",!1,s,!1)}else b(e)}},exports.decorateSyncAction=function(e,r,t,n,o,i,c,u,a,s){return function(){for(var l=[],f=0;f<arguments.length;f++)l[f]=arguments[f];if(c.current)if(r.debounceTimeout){var d=u.current[e];d&&clearTimeout(d),u.current[e]=setTimeout((function(){delete u.current[e],A(e,r,t,n,o,i,u,a,s,l)}),r.debounceTimeout)}else A(e,r,t,n,o,i,u,a,s,l);else b(e)}},exports.globalConfig=c,exports.isAsyncAction=function(e){return!(e instanceof Function)&&(e.hasOwnProperty("getPromise")||e.hasOwnProperty("getGetPromise"))},exports.isAsyncGetPromiseAction=function(e){return"function"!=typeof e&&e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.isAsyncGetPromiseGetAction=a,exports.isLoadingImpl=function(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];return r.some((function(r){var t,n=null,o=R;Array.isArray(r)?(n=r[0],o=void 0===(t=r[1])?R:t):n=r;var i=e[n];return null!=i&&(null!=i[o]&&i[o])}))},exports.isSimpleSyncAction=function(e){return"function"==typeof e},exports.isSyncAction=function(e){return"function"!=typeof e&&!e.hasOwnProperty("getPromise")&&!e.hasOwnProperty("getGetPromise")},exports.onPropChange=function(e,r,n,o,i,u,a,s){var l=null!=(null==u?void 0:u.derivedState);if(null!=u.onPropsChange){var f;f=Array.isArray(u.onPropsChange)?u.onPropsChange:[u.onPropsChange];var d=!1,v=p(e.current),y=[],h=c.comparator;f.forEach((function(t,i){var c,u=t.getDeps;if(u){var l=!1,f=[];if(s){if(!t.onMount)return;l=!0}else{var p=u(o),E=u(n.current);p.length!==E.length?(console.warn("options.onPropsChange.getDeps returned array must be stable (same length)"),l=!0):p.forEach((function(e,r){h(e,E[r])||(l=!0,f.push(r))}))}if(l){var m=g(v,r,n,f,i,s),P=w(e,null===(c=t.effects)||void 0===c?void 0:c.call(t,m));null!=P&&(d=!0,v.current=P,a(v.current,void 0,"onPropsChange","effects",!1,m,!0,s)),t.sideEffects&&y.push({index:i,indices:f,ctx:m})}}})),!d&&l&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0),y.length>0&&y.forEach((function(e){f[e.index].sideEffects(t(t({},m(P(e.ctx,i),v)),{indices:e.indices}))}))}else null!=(null==u?void 0:u.derivedState)&&a(void 0,void 0,"onPropsChange","effects",!1,null,!0)},exports.retryPromiseDecorator=d,exports.runMiddlewares=function(e,r,t,n,o,i,c,u){if("onPropsChange"===o&&void 0===t)return{newState:null,newLoading:!1};if(e&&e.length>0){var a=e.reduce((function(e,r){var t=r.effects({isAsync:c,name:o,type:i,context:u},e.oldState,e.newState,n);return{newState:(null==t?void 0:t.state)||e.newState,oldState:(null==t?void 0:t.state)?e.newState:e.oldState,loading:null==(null==t?void 0:t.loading)?e.loading:t.loading}}),{oldState:r,newState:t,loading:n});return{newLoading:a.loading,newState:a.newState}}return{newState:t,newLoading:n}},exports.setGlobalConfig=function(e){Object.keys(e).forEach((function(r){null!=e[r]&&(c[r]=e[r])}))},exports.updateErrorMap=l;
|
|
2
2
|
//# sourceMappingURL=impl.js.map
|