react-hooks-global-states 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -7
- package/lib/bundle.js +1304 -2
- package/lib/bundle.js.map +1 -0
- package/lib/src/GlobalStore.d.ts +3 -3
- package/lib/src/GlobalStore.types.d.ts +2 -0
- package/package.json +1 -1
- package/lib/bundle.js.LICENSE.txt +0 -1
package/lib/bundle.js
CHANGED
|
@@ -1,2 +1,1304 @@
|
|
|
1
|
-
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("react")):t["react-hooks-global-states"]=e(t.react)}(this,(t=>{return e={852:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.combineRetrieverAsynchronously=e.combineAsyncGetters=e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter=void 0;var i=r(608),a=r(156),u=r(774);e.combineAsyncGettersEmitter=function(t){for(var e,r,n,o=arguments.length,a=new Array(o>1?o-1:0),c=1;c<o;c++)a[c-1]=arguments[c];var l=a,s=new Map(l.map((function(t,e){return[e,t()]}))),f=t.selector(Array.from(s.values())),v=void 0!==(null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.isEqual)?null===(r=null==t?void 0:t.config)||void 0===r?void 0:r.isEqual:i.shallowCompare,p=new Set,y=(0,i.debounce)((function(){var e=t.selector(Array.from(s.values()));(null==v?void 0:v(f,e))||(f=e,p.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),d=l.map((function(t,e){return t((function(t){t((function(t){s.set(e,t),y()}))}))})),h=function(t,e,r){var n,o,a="function"==typeof e,u=a?t:null,c=a?e:t,l=a?r:e,s=Object.assign({delay:0,isEqual:i.shallowCompare},null!=l?l:{}),v=null!==(n=null==u?void 0:u(f))&&void 0!==n?n:f;s.skipFirst||c(v);var y=(0,i.debounce)((function(){var t,e,r=null!==(t=null==u?void 0:u(f))&&void 0!==t?t:f;(null===(e=s.isEqual)||void 0===e?void 0:e.call(s,v,r))||(v=r,c(r))}),null!==(o=s.delay)&&void 0!==o?o:0);return p.add(y),function(){p.delete(y)}};return[h,function(t){if(!t)return f;var e=[];return t((function(){e.push(h.apply(void 0,arguments))})),e.length||(0,u.throwNoSubscribersWereAdded)(),function(){e.forEach((function(t){t(),p.delete(t)}))}},function(){d.forEach((function(t){return t()}))}]},e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter,e.combineAsyncGetters=function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),u=1;u<r;u++)o[u-1]=arguments[u];var c=n(e.combineAsyncGettersEmitter.apply(void 0,[t].concat(o)),3),l=c[0],s=c[1],f=c[2];return[function(t,e){var r=n((0,a.useState)((function(){var e=s();return t?t(e):e})),2),o=r[0],u=r[1];return(0,a.useEffect)((function(){var r,n=Object.assign({delay:0,isEqual:i.shallowCompare},null!=e?e:{}),o=void 0!==n.isEqual?n.isEqual:i.shallowCompare,a=l((function(e){return t?t(e):e}),(0,i.debounce)((function(e){var r=t?t(e):e;(null==o?void 0:o(e,r))||u(r)}),null!==(r=n.delay)&&void 0!==r?r:0));return function(){a()}}),[]),[o,null,null]},s,f]},e.combineRetrieverAsynchronously=e.combineAsyncGetters},113:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createStatefulContext=void 0;var n,o=r(853),i=r(684),a=(n=r(156))&&n.__esModule?n:{default:n};e.createStatefulContext=function(t,e){var r=a.default.createContext(null);return[function(){return a.default.useContext(r)},function(n){var u=n.children,c=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}(n,["children"]),l=(0,o.createGlobalStateWithDecoupledFuncs)(function(){if(c.initialValue){if("function"==typeof c.initialValue)return c.initialValue((0,i.clone)(t));var e=Array.isArray(c.initialValue),r=c.initialValue instanceof Map,n=c.initialValue instanceof Set;return(0,i.isPrimitive)(c.initialValue)||(0,i.isDate)(c.initialValue)||e||r||n?c.initialValue:Object.assign(Object.assign({},t),c.initialValue)}return(0,i.clone)(t)}(),e);return a.default.createElement(r.Provider,{value:l},u)}]}},853:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var i=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r};Object.defineProperty(e,"__esModule",{value:!0}),e.createDerivateEmitter=e.createDerivate=e.createCustomGlobalStateWithDecoupledFuncs=e.createGlobalState=e.createGlobalStateWithDecoupledFuncs=void 0;var a=r(774);e.createGlobalStateWithDecoupledFuncs=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.actions,o=i(e,["actions"]),u=new a.GlobalStore(t,o,r),c=n(u.getHookDecoupled(),2),l=c[0],s=c[1];return[u.getHook(),l,s]},e.createGlobalState=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n((0,e.createGlobalStateWithDecoupledFuncs)(t,r),3),i=o[0],a=o[1],u=o[2];return i.stateControls=function(){return[a,u]},i},e.createCustomGlobalStateWithDecoupledFuncs=function(t){var r=t.onInitialize,n=t.onChange;return function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:null},a=o.config,u=o.onInit,c=o.onStateChanged,l=i(o,["config","onInit","onStateChanged"]);return(0,e.createGlobalStateWithDecoupledFuncs)(t,Object.assign({onInit:function(t){r(t,a),null==u||u(t)},onStateChanged:function(t){n(t,a),null==c||c(t)}},l))}},e.createDerivate=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(n){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t((function(t){var r=e(t);return n?n(r):r}),n&&o?o:r)}},e.createDerivateEmitter=function(t,r){var n=t._father_emitter;if(n){var o=function(t){var e=n.selector(t);return r(e)},i=(0,e.createDerivateEmitter)(n.getter,o);return i._father_emitter={getter:n.getter,selector:o},i}var a=function(e,n){var o="function"==typeof n,i=o?e:null,a=o?n:e,u=o?arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}:n;return t((function(t){t((function(t){var e,n=r(t);return null!==(e=null==i?void 0:i(n))&&void 0!==e?e:n}),a,u)}))};return a._father_emitter={getter:t,selector:r},a}},774:(t,e,r)=>{"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof y?e:y,a=Object.create(i.prototype),u=new P(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function v(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var p={};function y(){}function d(){}function h(){}var b={};s(b,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(C([])));m&&m!==e&&r.call(m,u)&&(b=m);var S=h.prototype=y.prototype=Object.create(b);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(o,a,u,c){var l=v(t[o],t,a);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==n(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){i("next",t,u,c)}),(function(t){i("throw",t,u,c)})):e.resolve(f).then((function(t){s.value=t,u(s)}),(function(t){return i("throw",t,u,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){i(t,r,e,n)}))}return a=a?a.then(n,n):n()}})}function j(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=A(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=v(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function A(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,A(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=v(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function C(t){if(t){var e=t[u];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:_}}function _(){return{value:void 0,done:!0}}return d.prototype=h,o(S,"constructor",{value:h,configurable:!0}),o(h,"constructor",{value:d,configurable:!0}),d.displayName=s(h,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},t.awrap=function(t){return{__await:t}},w(O.prototype),s(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(S),s(S,l,"Generator"),s(S,u,(function(){return this})),s(S,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=C,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:C(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,u(n.key),n)}}function u(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===n(e)?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStore=e.throwNoSubscribersWereAdded=void 0;var c=r(608),l=r(156);e.throwNoSubscribersWereAdded=function(){throw new Error("No new subscribers were added, please make sure to add at least one subscriber with the subscribe method")};var s=function(){function t(r){var n=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=s,this.subscribers=new Map,this.actions=null,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.initialize=function(){return t=n,e=void 0,r=void 0,o=i().mark((function t(){var e,r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.actionsConfig&&(this.actions=this.getStoreActionsMap()),e=this.onInit,r=this.config.onInit,e||r){t.next=5;break}return t.abrupt("return");case 5:n=this.getConfigCallbackParam(),null==e||e(n),null==r||r(n);case 8:case"end":return t.stop()}}),t,this)})),new(r||(r=Promise))((function(n,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function u(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}c((o=o.apply(t,e||[])).next())}));var t,e,r,o},this.setState=function(t){var e=t.state,r=t.forceUpdate;n.stateWrapper={state:e},Array.from(n.subscribers.values()).forEach((function(t){!function(t){var n=t.selector,o=t.callback,i=t.currentState,a=t.config,u=(null==a?void 0:a.isEqual)||null===(null==a?void 0:a.isEqual)?null==a?void 0:a.isEqual:n?c.shallowCompare:null,l=n?n(e):e;!r&&(null==u?void 0:u(i,l))||o({state:l})}(t)}))},this.setMetadata=function(t){var e,r,o="function"==typeof t?t(null!==(e=n.config.metadata)&&void 0!==e?e:null):t;n.config=Object.assign(Object.assign({},null!==(r=n.config)&&void 0!==r?r:{}),{metadata:o})},this.getMetadata=function(){var t;return null!==(t=n.config.metadata)&&void 0!==t?t:null},this.createChangesSubscriber=function(t){var e=t.callback,r=t.selector,o=t.config,i=r?r(n.stateWrapper.state):n.stateWrapper.state,a={state:i};return(null==o?void 0:o.skipFirst)||e(i),{stateWrapper:a,subscriptionCallback:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return n.stateWrapper.state;var r=[];return t((function(t,e,o){var i="function"==typeof e,a=i?t:null,u=i?e:t,l=i?o:e,s=n.createChangesSubscriber({selector:a,callback:u,config:l}),f=s.subscriptionCallback,v=s.stateWrapper,p=(0,c.uniqueId)();n.updateSubscription({subscriptionId:p,selector:a,config:l,stateWrapper:v,callback:f}),r.push(p)})),r.length||(0,e.throwNoSubscribersWereAdded)(),function(){r.forEach((function(t){n.subscribers.delete(t)}))}},this.getConfigCallbackParam=function(){var t=n.setMetadata,e=n.getMetadata,r=n.getState,o=n.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:n.setStateWrapper,actions:o}},this.updateSubscription=function(t){var e=t.subscriptionId,r=t.callback,o=t.selector,i=t.config,a=void 0===i?{}:i,u=t.stateWrapper.state,c=n.subscribers.get(e);if(c)return c.currentState=u,c;var l={subscriptionId:e,selector:o,config:a,currentState:u,callback:r};return n.subscribers.set(e,l),l},this.executeOnSubscribed=function(){var t=n.onSubscribed,e=n.config.onSubscribed;if(t||e){var r=n.getConfigCallbackParam();null==t||t(r),null==e||e(r)}},this.getHook=function(){return function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=(0,l.useRef)(null);(0,l.useEffect)((function(){return function(){n.subscribers.delete(i.current)}}),[]);var a,u,s=(a=(0,l.useState)((function(){return t?{state:t(n.stateWrapper.state)}:n.stateWrapper})),u=2,function(t){if(Array.isArray(t))return t}(a)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(a,u)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(a,u)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),f=s[0],v=s[1];return(0,l.useEffect)((function(){null===i.current&&(i.current=(0,c.uniqueId)())}),[]),(0,l.useEffect)((function(){var e=i.current;if(null!==e){var o=!n.subscribers.has(e);n.updateSubscription({subscriptionId:e,stateWrapper:f,selector:t,config:r,callback:v}),o&&n.executeOnSubscribed()}}),[f]),[f.state,n.getStateOrchestrator(),null!==(e=n.config.metadata)&&void 0!==e?e:null]}},this.getHookDecoupled=function(){var t=n.getStateOrchestrator(),e=n.getMetadata;return[n.getState,t,e]},this.getStateOrchestrator=function(){return n.actions?n.actions:n.setStateWrapper},this.hasStateCallbacks=function(){var t=n.computePreventStateChange,e=n.onStateChanged,r=n.config,o=r.computePreventStateChange,i=r.onStateChanged;return!!(t||o||e||i)},this.setStateWrapper=function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate,r="function"==typeof t,o=n.stateWrapper.state,i=r?t(o):t;if(e||!Object.is(n.stateWrapper.state,i)){var a=n.setMetadata,u=n.getMetadata,c=n.getState,l=n.actions,s={setMetadata:a,getMetadata:u,setState:n.setState,getState:c,actions:l,previousState:o,state:i},f=n.computePreventStateChange,v=n.config.computePreventStateChange;if((f||v)&&((null==f?void 0:f(s))||(null==v?void 0:v(s))))return;n.setState({forceUpdate:e,state:i});var p=n.onStateChanged,y=n.config.onStateChanged;(p||y)&&(null==p||p(s),null==y||y(s))}},this.getStoreActionsMap=function(){if(!n.actionsConfig)return null;var t=n.actionsConfig,e=n.setMetadata,r=n.setStateWrapper,o=n.getState,i=n.getMetadata,a=Object.keys(t).reduce((function(n,c){var l,s,f;return Object.assign(n,(l={},f=function(){for(var n=t[c],u=arguments.length,l=new Array(u),s=0;s<u;s++)l[s]=arguments[s];var f=n.apply(a,l);return"function"!=typeof f&&function(t){throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(t,"]: key is not a valid function, try something like this: \n{\n\n ").concat(t,": (param) => ({ setState, getState, setMetadata, getMetadata, actions }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(c),f.call(a,{setState:r,getState:o,setMetadata:e,getMetadata:i,actions:a})},(s=u(s=c))in l?Object.defineProperty(l,s,{value:f,enumerable:!0,configurable:!0,writable:!0}):l[s]=f,l)),n}),{});return a},this.stateWrapper={state:r},this.config=Object.assign({metadata:null},null!=a?a:{}),this.constructor!==t||this.initialize()}var r,n;return r=t,(n=[{key:"state",get:function(){return this.stateWrapper.state}}])&&a(r.prototype,n),Object.defineProperty(r,"prototype",{writable:!1}),t}();e.GlobalStore=s},530:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},608:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){c=!0,a=t},f:function(){try{u||null==r.return||r.return()}finally{if(c)throw a}}}}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueId=e.debounce=e.shallowCompare=void 0;var c=r(684);e.shallowCompare=function(t,e){if(t===e)return!0;var r=u(t),i=u(e);if(r!==i)return!1;if((0,c.isNil)(t)||(0,c.isNil)(e)||(0,c.isPrimitive)(t)&&(0,c.isPrimitive)(e)||(0,c.isDate)(t)&&(0,c.isDate)(e)||"function"===r&&"function"===i)return t===e;if(Array.isArray(t)){var a=t,l=e;if(a.length!==l.length)return!1;for(var s=0;s<a.length;s++)if(a[s]!==l[s])return!1}if(t instanceof Map){var f=t,v=e;if(f.size!==v.size)return!1;var p,y=o(f);try{for(y.s();!(p=y.n()).done;){var d=n(p.value,2),h=d[0];if(d[1]!==v.get(h))return!1}}catch(t){y.e(t)}finally{y.f()}}if(t instanceof Set){var b=t,g=e;if(b.size!==g.size)return!1;var m,S=o(b);try{for(S.s();!(m=S.n()).done;){var w=m.value;if(!g.has(w))return!1}}catch(t){S.e(t)}finally{S.f()}}var O=Object.keys(t),j=Object.keys(e);if(O.length!==j.length)return!1;for(var A=0,E=O;A<E.length;A++){var x=E[A];if(t[x]!==e[x])return!1}return!0},e.debounce=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return function(){for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){t.apply(void 0,o)}),r)}},e.uniqueId=function(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},195:(t,e,r)=>{"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStoreAbstract=void 0;var a=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}(c,t);var e,r,a,u=(r=c,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=i(r);if(a){var o=i(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function c(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.call(this,t,r,n)).onInit=function(t){e.onInitialize(t)},e.onStateChanged=function(t){e.onChange(t)},e}return e=c,Object.defineProperty(e,"prototype",{writable:!1}),e}(r(774).GlobalStore);e.GlobalStoreAbstract=a},991:(t,e,r)=>{"use strict";var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]},o=function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(684),e),o(r(530),e),o(r(774),e),o(r(195),e),o(r(853),e),o(r(608),e),o(r(852),e),o(r(113),e)},684:function(t){t.exports=(()=>{"use strict";var t={991:(t,e,r)=>{var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]};Object.defineProperty(e,"__esModule",{value:!0}),function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)}(r(729),e)},729:(t,e)=>{function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===r(e)?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.formatToStore=e.formatFromStore=e.isPrimitive=e.isFunction=e.isRegex=e.isDate=e.isString=e.isBoolean=e.isNumber=e.isNil=e.clone=void 0,e.clone=function(t){var r,a=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,e.isPrimitive)(t)||(0,e.isDate)(t))return t;if(Array.isArray(t))return a?function(t){if(Array.isArray(t))return i(t)}(r=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():t.map((function(t){return(0,e.clone)(t)}));if(t instanceof Map){var u=Array.from(t.entries());return a?new Map(u):new Map(u.map((function(t){return(0,e.clone)(t)})))}if(t instanceof Set){var c=Array.from(t.values());return a?new Set(c):new Set(c.map((function(t){return(0,e.clone)(t)})))}return t instanceof RegExp?new RegExp(t.toString()):(0,e.isFunction)(t)?a?t:Object.create(t):a?Object.assign({},t):t instanceof Error?new Error(t.message):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.clone)(i)))}),{})},e.isNil=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isBoolean=function(t){return"boolean"==typeof t},e.isString=function(t){return"string"==typeof t},e.isDate=function(t){return t instanceof Date},e.isRegex=function(t){return t instanceof RegExp},e.isFunction=function(t){return"function"==typeof t||t instanceof Function},e.isPrimitive=function(t){return(0,e.isNil)(t)||(0,e.isNumber)(t)||(0,e.isBoolean)(t)||(0,e.isString)(t)||"symbol"===r(t)},e.formatFromStore=function(t){return function(t){var r,i;if((0,e.isPrimitive)(t))return t;if("date"===(null==t?void 0:t.$t))return new Date(t.$v);if("map"===(null==t?void 0:t.$t)){var a=(null!==(r=t.$v)&&void 0!==r?r:[]).map((function(t){var r,n=(2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{for(i=(r=r.call(t)).next,0;!(c=(n=i.call(r)).done)&&(u.push(n.value),2!==u.length);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(r)||o(r,2)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=n[0],a=n[1];return[i,(0,e.formatFromStore)(a)]}));return new Map(a)}if("set"===(null==t?void 0:t.$t)){var u=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(u)}return"regex"===(null==t?void 0:t.$t)?new RegExp(t.$v):"error"===(null==t?void 0:t.$t)?new Error(t.$v):Array.isArray(t)?t.map((function(t){return(0,e.formatFromStore)(t)})):"function"===(null==t?void 0:t.$t)?Function("(".concat(t.$v,")(...arguments)")):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?JSON.parse(t):(0,e.clone)(t))},e.formatToStore=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,a=o.validator,u=o.excludeTypes,c=o.excludeKeys,l=new Set(null!=u?u:[]),s=new Set(null!=c?c:[]),f=l.size||s.size,v=null!=a?a:function(t){var e=t.key,n=t.value;if(!f)return!0;var o=s.has(e),i=l.has(r(n));return!o&&!i},p=function t(r){if((0,e.isPrimitive)(r))return r;if(Array.isArray(r))return r.map((function(e){return t(e)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(e){return t(e)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(e){return t(e)}))};if((0,e.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,e.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,e.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:Object.keys(r).reduce((function(e,o){var i=r[o],a=t(i);return v({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(p):p}}},e={};return function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}(991)})()},156:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(991);var e,r}));
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory(require("react"));
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define(["react"], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["react-hooks-global-states"] = factory(require("react"));
|
|
8
|
+
else
|
|
9
|
+
root["react-hooks-global-states"] = factory(root["react"]);
|
|
10
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE_react__) => {
|
|
11
|
+
return /******/ (() => { // webpackBootstrap
|
|
12
|
+
/******/ var __webpack_modules__ = ({
|
|
13
|
+
|
|
14
|
+
/***/ "./src/GlobalStore.combiners.ts":
|
|
15
|
+
/*!**************************************!*\
|
|
16
|
+
!*** ./src/GlobalStore.combiners.ts ***!
|
|
17
|
+
\**************************************/
|
|
18
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
24
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
27
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
28
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
29
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
30
|
+
value: true
|
|
31
|
+
}));
|
|
32
|
+
exports.combineRetrieverAsynchronously = exports.combineAsyncGetters = exports.combineRetrieverEmitterAsynchronously = exports.combineAsyncGettersEmitter = void 0;
|
|
33
|
+
var GlobalStore_utils_1 = __webpack_require__(/*! ./GlobalStore.utils */ "./src/GlobalStore.utils.ts");
|
|
34
|
+
var react_1 = __webpack_require__(/*! react */ "react");
|
|
35
|
+
var GlobalStore_1 = __webpack_require__(/*! ./GlobalStore */ "./src/GlobalStore.ts");
|
|
36
|
+
/**
|
|
37
|
+
* @description
|
|
38
|
+
* This function allows you to create a derivate state by merging the state of multiple hooks.
|
|
39
|
+
* The update of the derivate state is debounced to avoid unnecessary re-renders.
|
|
40
|
+
* By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
|
|
41
|
+
* @returns a tuple with the following elements: [subscribe, getState, dispose]
|
|
42
|
+
*/
|
|
43
|
+
var combineAsyncGettersEmitter = function combineAsyncGettersEmitter(parameters) {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
46
|
+
args[_key - 1] = arguments[_key];
|
|
47
|
+
}
|
|
48
|
+
var getters = args;
|
|
49
|
+
var dictionary = new Map(getters.map(function (useHook, index) {
|
|
50
|
+
return [index, useHook()];
|
|
51
|
+
}));
|
|
52
|
+
var parentState = parameters.selector(Array.from(dictionary.values()));
|
|
53
|
+
var parentIsEqual = ((_a = parameters === null || parameters === void 0 ? void 0 : parameters.config) === null || _a === void 0 ? void 0 : _a.isEqual) !== undefined ? (_b = parameters === null || parameters === void 0 ? void 0 : parameters.config) === null || _b === void 0 ? void 0 : _b.isEqual : GlobalStore_utils_1.shallowCompare;
|
|
54
|
+
var subscribers = new Set();
|
|
55
|
+
var updateMainState = (0, GlobalStore_utils_1.debounce)(function () {
|
|
56
|
+
var newState = parameters.selector(Array.from(dictionary.values()));
|
|
57
|
+
if (parentIsEqual === null || parentIsEqual === void 0 ? void 0 : parentIsEqual(parentState, newState)) return;
|
|
58
|
+
// update the parent state so the subscribers can be notified
|
|
59
|
+
parentState = newState;
|
|
60
|
+
subscribers.forEach(function (childCallback) {
|
|
61
|
+
return childCallback();
|
|
62
|
+
});
|
|
63
|
+
}, (_c = parameters === null || parameters === void 0 ? void 0 : parameters.config) === null || _c === void 0 ? void 0 : _c.delay);
|
|
64
|
+
var getterSubscriptions = getters.map(function (useHook, index) {
|
|
65
|
+
return useHook(function (subscribe) {
|
|
66
|
+
subscribe(function (value) {
|
|
67
|
+
dictionary.set(index, value);
|
|
68
|
+
updateMainState();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var subscribe = function subscribe(
|
|
73
|
+
/**
|
|
74
|
+
* @description
|
|
75
|
+
* The callback function to subscribe to the store changes or a selector function to derive the state
|
|
76
|
+
*/
|
|
77
|
+
param1,
|
|
78
|
+
/**
|
|
79
|
+
* @description
|
|
80
|
+
* The configuration object or the callback function to subscribe to the store changes
|
|
81
|
+
*/
|
|
82
|
+
param2,
|
|
83
|
+
/**
|
|
84
|
+
* @description
|
|
85
|
+
* The configuration object
|
|
86
|
+
*/
|
|
87
|
+
param3) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
var hasExplicitSelector = typeof param2 === 'function';
|
|
90
|
+
var selector = hasExplicitSelector ? param1 : null;
|
|
91
|
+
var callback = hasExplicitSelector ? param2 : param1;
|
|
92
|
+
var config = hasExplicitSelector ? param3 : param2;
|
|
93
|
+
var $config = Object.assign({
|
|
94
|
+
delay: 0,
|
|
95
|
+
isEqual: GlobalStore_utils_1.shallowCompare
|
|
96
|
+
}, config !== null && config !== void 0 ? config : {});
|
|
97
|
+
var childState = (_a = selector === null || selector === void 0 ? void 0 : selector(parentState)) !== null && _a !== void 0 ? _a : parentState;
|
|
98
|
+
if (!$config.skipFirst) {
|
|
99
|
+
// execute immediately the callback with the current state
|
|
100
|
+
callback(childState);
|
|
101
|
+
}
|
|
102
|
+
var updateState = (0, GlobalStore_utils_1.debounce)(function () {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
var newChildState = (_a = selector === null || selector === void 0 ? void 0 : selector(parentState)) !== null && _a !== void 0 ? _a : parentState;
|
|
105
|
+
// if the new state is equal to the current state, then we don't need to update the state
|
|
106
|
+
if ((_b = $config.isEqual) === null || _b === void 0 ? void 0 : _b.call($config, childState, newChildState)) return;
|
|
107
|
+
childState = newChildState;
|
|
108
|
+
callback(newChildState);
|
|
109
|
+
}, (_b = $config.delay) !== null && _b !== void 0 ? _b : 0);
|
|
110
|
+
subscribers.add(updateState);
|
|
111
|
+
return function () {
|
|
112
|
+
subscribers["delete"](updateState);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
var stateGetter = function stateGetter($callback) {
|
|
116
|
+
// if there is no subscription callback return the state
|
|
117
|
+
if (!$callback) return parentState;
|
|
118
|
+
var internalSubscribers = [];
|
|
119
|
+
$callback(function () {
|
|
120
|
+
internalSubscribers.push(subscribe.apply(void 0, arguments));
|
|
121
|
+
});
|
|
122
|
+
if (!internalSubscribers.length) {
|
|
123
|
+
(0, GlobalStore_1.throwNoSubscribersWereAdded)();
|
|
124
|
+
}
|
|
125
|
+
return function () {
|
|
126
|
+
internalSubscribers.forEach(function (unsubscribe) {
|
|
127
|
+
unsubscribe();
|
|
128
|
+
subscribers["delete"](unsubscribe);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
return [subscribe, stateGetter, function () {
|
|
133
|
+
getterSubscriptions.forEach(function (unsubscribe) {
|
|
134
|
+
return unsubscribe();
|
|
135
|
+
});
|
|
136
|
+
}];
|
|
137
|
+
};
|
|
138
|
+
exports.combineAsyncGettersEmitter = combineAsyncGettersEmitter;
|
|
139
|
+
exports.combineRetrieverEmitterAsynchronously = exports.combineAsyncGettersEmitter;
|
|
140
|
+
/**
|
|
141
|
+
* @description
|
|
142
|
+
* This function allows you to create a derivate state by merging the state of multiple hooks.
|
|
143
|
+
* The update of the derivate state is debounced to avoid unnecessary re-renders.
|
|
144
|
+
* By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
|
|
145
|
+
* @returns A tuple containing the subscribe function, the state getter and the dispose function
|
|
146
|
+
*/
|
|
147
|
+
var combineAsyncGetters = function combineAsyncGetters(parameters) {
|
|
148
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
149
|
+
args[_key2 - 1] = arguments[_key2];
|
|
150
|
+
}
|
|
151
|
+
var _ref = (0, exports.combineAsyncGettersEmitter).apply(void 0, [parameters].concat(args)),
|
|
152
|
+
_ref2 = _slicedToArray(_ref, 3),
|
|
153
|
+
subscribe = _ref2[0],
|
|
154
|
+
getState = _ref2[1],
|
|
155
|
+
dispose = _ref2[2];
|
|
156
|
+
var useHook = function useHook(selector, config) {
|
|
157
|
+
var _ref3 = (0, react_1.useState)(function () {
|
|
158
|
+
var parentState = getState();
|
|
159
|
+
return selector ? selector(parentState) : parentState;
|
|
160
|
+
}),
|
|
161
|
+
_ref4 = _slicedToArray(_ref3, 2),
|
|
162
|
+
state = _ref4[0],
|
|
163
|
+
setState = _ref4[1];
|
|
164
|
+
(0, react_1.useEffect)(function () {
|
|
165
|
+
var _a;
|
|
166
|
+
var $config = Object.assign({
|
|
167
|
+
delay: 0,
|
|
168
|
+
isEqual: GlobalStore_utils_1.shallowCompare
|
|
169
|
+
}, config !== null && config !== void 0 ? config : {});
|
|
170
|
+
var compareCallback = $config.isEqual !== undefined ? $config.isEqual : GlobalStore_utils_1.shallowCompare;
|
|
171
|
+
var unsubscribe = subscribe(function (state) {
|
|
172
|
+
return selector ? selector(state) : state;
|
|
173
|
+
}, (0, GlobalStore_utils_1.debounce)(function (state) {
|
|
174
|
+
var newState = selector ? selector(state) : state;
|
|
175
|
+
if (compareCallback === null || compareCallback === void 0 ? void 0 : compareCallback(state, newState)) return;
|
|
176
|
+
setState(newState);
|
|
177
|
+
}, (_a = $config.delay) !== null && _a !== void 0 ? _a : 0));
|
|
178
|
+
return function () {
|
|
179
|
+
unsubscribe();
|
|
180
|
+
};
|
|
181
|
+
}, []);
|
|
182
|
+
return [state, null, null];
|
|
183
|
+
};
|
|
184
|
+
return [useHook, getState, dispose];
|
|
185
|
+
};
|
|
186
|
+
exports.combineAsyncGetters = combineAsyncGetters;
|
|
187
|
+
exports.combineRetrieverAsynchronously = exports.combineAsyncGetters;
|
|
188
|
+
|
|
189
|
+
/***/ }),
|
|
190
|
+
|
|
191
|
+
/***/ "./src/GlobalStore.context.ts":
|
|
192
|
+
/*!************************************!*\
|
|
193
|
+
!*** ./src/GlobalStore.context.ts ***!
|
|
194
|
+
\************************************/
|
|
195
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
196
|
+
|
|
197
|
+
"use strict";
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
201
|
+
var t = {};
|
|
202
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
203
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
204
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
205
|
+
}
|
|
206
|
+
return t;
|
|
207
|
+
};
|
|
208
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
209
|
+
return mod && mod.__esModule ? mod : {
|
|
210
|
+
"default": mod
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
214
|
+
value: true
|
|
215
|
+
}));
|
|
216
|
+
exports.createStatefulContext = void 0;
|
|
217
|
+
var GlobalStore_functionHooks_1 = __webpack_require__(/*! ../src/GlobalStore.functionHooks */ "./src/GlobalStore.functionHooks.ts");
|
|
218
|
+
var json_storage_formatter_1 = __webpack_require__(/*! json-storage-formatter */ "./node_modules/json-storage-formatter/lib/bundle.js");
|
|
219
|
+
var react_1 = __importDefault(__webpack_require__(/*! react */ "react"));
|
|
220
|
+
var createStatefulContext = function createStatefulContext(initialValue, parameters) {
|
|
221
|
+
var context = react_1["default"].createContext(null);
|
|
222
|
+
var useHook = function useHook() {
|
|
223
|
+
return react_1["default"].useContext(context);
|
|
224
|
+
};
|
|
225
|
+
var Provider = function Provider(_a) {
|
|
226
|
+
var children = _a.children,
|
|
227
|
+
props = __rest(_a, ["children"]);
|
|
228
|
+
var hook = (0, GlobalStore_functionHooks_1.createGlobalStateWithDecoupledFuncs)(function () {
|
|
229
|
+
if (props.initialValue) {
|
|
230
|
+
var isFunction = typeof props.initialValue === 'function';
|
|
231
|
+
if (isFunction) return props.initialValue((0, json_storage_formatter_1.clone)(initialValue));
|
|
232
|
+
var isArray = Array.isArray(props.initialValue);
|
|
233
|
+
var isMap = props.initialValue instanceof Map;
|
|
234
|
+
var isSet = props.initialValue instanceof Set;
|
|
235
|
+
var isMergeAble = !(0, json_storage_formatter_1.isPrimitive)(props.initialValue) && !(0, json_storage_formatter_1.isDate)(props.initialValue) && !isArray && !isMap && !isSet;
|
|
236
|
+
return isMergeAble ? Object.assign(Object.assign({}, initialValue), props.initialValue) : props.initialValue;
|
|
237
|
+
}
|
|
238
|
+
// return a copy of the initial value to avoid reference issues
|
|
239
|
+
// this initial value will be reused in all the instances of the hook
|
|
240
|
+
return (0, json_storage_formatter_1.clone)(initialValue);
|
|
241
|
+
}(), parameters);
|
|
242
|
+
return react_1["default"].createElement(context.Provider, {
|
|
243
|
+
value: hook
|
|
244
|
+
}, children);
|
|
245
|
+
};
|
|
246
|
+
return [useHook, Provider];
|
|
247
|
+
};
|
|
248
|
+
exports.createStatefulContext = createStatefulContext;
|
|
249
|
+
|
|
250
|
+
/***/ }),
|
|
251
|
+
|
|
252
|
+
/***/ "./src/GlobalStore.functionHooks.ts":
|
|
253
|
+
/*!******************************************!*\
|
|
254
|
+
!*** ./src/GlobalStore.functionHooks.ts ***!
|
|
255
|
+
\******************************************/
|
|
256
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
257
|
+
|
|
258
|
+
"use strict";
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
262
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
263
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
264
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
265
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
266
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
267
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
268
|
+
var t = {};
|
|
269
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
270
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
271
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
272
|
+
}
|
|
273
|
+
return t;
|
|
274
|
+
};
|
|
275
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
276
|
+
value: true
|
|
277
|
+
}));
|
|
278
|
+
exports.createDerivateEmitter = exports.createDerivate = exports.createCustomGlobalStateWithDecoupledFuncs = exports.createGlobalState = exports.createGlobalStateWithDecoupledFuncs = void 0;
|
|
279
|
+
var GlobalStore_1 = __webpack_require__(/*! ./GlobalStore */ "./src/GlobalStore.ts");
|
|
280
|
+
/**
|
|
281
|
+
* Creates a global state with the given state and config.
|
|
282
|
+
* @returns {} [HOOK, DECOUPLED_RETRIEVER, DECOUPLED_MUTATOR] this is an array with the hook, the decoupled getState function and the decoupled setter of the state
|
|
283
|
+
*/
|
|
284
|
+
var createGlobalStateWithDecoupledFuncs = function createGlobalStateWithDecoupledFuncs(state) {
|
|
285
|
+
var _a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
286
|
+
var actions = _a.actions,
|
|
287
|
+
config = __rest(_a, ["actions"]);
|
|
288
|
+
var store = new GlobalStore_1.GlobalStore(state, config, actions);
|
|
289
|
+
var _store$getHookDecoupl = store.getHookDecoupled(),
|
|
290
|
+
_store$getHookDecoupl2 = _slicedToArray(_store$getHookDecoupl, 2),
|
|
291
|
+
getState = _store$getHookDecoupl2[0],
|
|
292
|
+
setter = _store$getHookDecoupl2[1];
|
|
293
|
+
return [store.getHook(), getState, setter];
|
|
294
|
+
};
|
|
295
|
+
exports.createGlobalStateWithDecoupledFuncs = createGlobalStateWithDecoupledFuncs;
|
|
296
|
+
/**
|
|
297
|
+
* Creates a global hook that can be used to access the state and actions across the application
|
|
298
|
+
* @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
|
|
299
|
+
*/
|
|
300
|
+
var createGlobalState = function createGlobalState(state) {
|
|
301
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
302
|
+
var _ref = (0, exports.createGlobalStateWithDecoupledFuncs)(state, config),
|
|
303
|
+
_ref2 = _slicedToArray(_ref, 3),
|
|
304
|
+
useState = _ref2[0],
|
|
305
|
+
stateRetriever = _ref2[1],
|
|
306
|
+
stateMutator = _ref2[2];
|
|
307
|
+
useState.stateControls = function () {
|
|
308
|
+
return [stateRetriever, stateMutator];
|
|
309
|
+
};
|
|
310
|
+
return useState;
|
|
311
|
+
};
|
|
312
|
+
exports.createGlobalState = createGlobalState;
|
|
313
|
+
/**
|
|
314
|
+
* @description
|
|
315
|
+
* Use this function to create a custom global store.
|
|
316
|
+
* You can use this function to create a store with async storage.
|
|
317
|
+
*/
|
|
318
|
+
var createCustomGlobalStateWithDecoupledFuncs = function createCustomGlobalStateWithDecoupledFuncs(_ref3) {
|
|
319
|
+
var onInitialize = _ref3.onInitialize,
|
|
320
|
+
onChange = _ref3.onChange;
|
|
321
|
+
/**
|
|
322
|
+
* @description
|
|
323
|
+
* Use this function to create a custom global store.
|
|
324
|
+
* You can use this function to create a store with async storage or any other custom logic.
|
|
325
|
+
* @param state The initial state of the store.
|
|
326
|
+
* @param config The configuration of the store.
|
|
327
|
+
* @returns [HOOK, DECOUPLED_RETRIEVER, DECOUPLED_MUTATOR] - this is an array with the hook, the decoupled getState function and the decoupled setter of the state
|
|
328
|
+
*/
|
|
329
|
+
return function (state) {
|
|
330
|
+
var _a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
331
|
+
config: null
|
|
332
|
+
};
|
|
333
|
+
var customConfig = _a.config,
|
|
334
|
+
onInit = _a.onInit,
|
|
335
|
+
onStateChanged = _a.onStateChanged,
|
|
336
|
+
parameters = __rest(_a, ["config", "onInit", "onStateChanged"]);
|
|
337
|
+
var onInitWrapper = function onInitWrapper(callBackParameters) {
|
|
338
|
+
onInitialize(callBackParameters, customConfig);
|
|
339
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(callBackParameters);
|
|
340
|
+
};
|
|
341
|
+
var onStateChangeWrapper = function onStateChangeWrapper(callBackParameters) {
|
|
342
|
+
onChange(callBackParameters, customConfig);
|
|
343
|
+
onStateChanged === null || onStateChanged === void 0 ? void 0 : onStateChanged(callBackParameters);
|
|
344
|
+
};
|
|
345
|
+
return (0, exports.createGlobalStateWithDecoupledFuncs)(state, Object.assign({
|
|
346
|
+
onInit: onInitWrapper,
|
|
347
|
+
onStateChanged: onStateChangeWrapper
|
|
348
|
+
}, parameters));
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
exports.createCustomGlobalStateWithDecoupledFuncs = createCustomGlobalStateWithDecoupledFuncs;
|
|
352
|
+
/**
|
|
353
|
+
* @description
|
|
354
|
+
* Use this function to create a custom global hook which contains a fragment of the state of another hook or a fragment
|
|
355
|
+
*/
|
|
356
|
+
var createDerivate = function createDerivate(useHook, selector_) {
|
|
357
|
+
var config_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
358
|
+
return function (selector) {
|
|
359
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
360
|
+
return useHook(function (state) {
|
|
361
|
+
var fragment = selector_(state);
|
|
362
|
+
return selector ? selector(fragment) : fragment;
|
|
363
|
+
}, selector && config ? config : config_);
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
exports.createDerivate = createDerivate;
|
|
367
|
+
/**
|
|
368
|
+
* @description
|
|
369
|
+
* This function allows you to create a derivate emitter
|
|
370
|
+
* With this approach, you can subscribe to changes in a specific fragment or subset of the state.
|
|
371
|
+
*/
|
|
372
|
+
var createDerivateEmitter = function createDerivateEmitter(getter, selector) {
|
|
373
|
+
var father_emitter = getter._father_emitter;
|
|
374
|
+
if (father_emitter) {
|
|
375
|
+
// if a subscriber is already a derivate emitter, then we need to merge the selectors
|
|
376
|
+
var selectorWrapper = function selectorWrapper(state) {
|
|
377
|
+
var fatherFragment = father_emitter.selector(state);
|
|
378
|
+
return selector(fatherFragment);
|
|
379
|
+
};
|
|
380
|
+
var _subscriber = (0, exports.createDerivateEmitter)(father_emitter.getter, selectorWrapper);
|
|
381
|
+
_subscriber._father_emitter = {
|
|
382
|
+
getter: father_emitter.getter,
|
|
383
|
+
selector: selectorWrapper
|
|
384
|
+
};
|
|
385
|
+
return _subscriber;
|
|
386
|
+
}
|
|
387
|
+
var subscriber = function subscriber(param1, param2) {
|
|
388
|
+
var param3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
389
|
+
var hasExplicitSelector = typeof param2 === 'function';
|
|
390
|
+
var $selector = hasExplicitSelector ? param1 : null;
|
|
391
|
+
var callback = hasExplicitSelector ? param2 : param1;
|
|
392
|
+
var config = hasExplicitSelector ? param3 : param2;
|
|
393
|
+
return getter(function (subscribe) {
|
|
394
|
+
subscribe(function (state) {
|
|
395
|
+
var _a;
|
|
396
|
+
var fatherFragment = selector(state);
|
|
397
|
+
return (_a = $selector === null || $selector === void 0 ? void 0 : $selector(fatherFragment)) !== null && _a !== void 0 ? _a : fatherFragment;
|
|
398
|
+
}, callback, config);
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
subscriber._father_emitter = {
|
|
402
|
+
getter: getter,
|
|
403
|
+
selector: selector
|
|
404
|
+
};
|
|
405
|
+
return subscriber;
|
|
406
|
+
};
|
|
407
|
+
exports.createDerivateEmitter = createDerivateEmitter;
|
|
408
|
+
|
|
409
|
+
/***/ }),
|
|
410
|
+
|
|
411
|
+
/***/ "./src/GlobalStore.ts":
|
|
412
|
+
/*!****************************!*\
|
|
413
|
+
!*** ./src/GlobalStore.ts ***!
|
|
414
|
+
\****************************/
|
|
415
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
416
|
+
|
|
417
|
+
"use strict";
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
421
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
422
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
423
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
424
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
425
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
426
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
427
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
428
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
429
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
430
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
431
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
432
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
433
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
434
|
+
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
435
|
+
function adopt(value) {
|
|
436
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
437
|
+
resolve(value);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
441
|
+
function fulfilled(value) {
|
|
442
|
+
try {
|
|
443
|
+
step(generator.next(value));
|
|
444
|
+
} catch (e) {
|
|
445
|
+
reject(e);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function rejected(value) {
|
|
449
|
+
try {
|
|
450
|
+
step(generator["throw"](value));
|
|
451
|
+
} catch (e) {
|
|
452
|
+
reject(e);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function step(result) {
|
|
456
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
457
|
+
}
|
|
458
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
462
|
+
value: true
|
|
463
|
+
}));
|
|
464
|
+
exports.GlobalStore = exports.throwNoSubscribersWereAdded = void 0;
|
|
465
|
+
var GlobalStore_utils_1 = __webpack_require__(/*! ./GlobalStore.utils */ "./src/GlobalStore.utils.ts");
|
|
466
|
+
var react_1 = __webpack_require__(/*! react */ "react");
|
|
467
|
+
var throwWrongKeyOnActionCollectionConfig = function throwWrongKeyOnActionCollectionConfig(action_key) {
|
|
468
|
+
throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(action_key, "]: key is not a valid function, try something like this: \n{\n\n ").concat(action_key, ": (param) => ({ setState, getState, setMetadata, getMetadata, actions }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"));
|
|
469
|
+
};
|
|
470
|
+
var throwNoSubscribersWereAdded = function throwNoSubscribersWereAdded() {
|
|
471
|
+
throw new Error('No new subscribers were added, please make sure to add at least one subscriber with the subscribe method');
|
|
472
|
+
};
|
|
473
|
+
exports.throwNoSubscribersWereAdded = throwNoSubscribersWereAdded;
|
|
474
|
+
var uniqueSymbol = Symbol('unique');
|
|
475
|
+
/**
|
|
476
|
+
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
477
|
+
* @template {TState} TState - The type of the state object
|
|
478
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
479
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
480
|
+
* */
|
|
481
|
+
var GlobalStore = /*#__PURE__*/function () {
|
|
482
|
+
/**
|
|
483
|
+
* Create a new instance of the GlobalStore
|
|
484
|
+
* @param {TState} state - The initial state
|
|
485
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config - The configuration object (optional) (default: { metadata: null })
|
|
486
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config.metadata - The metadata object (optional) (default: null) if not null the metadata object will be reactive
|
|
487
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
|
|
488
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
|
|
489
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config.onSubscribed - The callback to execute when a new component gets subscribed to the store (optional) (default: null)
|
|
490
|
+
* @param {GlobalStoreConfig<TState, TMetadata>} config.computePreventStateChange - The callback to execute every time a state change is triggered and before the state is updated, it allows to prevent the state change by returning true (optional) (default: null) * @param {TStateMutator} actionsConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
|
|
491
|
+
* */
|
|
492
|
+
function GlobalStore(state) {
|
|
493
|
+
var _this = this;
|
|
494
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
495
|
+
var actionsConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
496
|
+
_classCallCheck(this, GlobalStore);
|
|
497
|
+
this.actionsConfig = actionsConfig;
|
|
498
|
+
/**
|
|
499
|
+
* list of all the subscribers setState functions
|
|
500
|
+
* @template {TState} TState - The type of the state object
|
|
501
|
+
* */
|
|
502
|
+
this.subscribers = new Map();
|
|
503
|
+
/**
|
|
504
|
+
* Actions of the store
|
|
505
|
+
*/
|
|
506
|
+
this.actions = null;
|
|
507
|
+
/**
|
|
508
|
+
* additional configuration for the store
|
|
509
|
+
* @template {TState} TState - The type of the state object
|
|
510
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
511
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
512
|
+
* @property {GlobalStoreConfig<TState, TMetadata, TStateMutator>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
|
|
513
|
+
* @property {GlobalStoreConfig<TState, TMetadata, TStateMutator>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
|
|
514
|
+
* @property {GlobalStoreConfig<TState, TMetadata, TStateMutator>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
|
|
515
|
+
* @property {GlobalStoreConfig<TState, TMetadata, TStateMutator>} config.onSubscribed - The callback to execute when a component is subscribed to the store (optional) (default: null)
|
|
516
|
+
* @property {GlobalStoreConfig<TState, TMetadata, TStateMutator>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
|
|
517
|
+
*/
|
|
518
|
+
this.config = {
|
|
519
|
+
metadata: null
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* execute once the store is created
|
|
523
|
+
* @template {TState} TState - The type of the state object
|
|
524
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
525
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
526
|
+
* @param {StateConfigCallbackParam<TState, TMetadata, TStateMutator>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
|
|
527
|
+
* @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
|
|
528
|
+
* @param {() => TState} parameters.getState - The getState function to get the state
|
|
529
|
+
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
530
|
+
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
531
|
+
* */
|
|
532
|
+
this.onInit = null;
|
|
533
|
+
/**
|
|
534
|
+
* execute every time the state is changed
|
|
535
|
+
* @template {TState} TState - The type of the state object
|
|
536
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
537
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
538
|
+
* @param {StateConfigCallbackParam<TState, TMetadata, TStateMutator>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
|
|
539
|
+
* @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
|
|
540
|
+
* @param {() => TState} parameters.getState - The getState function to get the state
|
|
541
|
+
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
542
|
+
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
543
|
+
* */
|
|
544
|
+
this.onStateChanged = null;
|
|
545
|
+
/**
|
|
546
|
+
* Execute each time a new component gets subscribed to the store
|
|
547
|
+
* @template {TState} TState - The type of the state object
|
|
548
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
549
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
550
|
+
* @param {StateConfigCallbackParam<TState, TMetadata, TStateMutator>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
|
|
551
|
+
* @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
|
|
552
|
+
* @param {() => TState} parameters.getState - The getState function to get the state
|
|
553
|
+
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
554
|
+
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
555
|
+
* */
|
|
556
|
+
this.onSubscribed = null;
|
|
557
|
+
/**
|
|
558
|
+
* Execute every time a state change is triggered and before the state is updated, it allows to prevent the state change by returning true
|
|
559
|
+
* @template {TState} TState - The type of the state object
|
|
560
|
+
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
561
|
+
* @template {TStateMutator} TStateMutator - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
562
|
+
* @param {StateConfigCallbackParam<TState, TMetadata, TStateMutator>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
|
|
563
|
+
* @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
|
|
564
|
+
* @param {() => TState} parameters.getState - The getState function to get the state
|
|
565
|
+
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
566
|
+
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
567
|
+
* @returns {boolean} - true to prevent the state change, false to allow the state change
|
|
568
|
+
* */
|
|
569
|
+
this.computePreventStateChange = null;
|
|
570
|
+
this.initialize = function () {
|
|
571
|
+
return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
572
|
+
var onInit, onInitFromConfig, parameters;
|
|
573
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
574
|
+
while (1) switch (_context.prev = _context.next) {
|
|
575
|
+
case 0:
|
|
576
|
+
/**
|
|
577
|
+
* actions map is created just once after the initialization
|
|
578
|
+
*/
|
|
579
|
+
if (this.actionsConfig) {
|
|
580
|
+
this.actions = this.getStoreActionsMap();
|
|
581
|
+
}
|
|
582
|
+
onInit = this.onInit;
|
|
583
|
+
onInitFromConfig = this.config.onInit;
|
|
584
|
+
if (!(!onInit && !onInitFromConfig)) {
|
|
585
|
+
_context.next = 5;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
return _context.abrupt("return");
|
|
589
|
+
case 5:
|
|
590
|
+
parameters = this.getConfigCallbackParam();
|
|
591
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(parameters);
|
|
592
|
+
onInitFromConfig === null || onInitFromConfig === void 0 ? void 0 : onInitFromConfig(parameters);
|
|
593
|
+
case 8:
|
|
594
|
+
case "end":
|
|
595
|
+
return _context.stop();
|
|
596
|
+
}
|
|
597
|
+
}, _callee, this);
|
|
598
|
+
}));
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* set the state and update all the subscribers
|
|
602
|
+
* @param {StateSetter<TState>} setter - The setter function or the value to set
|
|
603
|
+
* */
|
|
604
|
+
this.setState = function (_ref) {
|
|
605
|
+
var newRootState = _ref.state,
|
|
606
|
+
forceUpdate = _ref.forceUpdate;
|
|
607
|
+
var currentRootState = _this.stateWrapper.state;
|
|
608
|
+
// update the main state
|
|
609
|
+
_this.stateWrapper = {
|
|
610
|
+
state: newRootState
|
|
611
|
+
};
|
|
612
|
+
var executeSetState = function executeSetState(parameters) {
|
|
613
|
+
var _a, _b;
|
|
614
|
+
var selector = parameters.selector,
|
|
615
|
+
callback = parameters.callback,
|
|
616
|
+
currentChildState = parameters.currentState,
|
|
617
|
+
config = parameters.config;
|
|
618
|
+
// compare the root state, there should not be a re-render if the root state is the same
|
|
619
|
+
if (!forceUpdate && ((_a = config === null || config === void 0 ? void 0 : config.isEqualRoot) !== null && _a !== void 0 ? _a : function (a, b) {
|
|
620
|
+
return Object.is(a, b);
|
|
621
|
+
})(currentRootState, newRootState)) return;
|
|
622
|
+
var newChildState = selector ? selector(newRootState) : newRootState;
|
|
623
|
+
// compare the result after the selector is executed
|
|
624
|
+
if (!forceUpdate && ((_b = config === null || config === void 0 ? void 0 : config.isEqual) !== null && _b !== void 0 ? _b : function (a, b) {
|
|
625
|
+
return Object.is(a, b);
|
|
626
|
+
})(currentChildState, newChildState)) return;
|
|
627
|
+
// this in the case of the hooks is the setState function
|
|
628
|
+
callback({
|
|
629
|
+
state: newChildState
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
var subscribers = Array.from(_this.subscribers.values());
|
|
633
|
+
// update all the subscribers
|
|
634
|
+
for (var index = 0; index < subscribers.length; index++) {
|
|
635
|
+
var parameters = subscribers[index];
|
|
636
|
+
executeSetState(parameters);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* Set the value of the metadata property, this is no reactive and will not trigger a re-render
|
|
641
|
+
* @param {MetadataSetter<TMetadata>} setter - The setter function or the value to set
|
|
642
|
+
* */
|
|
643
|
+
this.setMetadata = function (setter) {
|
|
644
|
+
var _a, _b;
|
|
645
|
+
var isSetterFunction = typeof setter === 'function';
|
|
646
|
+
var metadata = isSetterFunction ? setter((_a = _this.config.metadata) !== null && _a !== void 0 ? _a : null) : setter;
|
|
647
|
+
_this.config = Object.assign(Object.assign({}, (_b = _this.config) !== null && _b !== void 0 ? _b : {}), {
|
|
648
|
+
metadata: metadata
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
this.getMetadata = function () {
|
|
652
|
+
var _a;
|
|
653
|
+
return (_a = _this.config.metadata) !== null && _a !== void 0 ? _a : null;
|
|
654
|
+
};
|
|
655
|
+
this.createChangesSubscriber = function (_ref2) {
|
|
656
|
+
var callback = _ref2.callback,
|
|
657
|
+
selector = _ref2.selector,
|
|
658
|
+
config = _ref2.config;
|
|
659
|
+
var initialState = selector ? selector(_this.stateWrapper.state) : _this.stateWrapper.state;
|
|
660
|
+
var stateWrapper = {
|
|
661
|
+
state: initialState
|
|
662
|
+
};
|
|
663
|
+
var subscriptionCallback = function subscriptionCallback(_ref3) {
|
|
664
|
+
var state = _ref3.state;
|
|
665
|
+
stateWrapper.state = state;
|
|
666
|
+
callback(state);
|
|
667
|
+
};
|
|
668
|
+
if (!(config === null || config === void 0 ? void 0 : config.skipFirst)) {
|
|
669
|
+
callback(initialState);
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
stateWrapper: stateWrapper,
|
|
673
|
+
subscriptionCallback: subscriptionCallback
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
/**
|
|
677
|
+
* Return current state of the store
|
|
678
|
+
* Optionally you can use this method to subscribe a callback to the store changes
|
|
679
|
+
* @param {UseHookConfig<TState, TDerivate>} config - The configuration object (optional) (default: { selector: null, subscriptionCallback: null, config: null })
|
|
680
|
+
* @param {TSelector} config.selector - The selector function to derive the state (optional) (default: null)
|
|
681
|
+
* @param {TSubscriptionCallback} config.subscriptionCallback - The callback to execute every time the state is changed
|
|
682
|
+
* @param {UseHookConfig<TState, TDerivate>} config.config - The configuration for the callback (optional) (default: null)
|
|
683
|
+
* @param {UseHookConfig<TState, TDerivate>} config.config.isEqual - The compare function to check if the state is changed (optional) (default: shallowCompare)
|
|
684
|
+
* @returns The state of the store, optionally if you provide a subscriptionCallback it this method will return the unsubscribe function
|
|
685
|
+
*/
|
|
686
|
+
this.getState = function ($callback) {
|
|
687
|
+
// if there is no subscription callback return the state
|
|
688
|
+
if (!$callback) return _this.stateWrapper.state;
|
|
689
|
+
var changesSubscribers = [];
|
|
690
|
+
var subscribe = function subscribe(param1, param2, param3) {
|
|
691
|
+
var hasExplicitSelector = typeof param2 === 'function';
|
|
692
|
+
var selector = hasExplicitSelector ? param1 : null;
|
|
693
|
+
var callback = hasExplicitSelector ? param2 : param1;
|
|
694
|
+
var config = hasExplicitSelector ? param3 : param2;
|
|
695
|
+
var _this$createChangesSu = _this.createChangesSubscriber({
|
|
696
|
+
selector: selector,
|
|
697
|
+
callback: callback,
|
|
698
|
+
config: config
|
|
699
|
+
}),
|
|
700
|
+
subscriptionCallback = _this$createChangesSu.subscriptionCallback,
|
|
701
|
+
stateWrapper = _this$createChangesSu.stateWrapper;
|
|
702
|
+
var subscriptionId = (0, GlobalStore_utils_1.uniqueId)();
|
|
703
|
+
_this.updateSubscription({
|
|
704
|
+
subscriptionId: subscriptionId,
|
|
705
|
+
selector: selector,
|
|
706
|
+
config: config,
|
|
707
|
+
stateWrapper: stateWrapper,
|
|
708
|
+
callback: subscriptionCallback
|
|
709
|
+
});
|
|
710
|
+
changesSubscribers.push(subscriptionId);
|
|
711
|
+
};
|
|
712
|
+
$callback(subscribe);
|
|
713
|
+
if (!changesSubscribers.length) {
|
|
714
|
+
(0, exports.throwNoSubscribersWereAdded)();
|
|
715
|
+
}
|
|
716
|
+
return function () {
|
|
717
|
+
changesSubscribers.forEach(function (subscriber) {
|
|
718
|
+
_this.subscribers["delete"](subscriber);
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
/**
|
|
723
|
+
* get the parameters object to pass to the callback functions (onInit, onStateChanged, onSubscribed, computePreventStateChange)
|
|
724
|
+
* this parameters object brings the following properties: setState, getState, setMetadata, getMetadata
|
|
725
|
+
* this parameter object allows to update the state, get the state, update the metadata, get the metadata
|
|
726
|
+
* @returns {StateConfigCallbackParam<TState, TMetadata>} - The parameters object
|
|
727
|
+
* */
|
|
728
|
+
this.getConfigCallbackParam = function () {
|
|
729
|
+
var setMetadata = _this.setMetadata,
|
|
730
|
+
getMetadata = _this.getMetadata,
|
|
731
|
+
getState = _this.getState,
|
|
732
|
+
actions = _this.actions,
|
|
733
|
+
setStateWrapper = _this.setStateWrapper;
|
|
734
|
+
return {
|
|
735
|
+
setMetadata: setMetadata,
|
|
736
|
+
getMetadata: getMetadata,
|
|
737
|
+
getState: getState,
|
|
738
|
+
setState: setStateWrapper,
|
|
739
|
+
actions: actions
|
|
740
|
+
};
|
|
741
|
+
};
|
|
742
|
+
this.updateSubscription = function (_ref4) {
|
|
743
|
+
var subscriptionId = _ref4.subscriptionId,
|
|
744
|
+
callback = _ref4.callback,
|
|
745
|
+
selector = _ref4.selector,
|
|
746
|
+
_ref4$config = _ref4.config,
|
|
747
|
+
config = _ref4$config === void 0 ? {} : _ref4$config,
|
|
748
|
+
stateWrapper = _ref4.stateWrapper;
|
|
749
|
+
var subscriber = _this.subscribers.get(subscriptionId);
|
|
750
|
+
if (subscriber) {
|
|
751
|
+
// every time the hook is called we update the reference of the state derivate state
|
|
752
|
+
// this allows to compare the state and trigger the callback only when the state is changed
|
|
753
|
+
if (stateWrapper) subscriber.currentState = stateWrapper === null || stateWrapper === void 0 ? void 0 : stateWrapper.state;
|
|
754
|
+
// update other dependencies if present
|
|
755
|
+
if (selector) subscriber.selector = selector;
|
|
756
|
+
if (config) subscriber.config = config;
|
|
757
|
+
if (callback) subscriber.callback;
|
|
758
|
+
return subscriber;
|
|
759
|
+
}
|
|
760
|
+
var newSubscriber = {
|
|
761
|
+
subscriptionId: subscriptionId,
|
|
762
|
+
selector: selector,
|
|
763
|
+
config: config,
|
|
764
|
+
currentState: stateWrapper.state,
|
|
765
|
+
callback: callback
|
|
766
|
+
};
|
|
767
|
+
_this.subscribers.set(subscriptionId, newSubscriber);
|
|
768
|
+
return newSubscriber;
|
|
769
|
+
};
|
|
770
|
+
this.executeOnSubscribed = function () {
|
|
771
|
+
var onSubscribed = _this.onSubscribed;
|
|
772
|
+
var onSubscribedFromConfig = _this.config.onSubscribed;
|
|
773
|
+
if (onSubscribed || onSubscribedFromConfig) {
|
|
774
|
+
var parameters = _this.getConfigCallbackParam();
|
|
775
|
+
onSubscribed === null || onSubscribed === void 0 ? void 0 : onSubscribed(parameters);
|
|
776
|
+
onSubscribedFromConfig === null || onSubscribedFromConfig === void 0 ? void 0 : onSubscribedFromConfig(parameters);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
/**
|
|
780
|
+
* Returns a custom hook that allows to handle a global state
|
|
781
|
+
* @returns {[TState, TStateMutator, TMetadata]} - The state, the state setter or the actions map, the metadata
|
|
782
|
+
* */
|
|
783
|
+
this.getHook = function () {
|
|
784
|
+
return function (selector) {
|
|
785
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
786
|
+
var _a;
|
|
787
|
+
var subscriptionRef = (0, react_1.useRef)({
|
|
788
|
+
id: null,
|
|
789
|
+
dependencies: uniqueSymbol
|
|
790
|
+
});
|
|
791
|
+
// remove the subscription when the component is unmounted
|
|
792
|
+
(0, react_1.useEffect)(function () {
|
|
793
|
+
return function () {
|
|
794
|
+
_this.subscribers["delete"](subscriptionRef.current.id);
|
|
795
|
+
};
|
|
796
|
+
}, []);
|
|
797
|
+
var computeStateWrapper = function computeStateWrapper() {
|
|
798
|
+
if (selector) {
|
|
799
|
+
return {
|
|
800
|
+
state: selector(_this.stateWrapper.state)
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
return _this.stateWrapper;
|
|
804
|
+
};
|
|
805
|
+
var _ref5 = (0, react_1.useState)(computeStateWrapper),
|
|
806
|
+
_ref6 = _slicedToArray(_ref5, 2),
|
|
807
|
+
stateWrapper = _ref6[0],
|
|
808
|
+
setState = _ref6[1];
|
|
809
|
+
// by using a ref we can avoid to lose the id when StrictMode is enabled
|
|
810
|
+
(0, react_1.useEffect)(function () {
|
|
811
|
+
if (subscriptionRef.current.id !== null) return;
|
|
812
|
+
subscriptionRef.current.id = (0, GlobalStore_utils_1.uniqueId)();
|
|
813
|
+
}, []);
|
|
814
|
+
(0, react_1.useEffect)(function () {
|
|
815
|
+
var subscriptionId = subscriptionRef.current.id;
|
|
816
|
+
if (subscriptionId === null) return;
|
|
817
|
+
var isFirstTime = !_this.subscribers.has(subscriptionId);
|
|
818
|
+
// prepare the values for the orchestrator
|
|
819
|
+
_this.updateSubscription(Object.assign({
|
|
820
|
+
subscriptionId: subscriptionId,
|
|
821
|
+
stateWrapper: stateWrapper
|
|
822
|
+
}, isFirstTime && {
|
|
823
|
+
selector: selector,
|
|
824
|
+
config: config,
|
|
825
|
+
callback: setState
|
|
826
|
+
}));
|
|
827
|
+
if (!isFirstTime) return;
|
|
828
|
+
_this.executeOnSubscribed();
|
|
829
|
+
}, [stateWrapper]);
|
|
830
|
+
return [function () {
|
|
831
|
+
var _subscriptionRef$curr = subscriptionRef.current,
|
|
832
|
+
subscriptionId = _subscriptionRef$curr.id,
|
|
833
|
+
oldDependencies = _subscriptionRef$curr.dependencies;
|
|
834
|
+
var _ref7 = config !== null && config !== void 0 ? config : {},
|
|
835
|
+
newDependencies = _ref7.dependencies;
|
|
836
|
+
// update the dependencies
|
|
837
|
+
subscriptionRef.current.dependencies = newDependencies;
|
|
838
|
+
if (subscriptionId === null) return stateWrapper.state;
|
|
839
|
+
// make sure we don't proceed if wa ere just adding the dependencies
|
|
840
|
+
if (oldDependencies === uniqueSymbol) return stateWrapper.state;
|
|
841
|
+
// if the dependencies are the same we don't need to update the subscription
|
|
842
|
+
if (newDependencies === oldDependencies) return stateWrapper.state;
|
|
843
|
+
var haveDifferentLength = (oldDependencies === null || oldDependencies === void 0 ? void 0 : oldDependencies.length) !== (newDependencies === null || newDependencies === void 0 ? void 0 : newDependencies.length);
|
|
844
|
+
var haveDifferentValues = haveDifferentLength || !(0, GlobalStore_utils_1.shallowCompare)(oldDependencies, newDependencies);
|
|
845
|
+
if (!haveDifferentLength && !haveDifferentValues) return stateWrapper.state;
|
|
846
|
+
// this will be the state of the component but will not be part of react state yet
|
|
847
|
+
var impureStateWrapper = computeStateWrapper();
|
|
848
|
+
_this.updateSubscription({
|
|
849
|
+
subscriptionId: subscriptionId,
|
|
850
|
+
stateWrapper: impureStateWrapper,
|
|
851
|
+
selector: selector,
|
|
852
|
+
config: config
|
|
853
|
+
});
|
|
854
|
+
// we need to update directly the reference to be compatible with strict mode
|
|
855
|
+
stateWrapper.state = impureStateWrapper.state;
|
|
856
|
+
return impureStateWrapper.state;
|
|
857
|
+
}(), _this.getStateOrchestrator(), (_a = _this.config.metadata) !== null && _a !== void 0 ? _a : null];
|
|
858
|
+
};
|
|
859
|
+
};
|
|
860
|
+
/**
|
|
861
|
+
* Returns an array with the a function to get the state, the state setter or the actions map, and a function to get the metadata
|
|
862
|
+
* @returns {[() => TState, TStateMutator, () => TMetadata]} - The state getter, the state setter or the actions map, the metadata getter
|
|
863
|
+
* */
|
|
864
|
+
this.getHookDecoupled = function () {
|
|
865
|
+
var stateOrchestrator = _this.getStateOrchestrator();
|
|
866
|
+
var getMetadata = _this.getMetadata,
|
|
867
|
+
getState = _this.getState;
|
|
868
|
+
return [getState, stateOrchestrator, getMetadata];
|
|
869
|
+
};
|
|
870
|
+
/**
|
|
871
|
+
* Returns the state setter or the actions map
|
|
872
|
+
* @returns {TStateMutator} - The state setter or the actions map
|
|
873
|
+
* */
|
|
874
|
+
this.getStateOrchestrator = function () {
|
|
875
|
+
return function () {
|
|
876
|
+
if (_this.actions) {
|
|
877
|
+
return _this.actions;
|
|
878
|
+
}
|
|
879
|
+
return _this.setStateWrapper;
|
|
880
|
+
}();
|
|
881
|
+
};
|
|
882
|
+
/**
|
|
883
|
+
* Calculate whenever or not we should compute the callback parameters on the state change
|
|
884
|
+
* @returns {boolean} - True if we should compute the callback parameters on the state change
|
|
885
|
+
* */
|
|
886
|
+
this.hasStateCallbacks = function () {
|
|
887
|
+
var computePreventStateChange = _this.computePreventStateChange,
|
|
888
|
+
onStateChanged = _this.onStateChanged;
|
|
889
|
+
var _this$config = _this.config,
|
|
890
|
+
computePreventStateChangeFromConfig = _this$config.computePreventStateChange,
|
|
891
|
+
onStateChangedFromConfig = _this$config.onStateChanged;
|
|
892
|
+
var preventStateChangesCalls = computePreventStateChange || computePreventStateChangeFromConfig;
|
|
893
|
+
var stateChangeCalls = onStateChanged || onStateChangedFromConfig;
|
|
894
|
+
var shouldComputeParameter = preventStateChangesCalls || stateChangeCalls;
|
|
895
|
+
return !!shouldComputeParameter;
|
|
896
|
+
};
|
|
897
|
+
/**
|
|
898
|
+
* This is responsible for defining whenever or not the state change should be allowed or prevented
|
|
899
|
+
* the function also execute the functions:
|
|
900
|
+
* - onStateChanged (if defined) - this function is executed after the state change
|
|
901
|
+
* - computePreventStateChange (if defined) - this function is executed before the state change and it should return a boolean value that will be used to determine if the state change should be prevented or not
|
|
902
|
+
*/
|
|
903
|
+
this.setStateWrapper = function (setter) {
|
|
904
|
+
var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
905
|
+
forceUpdate = _ref8.forceUpdate;
|
|
906
|
+
var isSetterFunction = typeof setter === 'function';
|
|
907
|
+
var previousState = _this.stateWrapper.state;
|
|
908
|
+
var newState = isSetterFunction ? setter(previousState) : setter;
|
|
909
|
+
// if the state didn't change, we don't need to do anything
|
|
910
|
+
if (!forceUpdate && Object.is(_this.stateWrapper.state, newState)) return;
|
|
911
|
+
var setMetadata = _this.setMetadata,
|
|
912
|
+
getMetadata = _this.getMetadata,
|
|
913
|
+
getState = _this.getState,
|
|
914
|
+
actions = _this.actions,
|
|
915
|
+
setState = _this.setState;
|
|
916
|
+
var callbackParameter = {
|
|
917
|
+
setMetadata: setMetadata,
|
|
918
|
+
getMetadata: getMetadata,
|
|
919
|
+
setState: setState,
|
|
920
|
+
getState: getState,
|
|
921
|
+
actions: actions,
|
|
922
|
+
previousState: previousState,
|
|
923
|
+
state: newState
|
|
924
|
+
};
|
|
925
|
+
var computePreventStateChange = _this.computePreventStateChange;
|
|
926
|
+
var computePreventStateChangeFromConfig = _this.config.computePreventStateChange;
|
|
927
|
+
// check if the state change should be prevented
|
|
928
|
+
if (computePreventStateChange || computePreventStateChangeFromConfig) {
|
|
929
|
+
var preventStateChange = (computePreventStateChange === null || computePreventStateChange === void 0 ? void 0 : computePreventStateChange(callbackParameter)) || (computePreventStateChangeFromConfig === null || computePreventStateChangeFromConfig === void 0 ? void 0 : computePreventStateChangeFromConfig(callbackParameter));
|
|
930
|
+
if (preventStateChange) return;
|
|
931
|
+
}
|
|
932
|
+
_this.setState({
|
|
933
|
+
forceUpdate: forceUpdate,
|
|
934
|
+
state: newState
|
|
935
|
+
});
|
|
936
|
+
var onStateChanged = _this.onStateChanged;
|
|
937
|
+
var onStateChangedFromConfig = _this.config.onStateChanged;
|
|
938
|
+
if (!onStateChanged && !onStateChangedFromConfig) return;
|
|
939
|
+
onStateChanged === null || onStateChanged === void 0 ? void 0 : onStateChanged(callbackParameter);
|
|
940
|
+
onStateChangedFromConfig === null || onStateChangedFromConfig === void 0 ? void 0 : onStateChangedFromConfig(callbackParameter);
|
|
941
|
+
};
|
|
942
|
+
/**
|
|
943
|
+
* This creates a map of actions that can be used to modify or interact with the state
|
|
944
|
+
* @returns {ActionCollectionResult<TState, TMetadata, TStateMutator>} - The actions map result of the configuration object passed to the constructor
|
|
945
|
+
* */
|
|
946
|
+
this.getStoreActionsMap = function () {
|
|
947
|
+
if (!_this.actionsConfig) return null;
|
|
948
|
+
var actionsConfig = _this.actionsConfig,
|
|
949
|
+
setMetadata = _this.setMetadata,
|
|
950
|
+
setStateWrapper = _this.setStateWrapper,
|
|
951
|
+
getState = _this.getState,
|
|
952
|
+
getMetadata = _this.getMetadata;
|
|
953
|
+
var actionsKeys = Object.keys(actionsConfig);
|
|
954
|
+
// we bind the functions to the actions object to allow reusing actions in the same api config by using the -this- keyword
|
|
955
|
+
var actions = actionsKeys.reduce(function (accumulator, action_key) {
|
|
956
|
+
Object.assign(accumulator, _defineProperty({}, action_key, function () {
|
|
957
|
+
var actionConfig = actionsConfig[action_key];
|
|
958
|
+
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
959
|
+
parameters[_key] = arguments[_key];
|
|
960
|
+
}
|
|
961
|
+
var action = actionConfig.apply(actions, parameters);
|
|
962
|
+
var actionIsNotAFunction = typeof action !== 'function';
|
|
963
|
+
// we throw an error if the action is not a function, this is mandatory for the correct execution of the actions
|
|
964
|
+
if (actionIsNotAFunction) {
|
|
965
|
+
throwWrongKeyOnActionCollectionConfig(action_key);
|
|
966
|
+
}
|
|
967
|
+
// executes the actions bringing access to the state setter and a copy of the state
|
|
968
|
+
var result = action.call(actions, {
|
|
969
|
+
setState: setStateWrapper,
|
|
970
|
+
getState: getState,
|
|
971
|
+
setMetadata: setMetadata,
|
|
972
|
+
getMetadata: getMetadata,
|
|
973
|
+
actions: actions
|
|
974
|
+
});
|
|
975
|
+
// we return the result of the actions to the invoker
|
|
976
|
+
return result;
|
|
977
|
+
}));
|
|
978
|
+
return accumulator;
|
|
979
|
+
}, {});
|
|
980
|
+
return actions;
|
|
981
|
+
};
|
|
982
|
+
this.stateWrapper = {
|
|
983
|
+
state: state
|
|
984
|
+
};
|
|
985
|
+
this.config = Object.assign({
|
|
986
|
+
metadata: null
|
|
987
|
+
}, config !== null && config !== void 0 ? config : {});
|
|
988
|
+
var isExtensionClass = this.constructor !== GlobalStore;
|
|
989
|
+
if (isExtensionClass) return;
|
|
990
|
+
this.initialize();
|
|
991
|
+
}
|
|
992
|
+
_createClass(GlobalStore, [{
|
|
993
|
+
key: "state",
|
|
994
|
+
get:
|
|
995
|
+
/**
|
|
996
|
+
* @deprecated direct modifications of the state could end up in unexpected behaviors
|
|
997
|
+
*/
|
|
998
|
+
function get() {
|
|
999
|
+
return this.stateWrapper.state;
|
|
1000
|
+
}
|
|
1001
|
+
}]);
|
|
1002
|
+
return GlobalStore;
|
|
1003
|
+
}();
|
|
1004
|
+
exports.GlobalStore = GlobalStore;
|
|
1005
|
+
|
|
1006
|
+
/***/ }),
|
|
1007
|
+
|
|
1008
|
+
/***/ "./src/GlobalStore.types.ts":
|
|
1009
|
+
/*!**********************************!*\
|
|
1010
|
+
!*** ./src/GlobalStore.types.ts ***!
|
|
1011
|
+
\**********************************/
|
|
1012
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
1013
|
+
|
|
1014
|
+
"use strict";
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
1018
|
+
value: true
|
|
1019
|
+
}));
|
|
1020
|
+
|
|
1021
|
+
/***/ }),
|
|
1022
|
+
|
|
1023
|
+
/***/ "./src/GlobalStore.utils.ts":
|
|
1024
|
+
/*!**********************************!*\
|
|
1025
|
+
!*** ./src/GlobalStore.utils.ts ***!
|
|
1026
|
+
\**********************************/
|
|
1027
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1028
|
+
|
|
1029
|
+
"use strict";
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
1033
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1034
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
1035
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1036
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
1037
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
1038
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1039
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1040
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
1041
|
+
value: true
|
|
1042
|
+
}));
|
|
1043
|
+
exports.uniqueId = exports.debounce = exports.shallowCompare = void 0;
|
|
1044
|
+
var json_storage_formatter_1 = __webpack_require__(/*! json-storage-formatter */ "./node_modules/json-storage-formatter/lib/bundle.js");
|
|
1045
|
+
/**
|
|
1046
|
+
* Shallow compare two values and return true if they are equal.
|
|
1047
|
+
* This function just compare the first level of the values.
|
|
1048
|
+
* @param value1
|
|
1049
|
+
* @param value2
|
|
1050
|
+
* @returns {boolean} true if the values are equal, false otherwise
|
|
1051
|
+
*/
|
|
1052
|
+
var shallowCompare = function shallowCompare(value1, value2) {
|
|
1053
|
+
var isEqual = value1 === value2;
|
|
1054
|
+
if (isEqual) return true;
|
|
1055
|
+
var typeofValue1 = _typeof(value1);
|
|
1056
|
+
var typeofValue2 = _typeof(value2);
|
|
1057
|
+
if (typeofValue1 !== typeofValue2) return false;
|
|
1058
|
+
if ((0, json_storage_formatter_1.isNil)(value1) || (0, json_storage_formatter_1.isNil)(value2) || (0, json_storage_formatter_1.isPrimitive)(value1) && (0, json_storage_formatter_1.isPrimitive)(value2) || (0, json_storage_formatter_1.isDate)(value1) && (0, json_storage_formatter_1.isDate)(value2) || typeofValue1 === "function" && typeofValue2 === "function") {
|
|
1059
|
+
return value1 === value2;
|
|
1060
|
+
}
|
|
1061
|
+
var isArray = Array.isArray(value1);
|
|
1062
|
+
if (isArray) {
|
|
1063
|
+
var array1 = value1;
|
|
1064
|
+
var array2 = value2;
|
|
1065
|
+
if (array1.length !== array2.length) return false;
|
|
1066
|
+
for (var i = 0; i < array1.length; i++) {
|
|
1067
|
+
var _value = array1[i];
|
|
1068
|
+
var _value2 = array2[i];
|
|
1069
|
+
if (_value !== _value2) return false;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
var isMap = value1 instanceof Map;
|
|
1073
|
+
if (isMap) {
|
|
1074
|
+
var map1 = value1;
|
|
1075
|
+
var map2 = value2;
|
|
1076
|
+
if (map1.size !== map2.size) return false;
|
|
1077
|
+
var _iterator = _createForOfIteratorHelper(map1),
|
|
1078
|
+
_step;
|
|
1079
|
+
try {
|
|
1080
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1081
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
1082
|
+
key = _step$value[0],
|
|
1083
|
+
value = _step$value[1];
|
|
1084
|
+
var _value3 = map2.get(key);
|
|
1085
|
+
if (value !== _value3) return false;
|
|
1086
|
+
}
|
|
1087
|
+
} catch (err) {
|
|
1088
|
+
_iterator.e(err);
|
|
1089
|
+
} finally {
|
|
1090
|
+
_iterator.f();
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
var isSet = value1 instanceof Set;
|
|
1094
|
+
if (isSet) {
|
|
1095
|
+
var set1 = value1;
|
|
1096
|
+
var set2 = value2;
|
|
1097
|
+
if (set1.size !== set2.size) return false;
|
|
1098
|
+
var _iterator2 = _createForOfIteratorHelper(set1),
|
|
1099
|
+
_step2;
|
|
1100
|
+
try {
|
|
1101
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1102
|
+
var _value4 = _step2.value;
|
|
1103
|
+
if (!set2.has(_value4)) return false;
|
|
1104
|
+
}
|
|
1105
|
+
} catch (err) {
|
|
1106
|
+
_iterator2.e(err);
|
|
1107
|
+
} finally {
|
|
1108
|
+
_iterator2.f();
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
// for objects
|
|
1112
|
+
var keys1 = Object.keys(value1);
|
|
1113
|
+
var keys2 = Object.keys(value2);
|
|
1114
|
+
if (keys1.length !== keys2.length) return false;
|
|
1115
|
+
for (var _i2 = 0, _keys = keys1; _i2 < _keys.length; _i2++) {
|
|
1116
|
+
var _key = _keys[_i2];
|
|
1117
|
+
var propObject1 = value1[_key];
|
|
1118
|
+
var propObject2 = value2[_key];
|
|
1119
|
+
if (propObject1 !== propObject2) return false;
|
|
1120
|
+
}
|
|
1121
|
+
return true;
|
|
1122
|
+
};
|
|
1123
|
+
exports.shallowCompare = shallowCompare;
|
|
1124
|
+
/**
|
|
1125
|
+
* Debounce a function.
|
|
1126
|
+
*/
|
|
1127
|
+
var debounce = function debounce(callback) {
|
|
1128
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1129
|
+
var timeout;
|
|
1130
|
+
return function () {
|
|
1131
|
+
for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
|
|
1132
|
+
args[_key2] = arguments[_key2];
|
|
1133
|
+
}
|
|
1134
|
+
if (timeout) clearTimeout(timeout);
|
|
1135
|
+
timeout = setTimeout(function () {
|
|
1136
|
+
callback.apply(void 0, args);
|
|
1137
|
+
}, delay);
|
|
1138
|
+
};
|
|
1139
|
+
};
|
|
1140
|
+
exports.debounce = debounce;
|
|
1141
|
+
var uniqueId = function uniqueId() {
|
|
1142
|
+
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
|
|
1143
|
+
};
|
|
1144
|
+
exports.uniqueId = uniqueId;
|
|
1145
|
+
|
|
1146
|
+
/***/ }),
|
|
1147
|
+
|
|
1148
|
+
/***/ "./src/GlobalStoreAbstract.ts":
|
|
1149
|
+
/*!************************************!*\
|
|
1150
|
+
!*** ./src/GlobalStoreAbstract.ts ***!
|
|
1151
|
+
\************************************/
|
|
1152
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1153
|
+
|
|
1154
|
+
"use strict";
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1158
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
1159
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1160
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
1161
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1162
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1163
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
1164
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
1165
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
1166
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
1167
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1168
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1169
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
1170
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
1171
|
+
value: true
|
|
1172
|
+
}));
|
|
1173
|
+
exports.GlobalStoreAbstract = void 0;
|
|
1174
|
+
var GlobalStore_1 = __webpack_require__(/*! ./GlobalStore */ "./src/GlobalStore.ts");
|
|
1175
|
+
/**
|
|
1176
|
+
* @description
|
|
1177
|
+
* Use this class to extends the capabilities of the GlobalStore.
|
|
1178
|
+
* by implementing the abstract methods onInitialize and onChange.
|
|
1179
|
+
* You can use this class to create a store with async storage.
|
|
1180
|
+
*/
|
|
1181
|
+
var GlobalStoreAbstract = /*#__PURE__*/function (_GlobalStore_1$Global) {
|
|
1182
|
+
_inherits(GlobalStoreAbstract, _GlobalStore_1$Global);
|
|
1183
|
+
var _super = _createSuper(GlobalStoreAbstract);
|
|
1184
|
+
function GlobalStoreAbstract(state) {
|
|
1185
|
+
var _this;
|
|
1186
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1187
|
+
var actionsConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1188
|
+
_classCallCheck(this, GlobalStoreAbstract);
|
|
1189
|
+
_this = _super.call(this, state, config, actionsConfig);
|
|
1190
|
+
_this.onInit = function (parameters) {
|
|
1191
|
+
_this.onInitialize(parameters);
|
|
1192
|
+
};
|
|
1193
|
+
_this.onStateChanged = function (parameters) {
|
|
1194
|
+
_this.onChange(parameters);
|
|
1195
|
+
};
|
|
1196
|
+
return _this;
|
|
1197
|
+
}
|
|
1198
|
+
return _createClass(GlobalStoreAbstract);
|
|
1199
|
+
}(GlobalStore_1.GlobalStore);
|
|
1200
|
+
exports.GlobalStoreAbstract = GlobalStoreAbstract;
|
|
1201
|
+
|
|
1202
|
+
/***/ }),
|
|
1203
|
+
|
|
1204
|
+
/***/ "./src/index.ts":
|
|
1205
|
+
/*!**********************!*\
|
|
1206
|
+
!*** ./src/index.ts ***!
|
|
1207
|
+
\**********************/
|
|
1208
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1209
|
+
|
|
1210
|
+
"use strict";
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
1214
|
+
if (k2 === undefined) k2 = k;
|
|
1215
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1216
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1217
|
+
desc = {
|
|
1218
|
+
enumerable: true,
|
|
1219
|
+
get: function get() {
|
|
1220
|
+
return m[k];
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
Object.defineProperty(o, k2, desc);
|
|
1225
|
+
} : function (o, m, k, k2) {
|
|
1226
|
+
if (k2 === undefined) k2 = k;
|
|
1227
|
+
o[k2] = m[k];
|
|
1228
|
+
});
|
|
1229
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
1230
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1231
|
+
};
|
|
1232
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
1233
|
+
value: true
|
|
1234
|
+
}));
|
|
1235
|
+
__exportStar(__webpack_require__(/*! json-storage-formatter */ "./node_modules/json-storage-formatter/lib/bundle.js"), exports);
|
|
1236
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore.types */ "./src/GlobalStore.types.ts"), exports);
|
|
1237
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore */ "./src/GlobalStore.ts"), exports);
|
|
1238
|
+
__exportStar(__webpack_require__(/*! ./GlobalStoreAbstract */ "./src/GlobalStoreAbstract.ts"), exports);
|
|
1239
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore.functionHooks */ "./src/GlobalStore.functionHooks.ts"), exports);
|
|
1240
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore.utils */ "./src/GlobalStore.utils.ts"), exports);
|
|
1241
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore.combiners */ "./src/GlobalStore.combiners.ts"), exports);
|
|
1242
|
+
__exportStar(__webpack_require__(/*! ./GlobalStore.context */ "./src/GlobalStore.context.ts"), exports);
|
|
1243
|
+
|
|
1244
|
+
/***/ }),
|
|
1245
|
+
|
|
1246
|
+
/***/ "./node_modules/json-storage-formatter/lib/bundle.js":
|
|
1247
|
+
/*!***********************************************************!*\
|
|
1248
|
+
!*** ./node_modules/json-storage-formatter/lib/bundle.js ***!
|
|
1249
|
+
\***********************************************************/
|
|
1250
|
+
/***/ (function(module) {
|
|
1251
|
+
|
|
1252
|
+
!function(r,t){ true?module.exports=t():0}(this,(()=>(()=>{"use strict";var r={991:(r,t,e)=>{var n=Object.create?function(r,t,e,n){void 0===n&&(n=e);var o=Object.getOwnPropertyDescriptor(t,e);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(r,n,o)}:function(r,t,e,n){void 0===n&&(n=e),r[n]=t[e]};Object.defineProperty(t,"__esModule",{value:!0}),function(r,t){for(var e in r)"default"===e||Object.prototype.hasOwnProperty.call(t,e)||n(t,r,e)}(e(729),t)},729:(r,t)=>{function e(r){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},e(r)}function n(r,t,n){return(t=function(r){var t=function(r,t){if("object"!==e(r)||null===r)return r;var n=r[Symbol.toPrimitive];if(void 0!==n){var o=n.call(r,"string");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}(r);return"symbol"===e(t)?t:String(t)}(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function o(r,t){if(r){if("string"==typeof r)return i(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(r,t):void 0}}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}Object.defineProperty(t,"__esModule",{value:!0}),t.formatToStore=t.formatFromStore=t.isPrimitive=t.isFunction=t.isRegex=t.isDate=t.isString=t.isBoolean=t.isNumber=t.isNil=t.clone=void 0,t.clone=function(r){var e,u=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,t.isPrimitive)(r)||(0,t.isDate)(r))return r;if(Array.isArray(r))return u?function(r){if(Array.isArray(r))return i(r)}(e=r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():r.map((function(r){return(0,t.clone)(r)}));if(r instanceof Map){var a=Array.from(r.entries());return u?new Map(a):new Map(a.map((function(r){return(0,t.clone)(r)})))}if(r instanceof Set){var f=Array.from(r.values());return u?new Set(f):new Set(f.map((function(r){return(0,t.clone)(r)})))}return r instanceof RegExp?new RegExp(r.toString()):(0,t.isFunction)(r)?u?r:Object.create(r):u?Object.assign({},r):r instanceof Error?new Error(r.message):Object.keys(r).reduce((function(e,o){var i=r[o];return Object.assign(Object.assign({},e),n({},o,(0,t.clone)(i)))}),{})},t.isNil=function(r){return null==r},t.isNumber=function(r){return"number"==typeof r},t.isBoolean=function(r){return"boolean"==typeof r},t.isString=function(r){return"string"==typeof r},t.isDate=function(r){return r instanceof Date},t.isRegex=function(r){return r instanceof RegExp},t.isFunction=function(r){return"function"==typeof r||r instanceof Function},t.isPrimitive=function(r){return(0,t.isNil)(r)||(0,t.isNumber)(r)||(0,t.isBoolean)(r)||(0,t.isString)(r)||"symbol"===e(r)},t.formatFromStore=function(r){return function(r){var e,i;if((0,t.isPrimitive)(r))return r;if("date"===(null==r?void 0:r.$t))return new Date(r.$v);if("map"===(null==r?void 0:r.$t)){var u=(null!==(e=r.$v)&&void 0!==e?e:[]).map((function(r){var e,n,i=(n=2,function(r){if(Array.isArray(r))return r}(e=r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,u,a=[],f=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;f=!1}else for(;!(f=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);f=!0);}catch(r){c=!0,o=r}finally{try{if(!f&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,n)||o(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),u=i[0],a=i[1];return[u,(0,t.formatFromStore)(a)]}));return new Map(u)}if("set"===(null==r?void 0:r.$t)){var a=null!==(i=r.$v)&&void 0!==i?i:[].map((function(r){return(0,t.formatFromStore)(r)}));return new Set(a)}return"regex"===(null==r?void 0:r.$t)?new RegExp(r.$v):"error"===(null==r?void 0:r.$t)?new Error(r.$v):Array.isArray(r)?r.map((function(r){return(0,t.formatFromStore)(r)})):"function"===(null==r?void 0:r.$t)?Function("(".concat(r.$v,")(...arguments)")):Object.keys(r).reduce((function(e,o){var i=r[o];return Object.assign(Object.assign({},e),n({},o,(0,t.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?JSON.parse(r):(0,t.clone)(r))},t.formatToStore=function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,u=o.validator,a=o.excludeTypes,f=o.excludeKeys,c=new Set(null!=a?a:[]),s=new Set(null!=f?f:[]),l=c.size||s.size,m=null!=u?u:function(r){var t=r.key,n=r.value;if(!l)return!0;var o=s.has(t),i=c.has(e(n));return!o&&!i},v=function r(e){if((0,t.isPrimitive)(e))return e;if(Array.isArray(e))return e.map((function(t){return r(t)}));if(e instanceof Map)return{$t:"map",$v:Array.from(e.entries()).map((function(t){return r(t)}))};if(e instanceof Set)return{$t:"set",$v:Array.from(e.values()).map((function(t){return r(t)}))};if((0,t.isDate)(e))return{$t:"date",$v:e.toISOString()};if((0,t.isRegex)(e))return{$t:"regex",$v:e.toString()};if((0,t.isFunction)(e)){var o;try{o={$t:"function",$v:e.toString()}}catch(r){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return e instanceof Error?{$t:"error",$v:e.message}:Object.keys(e).reduce((function(t,o){var i=e[o],u=r(i);return m({obj:e,key:o,value:u})?Object.assign(Object.assign({},t),n({},o,r(i))):t}),{})}((0,t.clone)(r));return i?JSON.stringify(v):v}}},t={};return function e(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return r[n](i,i.exports,e),i.exports}(991)})()));
|
|
1253
|
+
|
|
1254
|
+
/***/ }),
|
|
1255
|
+
|
|
1256
|
+
/***/ "react":
|
|
1257
|
+
/*!************************!*\
|
|
1258
|
+
!*** external "react" ***!
|
|
1259
|
+
\************************/
|
|
1260
|
+
/***/ ((module) => {
|
|
1261
|
+
|
|
1262
|
+
"use strict";
|
|
1263
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_react__;
|
|
1264
|
+
|
|
1265
|
+
/***/ })
|
|
1266
|
+
|
|
1267
|
+
/******/ });
|
|
1268
|
+
/************************************************************************/
|
|
1269
|
+
/******/ // The module cache
|
|
1270
|
+
/******/ var __webpack_module_cache__ = {};
|
|
1271
|
+
/******/
|
|
1272
|
+
/******/ // The require function
|
|
1273
|
+
/******/ function __webpack_require__(moduleId) {
|
|
1274
|
+
/******/ // Check if module is in cache
|
|
1275
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
1276
|
+
/******/ if (cachedModule !== undefined) {
|
|
1277
|
+
/******/ return cachedModule.exports;
|
|
1278
|
+
/******/ }
|
|
1279
|
+
/******/ // Create a new module (and put it into the cache)
|
|
1280
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
1281
|
+
/******/ // no module.id needed
|
|
1282
|
+
/******/ // no module.loaded needed
|
|
1283
|
+
/******/ exports: {}
|
|
1284
|
+
/******/ };
|
|
1285
|
+
/******/
|
|
1286
|
+
/******/ // Execute the module function
|
|
1287
|
+
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
1288
|
+
/******/
|
|
1289
|
+
/******/ // Return the exports of the module
|
|
1290
|
+
/******/ return module.exports;
|
|
1291
|
+
/******/ }
|
|
1292
|
+
/******/
|
|
1293
|
+
/************************************************************************/
|
|
1294
|
+
/******/
|
|
1295
|
+
/******/ // startup
|
|
1296
|
+
/******/ // Load entry module and return exports
|
|
1297
|
+
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
1298
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
|
|
1299
|
+
/******/
|
|
1300
|
+
/******/ return __webpack_exports__;
|
|
1301
|
+
/******/ })()
|
|
1302
|
+
;
|
|
1303
|
+
});
|
|
1304
|
+
//# sourceMappingURL=bundle.js.map
|