react-hooks-global-states 4.0.7 → 5.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/lib/bundle.js +1 -1
- package/lib/src/GlobalStore.combiners.d.ts +10 -24
- package/lib/src/GlobalStore.context.d.ts +33 -170
- package/lib/src/GlobalStore.d.ts +62 -80
- package/lib/src/GlobalStore.functionHooks.d.ts +32 -120
- package/lib/src/GlobalStore.types.d.ts +62 -85
- package/lib/src/GlobalStore.utils.d.ts +8 -12
- package/lib/src/GlobalStoreAbstract.d.ts +2 -3
- package/package.json +3 -3
package/lib/bundle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see bundle.js.LICENSE.txt */
|
|
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,d=new Set,p=(0,i.debounce)((function(){var e=t.selector(Array.from(s.values()));(null==v?void 0:v(f,e))||(f=e,d.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),y=l.map((function(t,e){return t((function(t){t((function(t){s.set(e,t),p()}))}))})),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 p=(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 d.add(p),function(){d.delete(p)}};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(),d.delete(t)}))}},function(){y.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";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=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e};Object.defineProperty(e,"__esModule",{value:!0}),e.createContext=void 0;var i=r(608),a=r(774),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&n(e,t,r);return o(e,t),e}(r(156));e.createContext=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var o=new Map,c=u.default.createContext(null),l=function(){return u.default.useContext(c)};return l.createSelectorHook=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=(0,i.uniqueId)();return function(){var t=l(),r=o.get(t);return r.has(n)||r.set(n,t.createSelectorHook.apply(t,e)),r.get(n).apply(void 0,arguments)}},[l,function(e){var n=e.children,i=e.value,l=e.ref,s=(0,u.useMemo)((function(){var e="function"==typeof r[0],n=function(){var t;if(e){var n=r[0];return{config:r[1],actionsConfig:n()}}var o=r[0];return{config:o,actionsConfig:null!==(t=r[1])&&void 0!==t?t:null==o?void 0:o.actions}}(),o=n.config,u=n.actionsConfig,c=new a.GlobalStore(i?"function"==typeof i?i(t):i:t,o,u);return{store:c,hook:c.getHook()}}),[]),f=s.store,v=s.hook;return(0,u.useImperativeHandle)(l,(function(){return l?f.getConfigCallbackParam():{}}),[f]),o.has(v)||o.set(v,new Map),(0,u.useEffect)((function(){return function(){var t,e,r,n;o.delete(v),null===(e=null===(t=f.config)||void 0===t?void 0:t.onUnMount)||void 0===e||e.call(t),null===(n=(r=f).__onUnMountContext)||void 0===n||n.call(r,f,v)}}),[]),u.default.createElement(c.Provider,{value:v},n)}]}},853:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createDerivateEmitter=e.createDerivate=e.createCustomGlobalStateWithDecoupledFuncs=e.createCustomGlobalState=e.createGlobalState=void 0;var n=r(774);e.createGlobalState=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=arguments[o];var i="function"==typeof r[0],a=function(){var t;if(i){var e=r[0];return{config:r[1],actionsConfig:e()}}var n=r[0];return{config:n,actionsConfig:null!==(t=r[1])&&void 0!==t?t:null==n?void 0:n.actions}}(),u=a.config,c=a.actionsConfig;return new n.GlobalStore(t,u,c).getHook()},e.createCustomGlobalState=function(t){var r=t.onInitialize,n=t.onChange;return function(t,o){var i=null!=o?o:{},a=(i.actions,i.config),u=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}(i,["actions","config"]);return(0,e.createGlobalState)(t,Object.assign({onInit:function(t){var e;r(t,a),null===(e=null==u?void 0:u.onInit)||void 0===e||e.call(u,t)},onStateChanged:function(t){var e;n(t,a),null===(e=null==u?void 0:u.onStateChanged)||void 0===e||e.call(u,t)}},u))}},e.createCustomGlobalStateWithDecoupledFuncs=e.createCustomGlobalState,e.createDerivate=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.createSelectorHook(e,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){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 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}}(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 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}function a(){a=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",l=i.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 p?e:p,a=Object.create(i.prototype),u=new C(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 d={};function p(){}function y(){}function h(){}var b={};s(b,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==e&&r.call(m,u)&&(b=m);var S=h.prototype=p.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===d)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===d)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")),d;var o=v(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;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,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}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 C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function _(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:P}}function P(){return{value:void 0,done:!0}}return y.prototype=h,o(S,"constructor",{value:h,configurable:!0}),o(h,"constructor",{value:y,configurable:!0}),y.displayName=s(h,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"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.prototype={constructor:C,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,d):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),d},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),d}},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:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function u(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,c(n.key),n)}}function c(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 l=r(608),s=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 f=function(){function t(r,n){var i=this,u=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=u,this.subscribers=new Map,this.actions=null,this.config={metadata:null},this.initialize=function(){return t=i,e=void 0,r=void 0,n=a().mark((function t(){var e,r,n;return a().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(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function u(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}c((n=n.apply(t,e||[])).next())}));var t,e,r,n},this.executeSetStateForSubscriber=function(t,e){var r,n,o=e.forceUpdate,i=e.newRootState,a=e.currentRootState,u=e.identifier,c=t.selector,l=t.callback,s=t.currentState,f=t.config;if(o||!(null!==(r=null==f?void 0:f.isEqualRoot)&&void 0!==r?r:function(t,e){return Object.is(t,e)})(a,i)){var v=c?c(i):i;!o&&(null!==(n=null==f?void 0:f.isEqual)&&void 0!==n?n:function(t,e){return Object.is(t,e)})(s,v)||(t.currentState=v,l({state:v,identifier:u}))}},this.setState=function(t){var e=t.state,r=t.forceUpdate,n=t.identifier,o=i.stateWrapper.state;i.stateWrapper={state:e};for(var a=Array.from(i.subscribers.values()),u={forceUpdate:r,newRootState:e,currentRootState:o,identifier:n},c=0;c<a.length;c++){var l=a[c];i.executeSetStateForSubscriber(l,u)}},this.setMetadata=function(t){var e,r,n="function"==typeof t?t(null!==(e=i.config.metadata)&&void 0!==e?e:null):t;i.config=Object.assign(Object.assign({},null!==(r=i.config)&&void 0!==r?r:{}),{metadata:n})},this.getMetadata=function(){var t;return null!==(t=i.config.metadata)&&void 0!==t?t:null},this.createChangesSubscriber=function(t){var e=t.callback,r=t.selector,n=t.config,o=r?r(i.stateWrapper.state):i.stateWrapper.state,a={state:o};return(null==n?void 0:n.skipFirst)||e(o),{stateWrapper:a,subscriptionCallback:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return i.stateWrapper.state;var r=[];return t((function(t,e,n){var o="function"==typeof e,a=o?t:null,u=o?e:t,c=o?n:e,s=i.createChangesSubscriber({selector:a,callback:u,config:c}),f=s.subscriptionCallback,v=s.stateWrapper,d=(0,l.uniqueId)();i.updateSubscriptionArgs(d,{subscriptionId:d,selector:a,config:c,currentState:v.state,callback:f}),r.push(d)})),r.length||(0,e.throwNoSubscribersWereAdded)(),function(){for(var t=0;t<r.length;t++){var e=r[t];i.subscribers.delete(e)}}},this.getConfigCallbackParam=function(){var t=i.setMetadata,e=i.getMetadata,r=i.getState,n=i.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:i.setStateWrapper,actions:n}},this.lastSubscriptionId=null,this.updateSubscriptionArgs=function(t,e){return!!t&&(i.subscribers.has(t)?(Object.assign(i.subscribers.get(t),e),!1):(i.executeOnSubscribed(),i.subscribers.set(t,e),i.lastSubscriptionId=t,e))},this.executeOnSubscribed=function(){var t=i.onSubscribed,e=i.config.onSubscribed;if(t||e){var r=i.getConfigCallbackParam();null==t||t(r),null==e||e(r)}},this.getHook=function(){var t=function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=(0,s.useRef)(null),u=function(){var e=null===a.current?i.stateWrapper.state:null;return t?{state:t(i.stateWrapper.state),initialRootState:e}:{state:i.stateWrapper.state,initialRootState:e}},c=o((0,s.useState)(u),2),f=c[0],v=c[1];(0,s.useEffect)((function(){null===a.current&&(a.current=(0,l.uniqueId)());var e=a.current,r=i.updateSubscriptionArgs(e,{subscriptionId:e,currentState:f.state,selector:t,config:n,callback:v});return r&&i.executeSetStateForSubscriber(r,{forceUpdate:!1,newRootState:i.stateWrapper.state,currentRootState:f.initialRootState,identifier:null}),function(){i.subscribers.delete(e)}}),[]);var d=a.current,p=i.subscribers.get(d),y=(null!==(e=null==p?void 0:p.config)&&void 0!==e?e:{dependencies:n.dependencies}).dependencies;return i.updateSubscriptionArgs(d,{subscriptionId:d,currentState:f.state,selector:t,config:n,callback:v}),[function(){if(!t||!d)return f.state;var e=n.dependencies;if(y===e)return f.state;if((null==y?void 0:y.length)===(null==e?void 0:e.length)&&(0,l.shallowCompare)(y,e))return f.state;var r=u().state;return i.updateSubscriptionArgs(d,{currentState:r}),f.state=r,r}(),i.getStateOrchestrator(),null!==(r=i.config.metadata)&&void 0!==r?r:null]};return t.stateControls=i.stateControls,t.createSelectorHook=i.createSelectorHook,t},this.createSelectorHook=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.isEqualRoot,a=r.isEqual,u=r.name,c=o(i.stateControls(),3),s=c[0],f=c[1],v=c[2],d=s(),p=(null!=e?e:function(t){return t})(s()),y=function(){var t;if(u)return u;var e=null===(t=v())||void 0===t?void 0:t.name;return e?"selected-from-".concat(e,"_").concat((0,l.uniqueId)()):null}(),h=new t(p,y?{metadata:{name:y}}:null),b=o(h.stateControls(),2),g=b[0],m=b[1];s((function(t){t((function(t){if(!(null!=n?n:Object.is)(d,t)){d=t;var r=e(t);(null!=a?a:Object.is)(p,r)||(p=r,m(r))}}),{skipFirst:!0})}));var S=h.getHook(),w=function(t){return[o(S(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),1)[0],f,v]};return w.stateControls=function(){return[g,f,v]},w.createSelectorHook=i.createSelectorHook.bind(w),w},this.stateControls=function(){var t=i.getStateOrchestrator(),e=i.getMetadata;return[i.getState,t,e]},this.getStateOrchestrator=function(){return Object.assign(i.actions?i.actions:i.setStateWrapper)},this.hasStateCallbacks=function(){var t=i.computePreventStateChange,e=i.onStateChanged,r=i.config,n=r.computePreventStateChange,o=r.onStateChanged;return!!(t||n||e||o)},this.setStateWrapper=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.forceUpdate,n=e.identifier,o="function"==typeof t,a=i.stateWrapper.state,u=o?t(a):t;if(r||!Object.is(i.stateWrapper.state,u)){var c=i.setMetadata,l=i.getMetadata,s=i.getState,f=i.actions,v={setMetadata:c,getMetadata:l,setState:i.setState,getState:s,actions:f,previousState:a,state:u,identifier:n},d=i.computePreventStateChange,p=i.config.computePreventStateChange;if((d||p)&&((null==d?void 0:d(v))||(null==p?void 0:p(v))))return;i.setState({forceUpdate:r,identifier:n,state:u});var y=i.onStateChanged,h=i.config.onStateChanged;(y||h)&&(null==y||y(v),null==h||h(v))}},this.getStoreActionsMap=function(){if(!i.actionsConfig)return null;var t=i.actionsConfig,e=i.setMetadata,r=i.setStateWrapper,n=i.getState,o=i.getMetadata,a=Object.keys(t).reduce((function(i,u){var l,s,f;return Object.assign(i,(l={},f=function(){for(var i=t[u],c=arguments.length,l=new Array(c),s=0;s<c;s++)l[s]=arguments[s];var f=i.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"))}(u),f.call(a,{setState:r,getState:n,setMetadata:e,getMetadata:o,actions:a})},(s=c(s=u))in l?Object.defineProperty(l,s,{value:f,enumerable:!0,configurable:!0,writable:!0}):l[s]=f,l)),i}),{});return a},this.stateWrapper={state:r},this.config=Object.assign({metadata:null},null!=n?n:{}),(null===globalThis||void 0===globalThis?void 0:globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG)&&globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG(this,r,n,u),this.constructor!==t||this.initialize()}var r,n;return r=t,(n=[{key:"state",get:function(){return this.stateWrapper.state}}])&&u(r.prototype,n),Object.defineProperty(r,"prototype",{writable:!1}),t}();e.GlobalStore=f},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,l=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,l.isNil)(t)||(0,l.isNil)(e)||(0,l.isPrimitive)(t)&&(0,l.isPrimitive)(e)||(0,l.isDate)(t)&&(0,l.isDate)(e)||"function"===r&&"function"===i)return t===e;if(Array.isArray(t)){var a=t,c=e;if(a.length!==c.length)return!1;for(var s=0;s<a.length;s++)if(a[s]!==c[s])return!1}if(t instanceof Map){var f=t,v=e;if(f.size!==v.size)return!1;var d,p=o(f);try{for(p.s();!(d=p.n()).done;){var y=n(d.value,2),h=y[0];if(y[1]!==v.get(h))return!1}}catch(t){p.e(t)}finally{p.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=(c=0,function(){return c===Number.MAX_SAFE_INTEGER&&(c=0),Date.now().toString(36)+(c++).toString(36)})},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,e,r){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(n=u.call(this,t,e,r)).onInit=function(t){n.onInitialize(t)},n.onStateChanged=function(t){n.onChange(t)},n}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},d=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(d):d}}},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}));
|
|
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.combineRetrieverEmitterAsynchronously=void 0;var i=r(608),a=r(156);e.combineRetrieverEmitterAsynchronously=function(t){for(var e,r,n,o=arguments.length,a=new Array(o>1?o-1:0),u=1;u<o;u++)a[u-1]=arguments[u];var c=a,l=new Map(c.map((function(t,e){return[e,t()]}))),s=t.selector(Array.from(l.values())),f=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,v=new Set,d=(0,i.debounce)((function(){var e=t.selector(Array.from(l.values()));(null==f?void 0:f(s,e))||(s=e,v.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),p=c.map((function(t,e){return t((function(t){l.set(e,t),d()}))})),y=function(t,e,r){var n,o,a="function"==typeof e,u=a?t:null,c=a?e:t,l=a?r:e,f=Object.assign({delay:0,isEqual:i.shallowCompare},null!=l?l:{}),d=null!==(n=null==u?void 0:u(s))&&void 0!==n?n:s;f.skipFirst||c(d);var p=(0,i.debounce)((function(){var t,e,r=null!==(t=null==u?void 0:u(s))&&void 0!==t?t:s;(null===(e=f.isEqual)||void 0===e?void 0:e.call(f,d,r))||(d=r,c(r))}),null!==(o=f.delay)&&void 0!==o?o:0);return v.add(p),function(){v.delete(p)}};return[y,function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e[0]?y.apply(void 0,e):s},function(){p.forEach((function(t){return t()}))}]},e.combineRetrieverAsynchronously=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.combineRetrieverEmitterAsynchronously.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]}},113:(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=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e};Object.defineProperty(e,"__esModule",{value:!0}),e.createContext=void 0;var i=r(608),a=r(774),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&n(e,t,r);return o(e,t),e}(r(156)),c=r(684);e.createContext=function(t,e){var r=new Map,n=u.default.createContext(i.uniqueSymbol),o=function(){var t=u.default.useContext(n);if(t===i.uniqueSymbol)throw new Error("context hooks need to be used inside a provider");return t};return o.createSelectorHook=function(t,e){var n=(0,i.uniqueId)("cs:");return function(){var i,a,u=o(),l=(i=u,null!==(a=r.get(i))&&void 0!==a?a:r.set(i,new Map).get(i));l.has(n)||l.set(n,u.createSelectorHook(t,e));var s=l.get(n);if((0,c.isNil)(s))throw new Error("useSelectedHook is nil");return s.apply(void 0,arguments)}},[o,function(o){var i=o.children,l=o.value,s=o.ref,f=(0,u.useMemo)((function(){var r=void 0===l?t():(0,c.isFunction)(l)?l(t()):l,n=new a.GlobalStore(r,e);return{store:n,hook:n.getHook()}}),[]),v=f.store,d=f.hook;return r.has(d)||r.set(d,new Map),(0,u.useEffect)((function(){return function(){var t,e,n,o;r.delete(d),null===(e=null===(t=v.callbacks)||void 0===t?void 0:t.onUnMount)||void 0===e||e.call(t),null===(o=(n=v).__onUnMountContext)||void 0===o||o.call(n,v,d)}}),[]),(0,u.useImperativeHandle)(s,(function(){return s?v.getConfigCallbackParam():{}}),[v,s]),u.default.createElement(n.Provider,{value:d},i)}]}},853:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createCustomGlobalState=e.createGlobalState=void 0;var n=r(774);e.createGlobalState=function(t,e){return new n.GlobalStore(t,e).getHook()},e.createCustomGlobalState=function(t){var r=t.onInitialize,n=t.onChange;return function(t,o){return(0,e.createGlobalState)(t,{callbacks:Object.assign(Object.assign({},null==o?void 0:o.callbacks),{onInit:function(t){var e,n;null==r||r(t,null==o?void 0:o.config),null===(n=null===(e=null==o?void 0:o.callbacks)||void 0===e?void 0:e.onInit)||void 0===n||n.call(e,t)},onStateChanged:function(t){var e,r;null==n||n(t,null==o?void 0:o.config),null===(r=null===(e=null==o?void 0:o.callbacks)||void 0===e?void 0:e.onStateChanged)||void 0===r||r.call(e,t)}})})}}},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){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 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(){u=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",l=i.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 p?e:p,a=Object.create(i.prototype),u=new C(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 d={};function p(){}function y(){}function b(){}var h={};s(h,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(k([])));g&&g!==e&&r.call(g,a)&&(h=g);var S=b.prototype=p.prototype=Object.create(h);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=E(a,r);if(u){if(u===d)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===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function E(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,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var o=v(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;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,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function x(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 A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function k(t){if(t){var e=t[a];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 y.prototype=b,o(S,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=s(b,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,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,a,(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=k,C.prototype={constructor:C,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(A),!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,d):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),d},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),A(r),d}},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;A(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function c(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,l(n.key),n)}}function l(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=void 0;var s=r(608),f=r(156),v=r(684),d=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Map,this.initialize=function(){return t=r,e=void 0,n=void 0,o=u().mark((function t(){var e,r,n,o,i,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Object.keys(null!==(e=this.actionsConfig)&&void 0!==e?e:{}).length>0&&(this.actions=this.getStoreActionsMap()),n=this.onInit,o=null!==(r=this.callbacks)&&void 0!==r?r:{},i=o.onInit,n||i){t.next=6;break}return t.abrupt("return");case 6:a=this.getConfigCallbackParam(),null==n||n(a),(0,v.isNil)(i)||null==i||i(a);case 9:case"end":return t.stop()}}),t,this)})),new(n||(n=Promise))((function(r,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?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}c((o=o.apply(t,e||[])).next())}));var t,e,n,o},this.executeSetStateForSubscriber=function(t,e){var n,o,i=t.selector,a=t.callback,u=t.currentState,c=t.config;if(!e.forceUpdate&&(null!==(n=null==c?void 0:c.isEqualRoot)&&void 0!==n?n:function(t,e){return t===e})(e.currentRootState,e.newRootState))return{didUpdate:!1};var l=i?i(e.newRootState):e.newRootState;return!e.forceUpdate&&(null!==(o=null==c?void 0:c.isEqual)&&void 0!==o?o:function(t,e){return t===e})(u,l)?{didUpdate:!1}:(r.partialUpdateSubscription(t.subscriptionId,{currentState:l}),a({state:l},{identifier:e.identifier}),{didUpdate:!0})},this.setState=function(t,e){var n=t.state,o=e.forceUpdate,a=e.identifier,u=r.stateWrapper.state;if(o||u!==n){r.stateWrapper={state:n};var c,l={forceUpdate:o,newRootState:n,currentRootState:u,identifier:a},s=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))){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}}}}(r.subscribers.values());try{for(s.s();!(c=s.n()).done;){var f=c.value;r.executeSetStateForSubscriber(f,l)}}catch(t){s.e(t)}finally{s.f()}}},this.setMetadata=function(t){var e=(0,v.isFunction)(t)?t(r.metadata):t;r.metadata=e},this.getMetadata=function(){return r.metadata},this.getState=function(t,e,n){var o;if(!t)return r.stateWrapper.state;var i=(0,v.isFunction)(e),a=i?t:void 0,u=i?e:t,c=null!==(o=i?n:e)&&void 0!==o?o:void 0,l=a?a(r.stateWrapper.state):r.stateWrapper.state;(null==c?void 0:c.skipFirst)||u(l);var f=(0,s.uniqueId)("gs:");return r.setOrUpdateSubscription({subscriptionId:f,selector:a,config:c,currentState:l,callback:function(t){var e=t.state;return u(e)},isSetStateCallback:!1}),function(){r.subscribers.delete(f)}},this.getConfigCallbackParam=function(){var t=r.setMetadata,e=r.getMetadata,n=r.getState,o=r.actions;return{setMetadata:t,getMetadata:e,getState:n,setState:r.setStateWrapper,actions:o}},this.lastSubscriptionId=null,this.setOrUpdateSubscription=function(t){var e=t.subscriptionId;if(!e)return{isNewSubscription:!1};var n=r.subscribers.get(e);return(0,s.isRecord)(n)?(Object.assign(n,t),{isNewSubscription:!1}):(r.executeOnSubscribed(),r.subscribers.set(e,t),r.lastSubscriptionId=e,{isNewSubscription:!0})},this.partialUpdateSubscription=function(t,e){var n=r.subscribers.get(t);(0,s.isRecord)(n)&&Object.assign(n,e)},this.executeOnSubscribed=function(){var t,e=r.onSubscribed,n=null===(t=r.callbacks)||void 0===t?void 0:t.onSubscribed;if(e||n){var o=r.getConfigCallbackParam();null==e||e(o),null==n||n(o)}},this.getHook=function(){var t=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=(0,s.useConstantValueRef)((function(){return{subscriptionId:null,tempInitialRootState:r.stateWrapper.state}})),a=function(){return t?{state:t(r.stateWrapper.state)}:r.stateWrapper},u=o((0,f.useState)(a),2),c=u[0],l=u[1];(0,f.useEffect)((function(){if(!(0,v.isNil)(i.current)){(0,v.isNil)(i.current.subscriptionId)&&(i.current.subscriptionId=(0,s.uniqueId)("ss:"));var e=i.current.subscriptionId,o={subscriptionId:e,currentState:c.state,selector:t,config:n,callback:l,isSetStateCallback:!0};return r.setOrUpdateSubscription(o).isNewSubscription&&(r.executeSetStateForSubscriber(o,{forceUpdate:!1,newRootState:r.stateWrapper.state,currentRootState:i.current.tempInitialRootState,identifier:"on mount state update"}),i.current.tempInitialRootState=s.uniqueSymbol),function(){r.subscribers.delete(e)}}}),[]);var d=(0,v.isString)(i.current)?i.current:"",p=r.subscribers.get(d),y=(null!==(e=null==p?void 0:p.config)&&void 0!==e?e:{dependencies:n.dependencies}).dependencies;return r.partialUpdateSubscription(d,{currentState:c.state,selector:t,config:n,callback:l}),[r.computeSelectedState({selector:t,subscriptionId:d,config:n,currentDependencies:y,computeChildState:a,stateWrapperRef:c}),r.getStateOrchestrator(),r.metadata]};return t.stateControls=r.stateControls,t.createSelectorHook=r.createSelectorHook,t.createObservable=r.createObservable,t},this.computeSelectedState=function(t){var e=t.selector,n=t.subscriptionId,o=t.config,i=t.currentDependencies,a=t.computeChildState,u=t.stateWrapperRef;if(!e||!n)return u.state;var c=o.dependencies;if(i===c)return u.state;if((null==i?void 0:i.length)===(null==c?void 0:c.length)&&(0,s.shallowCompare)(i,c))return u.state;var l=a().state;return r.partialUpdateSubscription(n,{currentState:l}),u.state=l,l},this.createSelectorHook=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=n.isEqualRoot,a=n.isEqual,u=n.name,c=o(r.stateControls(),3),l=c[0],f=c[1],d=c[2],p=l(),y=(null!=e?e:function(t){return t})(p),b=new t(y,{name:null!=u?u:(0,s.uniqueId)("sh:")}),h=o(b.stateControls(),2),m=h[0],g=h[1];l((function(t){if(!(null!=i?i:Object.is)(p,t)){p=t;var r=e(t);(null!=a?a:Object.is)(y,r)||(y=r,g(r))}}),{skipFirst:!0});var S=b.getHook(),w=function(t,e){return[o((0,v.isFunction)(t)?S(t,e):S(),1)[0],f,d]};return w.stateControls=function(){return[m,f,d]},w.createSelectorHook=r.createSelectorHook.bind(w),w.createObservable=r.createObservable.bind(w),w},this.stateControls=function(){var t=r.getStateOrchestrator(),e=r.getMetadata;return[r.getState,t,e]},this.getStateOrchestrator=function(){return r.actions?r.actions:r.setStateWrapper},this.setStateWrapper=function(t){var e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o.forceUpdate,a=o.identifier,u=r.stateWrapper.state,c=(0,v.isFunction)(t)?t(u):t;if(i||r.stateWrapper.state!==c){var l=r.setMetadata,s=r.getMetadata,f=r.getState,d=r.actions,p={setMetadata:l,getMetadata:s,setState:r.setState,getState:f,actions:d,previousState:u,state:c,identifier:a},y=r.computePreventStateChange,b=null===(e=r.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((y||b)&&((null==y?void 0:y(p))||(null==b?void 0:b(p))))return;r.setState({state:c},{forceUpdate:i,identifier:a});var h=r.onStateChanged,m=null===(n=r.callbacks)||void 0===n?void 0:n.onStateChanged;(h||m)&&(null==h||h(p),null==m||m(p))}},this.getStoreActionsMap=function(){if(!(0,s.isRecord)(r.actionsConfig))return null;var t=r.actionsConfig,e=r.setMetadata,n=r.setStateWrapper,o=r.getState,i=r.getMetadata,a=Object.keys(t).reduce((function(r,u){var c,f,v;return Object.assign(r,(c={},v=function(){for(var r=t[u],c=arguments.length,l=new Array(c),f=0;f<c;f++)l[f]=arguments[f];var v=r.apply(a,l);return"function"!=typeof v&&(0,s.throwWrongKeyOnActionCollectionConfig)(u),v.call(a,{setState:n,getState:o,setMetadata:e,getMetadata:i,actions:a})},(f=l(f=u))in c?Object.defineProperty(c,f,{value:v,enumerable:!0,configurable:!0,writable:!0}):c[f]=v,c)),r}),{});return a};var a=n.metadata,c=n.callbacks,d=n.actions,p=n.name;this.stateWrapper={state:e},this._name=null!=p?p:(0,s.uniqueId)("gs:"),this.metadata=null!=a?a:{},this.callbacks=null!=c?c:null,this.actionsConfig=null!=d?d:null,(null===globalThis||void 0===globalThis?void 0:globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG)&&globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG(this),this.constructor!==t||this.initialize()}var e,r;return e=t,r=[{key:"createObservable",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.isEqualRoot,n=e.isEqual,i=e.name,a=o(this.stateControls(),1)[0],u=[],c=a(),l=(null!=t?t:function(t){return t})(a());a((function(e){if(!(null!=r?r:Object.is)(c,e)){c=e;var o=t(e);(null!=n?n:Object.is)(l,o)||(l=o,u.forEach((function(t){return t()})))}}),{skipFirst:!0});var f=function(t,e,r){var n;if(!t)return l;var o=(0,v.isFunction)(e),i=o?t:void 0,a=o?e:t,c=null!==(n=o?r:e)&&void 0!==n?n:void 0,s=function(){return a(i?i(l):l)};(null==c?void 0:c.skipFirst)||s();var f=function(){s()};return u.push(f),function(){u.splice(u.indexOf(f),1)}};return f._name=null!=i?i:(0,s.uniqueId)("ob:"),f.createObservable=this.createObservable.bind(f),f.stateControls=function(){return[f]},f}}],r&&c(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=d},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.useConstantValueRef=e.uniqueSymbol=e.isRecord=e.throwWrongKeyOnActionCollectionConfig=e.uniqueId=e.debounce=e.shallowCompare=void 0;var c,l=r(684),s=r(156);e.shallowCompare=function(t,r){if(t===r)return!0;var i=u(t),a=u(r);if(i!==a)return!1;if((0,l.isNil)(t)||(0,l.isNil)(r)||(0,l.isPrimitive)(t)&&(0,l.isPrimitive)(r)||(0,l.isDate)(t)&&(0,l.isDate)(r)||"function"===i&&"function"===a)return t===r;if(Array.isArray(t)){var c=t,s=r;if(c.length!==s.length)return!1;for(var f=0;f<c.length;f++)if(c[f]!==s[f])return!1}if(t instanceof Map){var v=t,d=r;if(v.size!==d.size)return!1;var p,y=o(v);try{for(y.s();!(p=y.n()).done;){var b=n(p.value,2),h=b[0];if(b[1]!==d.get(h))return!1}}catch(t){y.e(t)}finally{y.f()}}if(t instanceof Set){var m=t,g=r;if(m.size!==g.size)return!1;var S,w=o(m);try{for(w.s();!(S=w.n()).done;){var O=S.value;if(!g.has(O))return!1}}catch(t){w.e(t)}finally{w.f()}}if(!(0,e.isRecord)(t)||!(0,e.isRecord)(r))return t===r;var j=Object.keys(t),E=Object.keys(r);if(j.length!==E.length)return!1;for(var x=0,A=j;x<A.length;x++){var C=A[x];if(t[C]!==r[C])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=(c=0,function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return c===Number.MAX_SAFE_INTEGER&&(c=0),t+Date.now().toString(36)+(c++).toString(36)}),e.throwWrongKeyOnActionCollectionConfig=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"))},e.isRecord=function(t){return!(0,l.isNil)(t)&&"object"===u(t)},e.uniqueSymbol=Symbol("unique"),e.useConstantValueRef=function(t){var r=(0,s.useRef)(e.uniqueSymbol);return r.current===e.uniqueSymbol&&(r.current=t()),r}},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(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(t=u.apply(this,arguments)).onInit=function(e){t.onInitialize(e)},t.onStateChanged=function(e){t.onChange(e)},t}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={124:(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(331),e)},331:(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){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e: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={}.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=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){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.jsonParse,a=r.sortKeys;return function(t){var r,i,u;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 c=(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(c)}if("set"===(null==t?void 0:t.$t)){var l=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(l)}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)")):(u=Object.keys(t),a?(0,e.isFunction)(a)?u.sort(a):u.sort((function(t,e){return(null!=t?t:"").localeCompare(e)})):u).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}(i?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=o.sortKeys,s=new Set(null!=u?u:[]),f=new Set(null!=c?c:[]),v=s.size||f.size,d=null!=a?a:function(t){var e=t.key,n=t.value;if(!v)return!0;var o=f.has(e),i=s.has(r(n));return!o&&!i},p=function(t){if((0,e.isPrimitive)(t))return t;var r;if(Array.isArray(t))return t.map((function(t){return p(t)}));if(t instanceof Map)return{$t:"map",$v:Array.from(t.entries()).map((function(t){return p(t)}))};if(t instanceof Set)return{$t:"set",$v:Array.from(t.values()).map((function(t){return p(t)}))};if((0,e.isDate)(t))return{$t:"date",$v:t.toISOString()};if((0,e.isRegex)(t))return{$t:"regex",$v:t.toString()};if((0,e.isFunction)(t)){var o;try{o={$t:"function",$v:t.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return t instanceof Error?{$t:"error",$v:t.message}:(r=Object.keys(t),l?(0,e.isFunction)(l)?r.sort(l):r.sort((function(t,e){return(null!=t?t:"").localeCompare(e)})):r).reduce((function(e,r){var o=t[r],i=p(o);return d({obj:t,key:r,value:i})?Object.assign(Object.assign({},e),n({},r,p(o))):e}),{})},y=p((0,e.clone)(t));return i?JSON.stringify(y):y}}},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}(124)})()},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,41 +1,27 @@
|
|
|
1
|
-
import { StateGetter, UnsubscribeCallback, SelectorCallback, UseHookConfig,
|
|
1
|
+
import { StateGetter, UnsubscribeCallback, SelectorCallback, UseHookConfig, StateHook, BaseMetadata } from './GlobalStore.types';
|
|
2
2
|
/**
|
|
3
|
-
* @deprecated will be removed in the next major version, use combineAsyncGettersEmitter instead
|
|
4
3
|
* @description
|
|
5
4
|
* This function allows you to create a derivate state by merging the state of multiple hooks.
|
|
6
5
|
* The update of the derivate state is debounced to avoid unnecessary re-renders.
|
|
7
6
|
* By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
|
|
8
7
|
* @returns a tuple with the following elements: [subscribe, getState, dispose]
|
|
9
8
|
*/
|
|
10
|
-
export declare const combineAsyncGettersEmitter: <TDerivate, TArguments extends StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends () => infer TResult ? Exclude<TResult, UnsubscribeCallback> : never; }>(parameters: {
|
|
11
|
-
selector: SelectorCallback<TResults, TDerivate>;
|
|
12
|
-
config?: UseHookConfig<TDerivate> & {
|
|
13
|
-
delay?: number;
|
|
14
|
-
};
|
|
15
|
-
}, ...args: TArguments) => [subscribe: SubscribeToEmitter<TDerivate>, getState: StateGetter<TDerivate>, dispose: UnsubscribeCallback];
|
|
16
9
|
export declare const combineRetrieverEmitterAsynchronously: <TDerivate, TArguments extends StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends () => infer TResult ? Exclude<TResult, UnsubscribeCallback> : never; }>(parameters: {
|
|
17
10
|
selector: SelectorCallback<TResults, TDerivate>;
|
|
18
|
-
config?: UseHookConfig<TDerivate> & {
|
|
19
|
-
delay?: number;
|
|
20
|
-
};
|
|
21
|
-
}, ...args: TArguments) => [subscribe:
|
|
11
|
+
config?: (UseHookConfig<TDerivate> & {
|
|
12
|
+
delay?: number | undefined;
|
|
13
|
+
}) | undefined;
|
|
14
|
+
}, ...args: TArguments) => [subscribe: StateGetter<TDerivate>, getState: StateGetter<unknown>, dispose: UnsubscribeCallback];
|
|
22
15
|
/**
|
|
23
|
-
* @deprecated will be removed in the next major version use combineRetrieverAsynchronously
|
|
24
16
|
* @description
|
|
25
17
|
* This function allows you to create a derivate state by merging the state of multiple hooks.
|
|
26
18
|
* The update of the derivate state is debounced to avoid unnecessary re-renders.
|
|
27
19
|
* By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
|
|
28
20
|
* @returns A tuple containing the subscribe function, the state getter and the dispose function
|
|
29
21
|
*/
|
|
30
|
-
export declare const
|
|
31
|
-
selector: SelectorCallback<TResults, TDerivate>;
|
|
32
|
-
config?: UseHookConfig<TDerivate> & {
|
|
33
|
-
delay?: number;
|
|
34
|
-
};
|
|
35
|
-
}, ...args: TArguments) => [useHook: StateHook<TDerivate, null, null>, getState: StateGetter<TDerivate>, dispose: UnsubscribeCallback];
|
|
36
|
-
export declare const combineRetrieverAsynchronously: <TDerivate, TArguments extends StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends () => infer TResult ? Exclude<TResult, UnsubscribeCallback> : never; }>(parameters: {
|
|
22
|
+
export declare const combineRetrieverAsynchronously: <TDerivate, TArguments extends readonly StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends StateGetter<infer R> ? R : never; }>(parameters: {
|
|
37
23
|
selector: SelectorCallback<TResults, TDerivate>;
|
|
38
|
-
config?: UseHookConfig<TDerivate> & {
|
|
39
|
-
delay?: number;
|
|
40
|
-
};
|
|
41
|
-
}, ...args: TArguments) => [useHook: StateHook<TDerivate, null,
|
|
24
|
+
config?: (UseHookConfig<TDerivate> & {
|
|
25
|
+
delay?: number | undefined;
|
|
26
|
+
}) | undefined;
|
|
27
|
+
}, ...args: TArguments) => [useHook: StateHook<TDerivate, null, BaseMetadata>, getState: StateGetter<TDerivate>, dispose: UnsubscribeCallback];
|
|
@@ -1,187 +1,50 @@
|
|
|
1
|
-
import { ActionCollectionConfig, StateHook, StateSetter, ActionCollectionResult, StateGetter,
|
|
1
|
+
import { ActionCollectionConfig, StateHook, StateSetter, ActionCollectionResult, StateGetter, BaseMetadata, MetadataSetter, GlobalStoreCallbacks } from './GlobalStore.types';
|
|
2
2
|
import React, { PropsWithChildren } from 'react';
|
|
3
|
-
export type
|
|
3
|
+
export type ContextProviderAPI<Value, Metadata extends BaseMetadata | unknown> = {
|
|
4
4
|
setMetadata: MetadataSetter<Metadata>;
|
|
5
5
|
setState: StateSetter<Value>;
|
|
6
6
|
getState: StateGetter<Value>;
|
|
7
7
|
getMetadata: () => Metadata;
|
|
8
8
|
actions: Record<string, (...args: any[]) => void>;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
10
|
+
export type ContextProvider<Value, Metadata extends BaseMetadata | unknown> = React.FC<PropsWithChildren<{
|
|
11
11
|
value?: Value | ((initialValue: Value) => Value);
|
|
12
|
-
ref?: React.
|
|
12
|
+
ref?: React.RefObject<ContextProviderAPI<Value, Metadata>>;
|
|
13
13
|
}>>;
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
* Allows you to create a selector hooks
|
|
17
|
-
* This hooks only works when contained in the scope of the provider
|
|
18
|
-
*/
|
|
19
|
-
createSelectorHook: <RootState, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(this: Context<RootState, PublicStateMutator, Metadata>, mainSelector?: (state: Value) => RootSelectorResult, args?: {
|
|
14
|
+
export type ContextHook<Value, PublicStateMutator, Metadata extends BaseMetadata | unknown> = (() => StateHook<Value, PublicStateMutator, Metadata>) & {
|
|
15
|
+
createSelectorHook: <RootState, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(this: ContextHook<RootState, PublicStateMutator, Metadata>, mainSelector?: (state: Value) => RootSelectorResult, args?: {
|
|
20
16
|
isEqual?: (current: RootDerivate, next: RootDerivate) => boolean;
|
|
21
17
|
isEqualRoot?: (current: RootState, next: RootState) => boolean;
|
|
22
18
|
name?: string;
|
|
23
19
|
}) => StateHook<RootDerivate, PublicStateMutator, Metadata>;
|
|
24
20
|
};
|
|
25
21
|
export interface CreateContext {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
];
|
|
30
|
-
createContext<Value, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<Value, Metadata> | {} | null = null, StoreAPI = {
|
|
31
|
-
setMetadata: MetadataSetter<Metadata>;
|
|
32
|
-
setState: StateSetter<Value>;
|
|
33
|
-
getState: StateGetter<Value>;
|
|
34
|
-
getMetadata: () => Metadata;
|
|
35
|
-
actions: ActionsConfig extends null ? null : Record<string, (...args: any[]) => void>;
|
|
36
|
-
}>(state: Value, config: Readonly<{
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated We needed to move the actions parameter as a third argument to fix several issues with the type inference of the actions
|
|
39
|
-
*/
|
|
40
|
-
actions?: ActionsConfig;
|
|
41
|
-
/**
|
|
42
|
-
* Non reactive information about the state
|
|
43
|
-
*/
|
|
44
|
-
metadata?: Metadata;
|
|
45
|
-
/**
|
|
46
|
-
* executes immediately after the store is created
|
|
47
|
-
* */
|
|
48
|
-
onInit?: (args: StoreAPI) => void;
|
|
49
|
-
onStateChanged?: (args: StoreAPI & StateChanges<Value>) => void;
|
|
50
|
-
onSubscribed?: (args: StoreAPI) => void;
|
|
51
|
-
/**
|
|
52
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
53
|
-
*/
|
|
54
|
-
computePreventStateChange?: (args: StoreAPI & StateChanges<Value>) => boolean;
|
|
55
|
-
onUnMount?: () => void;
|
|
56
|
-
}>): readonly [
|
|
57
|
-
Context<Value, ActionsConfig extends null ? StateSetter<Value> : ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>,
|
|
58
|
-
Provider<Context<Value, ActionsConfig extends null ? StateSetter<Value> : ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>, Metadata>
|
|
59
|
-
];
|
|
60
|
-
createContext<Value, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, StoreAPI = {
|
|
61
|
-
setMetadata: MetadataSetter<Metadata>;
|
|
62
|
-
setState: StateSetter<Value>;
|
|
63
|
-
getState: StateGetter<Value>;
|
|
64
|
-
getMetadata: () => Metadata;
|
|
65
|
-
actions: Record<string, (...args: any[]) => void>;
|
|
66
|
-
}>(state: Value, config: Readonly<{
|
|
67
|
-
/**
|
|
68
|
-
* Non reactive information about the state
|
|
69
|
-
*/
|
|
70
|
-
metadata?: Metadata;
|
|
71
|
-
/**
|
|
72
|
-
* executes immediately after the store is created
|
|
73
|
-
* */
|
|
74
|
-
onInit?: (args: StoreAPI) => void;
|
|
75
|
-
onStateChanged?: (args: StoreAPI & StateChanges<Value>) => void;
|
|
76
|
-
onSubscribed?: (args: StoreAPI) => void;
|
|
77
|
-
/**
|
|
78
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
79
|
-
*/
|
|
80
|
-
computePreventStateChange?: (args: StoreAPI & StateChanges<Value>) => boolean;
|
|
81
|
-
onUnMount?: () => void;
|
|
82
|
-
}>, actions: ActionsConfig): readonly [
|
|
83
|
-
Context<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>,
|
|
84
|
-
Provider<Context<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>>
|
|
85
|
-
];
|
|
86
|
-
createContext<Value, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, StoreAPI = {
|
|
87
|
-
setMetadata: MetadataSetter<Metadata>;
|
|
88
|
-
setState: StateSetter<Value>;
|
|
89
|
-
getState: StateGetter<Value>;
|
|
90
|
-
getMetadata: () => Metadata;
|
|
91
|
-
}>(state: Value, builder: () => ActionsConfig, config?: Readonly<{
|
|
92
|
-
/**
|
|
93
|
-
* Non reactive information about the state
|
|
94
|
-
*/
|
|
95
|
-
metadata?: Metadata;
|
|
96
|
-
/**
|
|
97
|
-
* executes immediately after the store is created
|
|
98
|
-
* */
|
|
99
|
-
onInit?: (args: StoreAPI) => void;
|
|
100
|
-
onStateChanged?: (args: StoreAPI & StateChanges<Value>) => void;
|
|
101
|
-
onSubscribed?: (args: StoreAPI) => void;
|
|
102
|
-
/**
|
|
103
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
104
|
-
*/
|
|
105
|
-
computePreventStateChange?: (args: StoreAPI & StateChanges<Value>) => boolean;
|
|
106
|
-
onUnMount?: () => void;
|
|
107
|
-
}>): readonly [
|
|
108
|
-
Context<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>,
|
|
109
|
-
Provider<Context<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>>
|
|
22
|
+
<Value, Hook = ContextHook<Value, StateSetter<Value>, BaseMetadata>>(builder: () => Value): readonly [
|
|
23
|
+
Hook,
|
|
24
|
+
ContextProvider<Hook, BaseMetadata>
|
|
110
25
|
];
|
|
26
|
+
<Value, Metadata extends BaseMetadata | unknown, Hook = ContextHook<Value, StateSetter<Value>, Metadata>>(builder: () => Value, args: {
|
|
27
|
+
name?: string;
|
|
28
|
+
metadata?: unknown;
|
|
29
|
+
callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
|
|
30
|
+
onUnMount?: () => void;
|
|
31
|
+
};
|
|
32
|
+
}): readonly [Hook, ContextProvider<Hook, Metadata>];
|
|
33
|
+
<Value, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<Value> : ActionCollectionResult<Value, Metadata, NonNullable<ActionsConfig>>, Hook = ContextHook<Value, PublicStateMutator, Metadata>>(builder: () => Value, args: {
|
|
34
|
+
name?: string;
|
|
35
|
+
metadata?: unknown;
|
|
36
|
+
callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
|
|
37
|
+
onUnMount?: () => void;
|
|
38
|
+
};
|
|
39
|
+
actions?: ActionCollectionConfig<Value, Metadata>;
|
|
40
|
+
}): readonly [Hook, ContextProvider<Hook, Metadata>];
|
|
41
|
+
<Value, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, Hook = ContextHook<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>>(builder: () => Value, args: {
|
|
42
|
+
name?: string;
|
|
43
|
+
metadata?: unknown;
|
|
44
|
+
callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
|
|
45
|
+
onUnMount?: () => void;
|
|
46
|
+
};
|
|
47
|
+
actions: ActionCollectionConfig<Value, Metadata>;
|
|
48
|
+
}): readonly [Hook, ContextProvider<Hook, Metadata>];
|
|
111
49
|
}
|
|
112
|
-
export declare const createContext:
|
|
113
|
-
<Value>(state: Value): readonly [Context<Value, StateSetter<Value>, BaseMetadata>, Provider<Context<Value, StateSetter<Value>, BaseMetadata>, BaseMetadata>];
|
|
114
|
-
<Value_1, Metadata extends BaseMetadata, ActionsConfig extends {} | ActionCollectionConfig<Value_1, Metadata> = null, StoreAPI = {
|
|
115
|
-
setMetadata: MetadataSetter<Metadata>;
|
|
116
|
-
setState: StateSetter<Value_1>;
|
|
117
|
-
getState: StateGetter<Value_1>;
|
|
118
|
-
getMetadata: () => Metadata;
|
|
119
|
-
actions: ActionsConfig extends null ? null : Record<string, (...args: any[]) => void>;
|
|
120
|
-
}>(state: Value_1, config: Readonly<{
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated We needed to move the actions parameter as a third argument to fix several issues with the type inference of the actions
|
|
123
|
-
*/
|
|
124
|
-
actions?: ActionsConfig;
|
|
125
|
-
/**
|
|
126
|
-
* Non reactive information about the state
|
|
127
|
-
*/
|
|
128
|
-
metadata?: Metadata;
|
|
129
|
-
/**
|
|
130
|
-
* executes immediately after the store is created
|
|
131
|
-
* */
|
|
132
|
-
onInit?: (args: StoreAPI) => void;
|
|
133
|
-
onStateChanged?: (args: StoreAPI & StateChanges<Value_1>) => void;
|
|
134
|
-
onSubscribed?: (args: StoreAPI) => void;
|
|
135
|
-
/**
|
|
136
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
137
|
-
*/
|
|
138
|
-
computePreventStateChange?: (args: StoreAPI & StateChanges<Value_1>) => boolean;
|
|
139
|
-
onUnMount?: () => void;
|
|
140
|
-
}>): readonly [Context<Value_1, ActionsConfig extends null ? StateSetter<Value_1> : ActionCollectionResult<Value_1, Metadata, ActionsConfig>, Metadata>, Provider<Context<Value_1, ActionsConfig extends null ? StateSetter<Value_1> : ActionCollectionResult<Value_1, Metadata, ActionsConfig>, Metadata>, Metadata>];
|
|
141
|
-
<Value_2, Metadata_1 extends BaseMetadata, ActionsConfig_1 extends ActionCollectionConfig<Value_2, Metadata_1>, StoreAPI_1 = {
|
|
142
|
-
setMetadata: MetadataSetter<Metadata_1>;
|
|
143
|
-
setState: StateSetter<Value_2>;
|
|
144
|
-
getState: StateGetter<Value_2>;
|
|
145
|
-
getMetadata: () => Metadata_1;
|
|
146
|
-
actions: Record<string, (...args: any[]) => void>;
|
|
147
|
-
}>(state: Value_2, config: Readonly<{
|
|
148
|
-
/**
|
|
149
|
-
* Non reactive information about the state
|
|
150
|
-
*/
|
|
151
|
-
metadata?: Metadata_1;
|
|
152
|
-
/**
|
|
153
|
-
* executes immediately after the store is created
|
|
154
|
-
* */
|
|
155
|
-
onInit?: (args: StoreAPI_1) => void;
|
|
156
|
-
onStateChanged?: (args: StoreAPI_1 & StateChanges<Value_2>) => void;
|
|
157
|
-
onSubscribed?: (args: StoreAPI_1) => void;
|
|
158
|
-
/**
|
|
159
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
160
|
-
*/
|
|
161
|
-
computePreventStateChange?: (args: StoreAPI_1 & StateChanges<Value_2>) => boolean;
|
|
162
|
-
onUnMount?: () => void;
|
|
163
|
-
}>, actions: ActionsConfig_1): readonly [Context<Value_2, ActionCollectionResult<Value_2, Metadata_1, ActionsConfig_1>, Metadata_1>, Provider<Context<Value_2, ActionCollectionResult<Value_2, Metadata_1, ActionsConfig_1>, Metadata_1>, BaseMetadata>];
|
|
164
|
-
<Value_3, Metadata_2 extends BaseMetadata, ActionsConfig_2 extends ActionCollectionConfig<Value_3, Metadata_2>, StoreAPI_2 = {
|
|
165
|
-
setMetadata: MetadataSetter<Metadata_2>;
|
|
166
|
-
setState: StateSetter<Value_3>;
|
|
167
|
-
getState: StateGetter<Value_3>;
|
|
168
|
-
getMetadata: () => Metadata_2;
|
|
169
|
-
}>(state: Value_3, builder: () => ActionsConfig_2, config?: Readonly<{
|
|
170
|
-
/**
|
|
171
|
-
* Non reactive information about the state
|
|
172
|
-
*/
|
|
173
|
-
metadata?: Metadata_2;
|
|
174
|
-
/**
|
|
175
|
-
* executes immediately after the store is created
|
|
176
|
-
* */
|
|
177
|
-
onInit?: (args: StoreAPI_2) => void;
|
|
178
|
-
onStateChanged?: (args: StoreAPI_2 & StateChanges<Value_3>) => void;
|
|
179
|
-
onSubscribed?: (args: StoreAPI_2) => void;
|
|
180
|
-
/**
|
|
181
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
182
|
-
*/
|
|
183
|
-
computePreventStateChange?: (args: StoreAPI_2 & StateChanges<Value_3>) => boolean;
|
|
184
|
-
onUnMount?: () => void;
|
|
185
|
-
}>): readonly [Context<Value_3, ActionCollectionResult<Value_3, Metadata_2, ActionsConfig_2>, Metadata_2>, Provider<Context<Value_3, ActionCollectionResult<Value_3, Metadata_2, ActionsConfig_2>, Metadata_2>, BaseMetadata>];
|
|
186
|
-
};
|
|
187
|
-
export {};
|
|
50
|
+
export declare const createContext: CreateContext;
|
package/lib/src/GlobalStore.d.ts
CHANGED
|
@@ -1,64 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { UniqueSymbol } from './GlobalStore.utils';
|
|
2
|
+
import { ActionCollectionConfig, StateSetter, GlobalStoreCallbacks, ActionCollectionResult, MetadataSetter, UseHookConfig, StateGetter, SelectorCallback, SubscriberParameters, MetadataGetter, StateHook, BaseMetadata, StateChanges, StoreTools, ObservableFragment } from './GlobalStore.types';
|
|
3
3
|
/**
|
|
4
4
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
5
5
|
* */
|
|
6
|
-
export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> |
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
actions:
|
|
12
|
-
}, PublicStateMutator = ActionsConfig extends null ? StateSetter<State> : ActionCollectionResult<State, Metadata, ActionsConfig>> {
|
|
13
|
-
protected actionsConfig: ActionsConfig;
|
|
14
|
-
/**
|
|
15
|
-
* list of all the subscribers setState functions
|
|
16
|
-
* @template {State} TState - The type of the state object
|
|
17
|
-
* */
|
|
6
|
+
export declare class GlobalStore<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> {
|
|
7
|
+
protected _name: string;
|
|
8
|
+
actionsConfig: ActionsConfig | null;
|
|
9
|
+
callbacks: GlobalStoreCallbacks<State, Metadata> | null;
|
|
10
|
+
metadata: Metadata;
|
|
11
|
+
actions: ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>> | null;
|
|
18
12
|
subscribers: Map<string, SubscriberParameters>;
|
|
19
|
-
|
|
20
|
-
* Actions of the store
|
|
21
|
-
*/
|
|
22
|
-
actions?: ActionsConfig extends null ? null : ActionCollectionResult<State, Metadata, ActionsConfig>;
|
|
23
|
-
protected config: GlobalStoreConfig<State, Metadata>;
|
|
24
|
-
/**
|
|
25
|
-
* execute when the store is initialized
|
|
26
|
-
*/
|
|
27
|
-
protected onInit?: (args: StoreAPI) => void;
|
|
28
|
-
protected onStateChanged?: (args: StoreAPI & StateChanges<State>) => void;
|
|
29
|
-
protected onSubscribed?: (args: StoreAPI) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Every time a state change is triggered and before the state is updated, it allows to prevent the state change by returning true
|
|
32
|
-
*/
|
|
33
|
-
protected computePreventStateChange?: (parameters: StoreAPI & StateChanges<State>) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* We use a wrapper in order to be able to force the state update when necessary even with primitive types
|
|
36
|
-
*/
|
|
37
|
-
protected stateWrapper: {
|
|
13
|
+
stateWrapper: {
|
|
38
14
|
state: State;
|
|
39
15
|
};
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated direct modifications of the state could end up in unexpected behaviors
|
|
42
|
-
*/
|
|
43
|
-
protected get state(): State;
|
|
44
16
|
constructor(state: State);
|
|
45
|
-
constructor(state: State,
|
|
46
|
-
|
|
17
|
+
constructor(state: State, args: {
|
|
18
|
+
metadata?: Metadata;
|
|
19
|
+
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
20
|
+
actions?: ActionsConfig;
|
|
21
|
+
name?: string;
|
|
22
|
+
});
|
|
23
|
+
protected onInit?: (args: StoreTools<State, Metadata>) => void;
|
|
24
|
+
protected onStateChanged?: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
|
|
25
|
+
protected onSubscribed?: (args: StoreTools<State, Metadata>) => void;
|
|
26
|
+
protected computePreventStateChange?: (parameters: StoreTools<State, Metadata> & StateChanges<State>) => boolean;
|
|
47
27
|
protected initialize: () => Promise<void>;
|
|
48
|
-
protected executeSetStateForSubscriber: (subscription: SubscriberParameters,
|
|
49
|
-
forceUpdate: boolean;
|
|
28
|
+
protected executeSetStateForSubscriber: (subscription: SubscriberParameters, args: {
|
|
29
|
+
forceUpdate: boolean | undefined;
|
|
50
30
|
newRootState: State;
|
|
51
|
-
currentRootState: State;
|
|
52
|
-
identifier: string;
|
|
53
|
-
}) =>
|
|
31
|
+
currentRootState: State | UniqueSymbol;
|
|
32
|
+
identifier: string | undefined;
|
|
33
|
+
}) => {
|
|
34
|
+
didUpdate: boolean;
|
|
35
|
+
};
|
|
54
36
|
/**
|
|
55
37
|
* set the state and update all the subscribers
|
|
56
38
|
* @param {StateSetter<State>} setter - The setter function or the value to set
|
|
57
39
|
* */
|
|
58
|
-
protected setState: ({ state: newRootState,
|
|
40
|
+
protected setState: ({ state: newRootState, }: {
|
|
59
41
|
state: State;
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
}, { forceUpdate, identifier }: {
|
|
43
|
+
forceUpdate?: boolean | undefined;
|
|
44
|
+
identifier?: string | undefined;
|
|
62
45
|
}) => void;
|
|
63
46
|
/**
|
|
64
47
|
* Set the value of the metadata property, this is no reactive and will not trigger a re-render
|
|
@@ -66,56 +49,50 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
66
49
|
* */
|
|
67
50
|
protected setMetadata: MetadataSetter<Metadata>;
|
|
68
51
|
protected getMetadata: () => Metadata;
|
|
69
|
-
|
|
70
|
-
selector?: SelectorCallback<unknown, unknown>;
|
|
71
|
-
callback: SubscribeCallback<unknown>;
|
|
72
|
-
config: SubscribeCallbackConfig<unknown>;
|
|
73
|
-
}) => {
|
|
74
|
-
stateWrapper: {
|
|
75
|
-
state: unknown;
|
|
76
|
-
};
|
|
77
|
-
subscriptionCallback: SubscriptionCallback;
|
|
78
|
-
};
|
|
79
|
-
protected getState: StateGetter<State>;
|
|
52
|
+
getState: StateGetter<State>;
|
|
80
53
|
/**
|
|
81
|
-
* get the parameters object to pass to the callback functions
|
|
54
|
+
* get the parameters object to pass to the callback functions:
|
|
55
|
+
* onInit, onStateChanged, onSubscribed, computePreventStateChange
|
|
82
56
|
* */
|
|
83
|
-
|
|
84
|
-
protected lastSubscriptionId: string;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
protected
|
|
57
|
+
getConfigCallbackParam: () => StoreTools<State, Metadata>;
|
|
58
|
+
protected lastSubscriptionId: string | null;
|
|
59
|
+
protected setOrUpdateSubscription: (subscription: SubscriberParameters) => {
|
|
60
|
+
isNewSubscription?: boolean;
|
|
61
|
+
};
|
|
62
|
+
protected partialUpdateSubscription: (subscriptionId: string, values: Partial<SubscriberParameters>) => void;
|
|
89
63
|
protected executeOnSubscribed: () => void;
|
|
90
64
|
/**
|
|
91
65
|
* Returns a custom hook that allows to handle a global state
|
|
92
66
|
* @returns {[State, StateMutator, Metadata]} - The state, the state setter or the actions map, the metadata
|
|
93
67
|
* */
|
|
94
68
|
getHook: () => StateHook<State, PublicStateMutator, Metadata>;
|
|
69
|
+
protected computeSelectedState: ({ selector, subscriptionId, config, currentDependencies, computeChildState, stateWrapperRef, }: {
|
|
70
|
+
selector: SelectorCallback<unknown, unknown> | undefined;
|
|
71
|
+
subscriptionId: string;
|
|
72
|
+
config: UseHookConfig<unknown, unknown>;
|
|
73
|
+
currentDependencies: unknown[] | undefined;
|
|
74
|
+
computeChildState: () => {
|
|
75
|
+
state: unknown;
|
|
76
|
+
};
|
|
77
|
+
stateWrapperRef: {
|
|
78
|
+
state: unknown;
|
|
79
|
+
};
|
|
80
|
+
}) => unknown;
|
|
95
81
|
/**
|
|
96
82
|
* @description
|
|
97
83
|
* Use this function to create a custom global hook which contains a fragment of the state of another hook
|
|
98
84
|
*/
|
|
99
|
-
createSelectorHook: <RootState, StateMutator, Metadata_1 extends BaseMetadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector
|
|
100
|
-
isEqual?: (current: RootDerivate, next: RootDerivate) => boolean;
|
|
101
|
-
isEqualRoot?: (current: RootState, next: RootState) => boolean;
|
|
102
|
-
name?: string;
|
|
85
|
+
createSelectorHook: <RootState, StateMutator, Metadata_1 extends BaseMetadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector: (state: RootState) => RootSelectorResult, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
|
|
86
|
+
isEqual?: ((current: RootDerivate, next: RootDerivate) => boolean) | undefined;
|
|
87
|
+
isEqualRoot?: ((current: RootState, next: RootState) => boolean) | undefined;
|
|
88
|
+
name?: string | undefined;
|
|
103
89
|
}) => StateHook<RootDerivate, StateMutator, Metadata_1>;
|
|
104
|
-
|
|
105
|
-
* 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
|
|
106
|
-
* @returns {[() => State, StateMutator, () => Metadata]} - The state getter, the state setter or the actions map, the metadata getter
|
|
107
|
-
* */
|
|
108
|
-
stateControls: () => [StateGetter<State>, PublicStateMutator, MetadataGetter<Metadata>];
|
|
90
|
+
stateControls: () => [retriever: StateGetter<State>, mutator: PublicStateMutator, metadata: MetadataGetter<Metadata>];
|
|
109
91
|
/**
|
|
110
92
|
* Returns the state setter or the actions map
|
|
111
93
|
* @returns {StateMutator} - The state setter or the actions map
|
|
112
94
|
* */
|
|
113
95
|
protected getStateOrchestrator: () => PublicStateMutator;
|
|
114
|
-
/**
|
|
115
|
-
* Calculate whenever or not we should compute the callback parameters on the state change
|
|
116
|
-
* @returns {boolean} - True if we should compute the callback parameters on the state change
|
|
117
|
-
* */
|
|
118
|
-
protected hasStateCallbacks: () => boolean;
|
|
119
96
|
/**
|
|
120
97
|
* This is responsible for defining whenever or not the state change should be allowed or prevented
|
|
121
98
|
* the function also execute the functions:
|
|
@@ -127,5 +104,10 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
127
104
|
* This creates a map of actions that can be used to modify or interact with the state
|
|
128
105
|
* @returns {ActionCollectionResult<State, Metadata, StateMutator>} - The actions map result of the configuration object passed to the constructor
|
|
129
106
|
* */
|
|
130
|
-
|
|
107
|
+
getStoreActionsMap: () => null | ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>;
|
|
108
|
+
createObservable<Fragment>(mainSelector: (state: State) => Fragment, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
|
|
109
|
+
isEqual?: (current: Fragment, next: Fragment) => boolean;
|
|
110
|
+
isEqualRoot?: (current: State, next: State) => boolean;
|
|
111
|
+
name?: string;
|
|
112
|
+
}): ObservableFragment<Fragment>;
|
|
131
113
|
}
|
|
@@ -1,125 +1,37 @@
|
|
|
1
|
-
import { ActionCollectionConfig, StateSetter, ActionCollectionResult,
|
|
2
|
-
|
|
3
|
-
* Creates a global hook that can be used to access the state and actions across the application
|
|
4
|
-
* @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
|
|
5
|
-
*/
|
|
6
|
-
export declare const createGlobalState: {
|
|
1
|
+
import { ActionCollectionConfig, StateSetter, ActionCollectionResult, StateHook, CustomGlobalHookBuilderParams, BaseMetadata, GlobalStoreCallbacks } from './GlobalStore.types';
|
|
2
|
+
export interface CreateGlobalState {
|
|
7
3
|
<State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>;
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getMetadata: () => Metadata;
|
|
13
|
-
actions: ActionsConfig extends null ? null : Record<string, (...args: any[]) => void>;
|
|
14
|
-
}>(state: State_1, config: Readonly<{
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated We needed to move the actions parameter as a third argument to fix several issues with the type inference of the actions
|
|
17
|
-
*/
|
|
4
|
+
<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
5
|
+
name?: string;
|
|
6
|
+
metadata?: Metadata;
|
|
7
|
+
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
18
8
|
actions?: ActionsConfig;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
}): StateHook<State, PublicStateMutator, Metadata>;
|
|
10
|
+
<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>>(state: State, args: {
|
|
11
|
+
name?: string;
|
|
22
12
|
metadata?: Metadata;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
metadata?: Metadata_1;
|
|
45
|
-
/**
|
|
46
|
-
* executes immediately after the store is created
|
|
47
|
-
* */
|
|
48
|
-
onInit?: (args: StoreAPI_1) => void;
|
|
49
|
-
onStateChanged?: (args: StoreAPI_1 & StateChanges<State_2>) => void;
|
|
50
|
-
onSubscribed?: (args: StoreAPI_1) => void;
|
|
51
|
-
/**
|
|
52
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
53
|
-
*/
|
|
54
|
-
computePreventStateChange?: (args: StoreAPI_1 & StateChanges<State_2>) => boolean;
|
|
55
|
-
}>, actions: ActionsConfig_1): StateHook<State_2, ActionCollectionResult<State_2, Metadata_1, ActionsConfig_1>, Metadata_1>;
|
|
56
|
-
<State_3, Metadata_2 extends BaseMetadata, ActionsConfig_2 extends ActionCollectionConfig<State_3, Metadata_2>, StoreAPI_2 = {
|
|
57
|
-
setMetadata: MetadataSetter<Metadata_2>;
|
|
58
|
-
setState: StateSetter<State_3>;
|
|
59
|
-
getState: StateGetter<State_3>;
|
|
60
|
-
getMetadata: () => Metadata_2;
|
|
61
|
-
}>(state: State_3, builder: () => ActionsConfig_2, config?: Readonly<{
|
|
62
|
-
/**
|
|
63
|
-
* Non reactive information about the state
|
|
64
|
-
*/
|
|
65
|
-
metadata?: Metadata_2;
|
|
66
|
-
/**
|
|
67
|
-
* executes immediately after the store is created
|
|
68
|
-
* */
|
|
69
|
-
onInit?: (args: StoreAPI_2) => void;
|
|
70
|
-
onStateChanged?: (args: StoreAPI_2 & StateChanges<State_3>) => void;
|
|
71
|
-
onSubscribed?: (args: StoreAPI_2) => void;
|
|
72
|
-
/**
|
|
73
|
-
* callback function called every time the state is about to change and it allows you to prevent the state change
|
|
74
|
-
*/
|
|
75
|
-
computePreventStateChange?: (args: StoreAPI_2 & StateChanges<State_3>) => boolean;
|
|
76
|
-
}>): StateHook<State_3, ActionCollectionResult<State_3, Metadata_2, ActionsConfig_2>, Metadata_2>;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* @description
|
|
80
|
-
* Use this function to create a custom global store.
|
|
81
|
-
* You can use this function to create a store with async storage.
|
|
82
|
-
*/
|
|
83
|
-
export declare const createCustomGlobalState: <InheritMetadata, TCustomConfig>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<InheritMetadata, TCustomConfig>) => <State, Metadata, ActionsConfig extends Readonly<ActionCollectionConfig<State, Metadata & InheritMetadata>> = null>(state: State, _config?: Readonly<{
|
|
84
|
-
metadata?: Metadata & InheritMetadata;
|
|
85
|
-
readonly actions?: Readonly<ActionsConfig>;
|
|
86
|
-
onInit?: (args: StoreTools<State, Metadata & InheritMetadata>) => void;
|
|
87
|
-
onStateChanged?: (args: StoreTools<State, Metadata & InheritMetadata> & StateChanges<State>) => void;
|
|
88
|
-
onSubscribed?: (parameters: StoreTools<State, Metadata & InheritMetadata>) => void;
|
|
89
|
-
computePreventStateChange?: (args: StoreTools<State, Metadata & InheritMetadata> & StateChanges<State>) => boolean;
|
|
90
|
-
/**
|
|
91
|
-
* @description
|
|
92
|
-
* Type of the configuration object that the custom hook will require or accept
|
|
93
|
-
*/
|
|
94
|
-
config?: TCustomConfig;
|
|
95
|
-
}>) => StateHook<State, ActionsConfig extends null ? StateSetter<State> : ActionCollectionResult<State, Metadata & InheritMetadata, ActionsConfig>, Metadata & InheritMetadata>;
|
|
96
|
-
/**
|
|
97
|
-
* @description
|
|
98
|
-
* Use this function to create a custom global store.
|
|
99
|
-
* You can use this function to create a store with async storage.
|
|
100
|
-
* @deprecated
|
|
101
|
-
*/
|
|
102
|
-
export declare const createCustomGlobalStateWithDecoupledFuncs: <InheritMetadata, TCustomConfig>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<InheritMetadata, TCustomConfig>) => <State, Metadata, ActionsConfig extends Readonly<ActionCollectionConfig<State, Metadata & InheritMetadata>> = null>(state: State, _config?: Readonly<{
|
|
103
|
-
metadata?: Metadata & InheritMetadata;
|
|
104
|
-
readonly actions?: Readonly<ActionsConfig>;
|
|
105
|
-
onInit?: (args: StoreTools<State, Metadata & InheritMetadata>) => void;
|
|
106
|
-
onStateChanged?: (args: StoreTools<State, Metadata & InheritMetadata> & StateChanges<State>) => void;
|
|
107
|
-
onSubscribed?: (parameters: StoreTools<State, Metadata & InheritMetadata>) => void;
|
|
108
|
-
computePreventStateChange?: (args: StoreTools<State, Metadata & InheritMetadata> & StateChanges<State>) => boolean;
|
|
109
|
-
/**
|
|
110
|
-
* @description
|
|
111
|
-
* Type of the configuration object that the custom hook will require or accept
|
|
112
|
-
*/
|
|
113
|
-
config?: TCustomConfig;
|
|
114
|
-
}>) => StateHook<State, ActionsConfig extends null ? StateSetter<State> : ActionCollectionResult<State, Metadata & InheritMetadata, ActionsConfig>, Metadata & InheritMetadata>;
|
|
115
|
-
/**
|
|
116
|
-
* @description
|
|
117
|
-
* Use this function to create a custom global hook which contains a fragment of the state of another hook
|
|
118
|
-
*/
|
|
119
|
-
export declare const createDerivate: <RootState, StateMutator, Metadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(useHook: StateHook<RootState, StateMutator, Metadata>, mainSelector?: (state: RootState) => RootSelectorResult, args?: Omit<UseHookConfig<RootDerivate, RootState>, "dependencies">) => StateHook<RootDerivate, StateMutator, Metadata>;
|
|
13
|
+
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
14
|
+
actions: ActionsConfig;
|
|
15
|
+
}): StateHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
|
|
16
|
+
}
|
|
17
|
+
export declare const createGlobalState: CreateGlobalState;
|
|
18
|
+
export interface CustomCreateGlobalState<TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata> {
|
|
19
|
+
<State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>;
|
|
20
|
+
<State, Metadata extends BaseMetadata | unknown>(state: State, args: {
|
|
21
|
+
name?: string;
|
|
22
|
+
metadata?: Metadata;
|
|
23
|
+
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
24
|
+
config?: TCustomConfig;
|
|
25
|
+
}): StateHook<State, StateSetter<State>, BaseMetadata>;
|
|
26
|
+
<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends Readonly<ActionCollectionConfig<State, InheritMetadata & Metadata>>>(state: State, args: {
|
|
27
|
+
name?: string;
|
|
28
|
+
metadata?: Metadata;
|
|
29
|
+
callbacks?: GlobalStoreCallbacks<State, Metadata>;
|
|
30
|
+
actions?: ActionsConfig;
|
|
31
|
+
config?: TCustomConfig;
|
|
32
|
+
}): StateHook<State, ActionCollectionResult<State, InheritMetadata & Metadata, ActionsConfig>, Metadata>;
|
|
33
|
+
}
|
|
120
34
|
/**
|
|
121
|
-
* @description
|
|
122
|
-
* This function allows you to create a derivate emitter
|
|
123
|
-
* With this approach, you can subscribe to changes in a specific fragment or subset of the state.
|
|
35
|
+
* @description Simple custom global state hook builder
|
|
124
36
|
*/
|
|
125
|
-
export declare const
|
|
37
|
+
export declare const createCustomGlobalState: <TCustomConfig extends unknown, InheritMetadata extends unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* This parameter indicate whether we should force the re-render of the subscribers even if the state is the same,
|
|
4
|
-
* Do
|
|
5
|
-
*/
|
|
6
|
-
{ forceUpdate, }?: {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type StateSetter<State> = (setter: State | ((state: State) => State), meta?: {
|
|
7
3
|
/**
|
|
8
4
|
* @description you can add an identifier to the state call
|
|
9
5
|
* this will show up in the devtools to help you identify from where the state change was called
|
|
10
6
|
*/
|
|
11
|
-
identifier?: string;
|
|
7
|
+
identifier?: string | undefined;
|
|
12
8
|
/**
|
|
13
9
|
* @deprecated forceUpdate normally should not be used inside components
|
|
14
10
|
* Use this flag just in custom implementations of the global store
|
|
15
11
|
*/
|
|
16
|
-
forceUpdate?: boolean;
|
|
12
|
+
forceUpdate?: boolean | undefined;
|
|
17
13
|
}) => void;
|
|
18
|
-
export type
|
|
14
|
+
export type HookExtensions<State, StateMutator, Metadata extends BaseMetadata | unknown> = {
|
|
19
15
|
/**
|
|
20
16
|
* @description Return the state controls of the hook
|
|
21
17
|
* This selectors includes:
|
|
@@ -34,20 +30,41 @@ export type StateHook<State, StateMutator, Metadata extends BaseMetadata> = (<De
|
|
|
34
30
|
* The selector hook will be evaluated only if the result of the selector changes and the equality function returns false
|
|
35
31
|
* you can customize the equality function by passing the isEqualRoot and isEqual parameters
|
|
36
32
|
*/
|
|
37
|
-
createSelectorHook: <
|
|
33
|
+
createSelectorHook: <Derivate>(this: StateHook<State, StateMutator, Metadata>, selector: (state: State) => Derivate, args?: Omit<UseHookConfig<Derivate, State>, 'dependencies'> & {
|
|
34
|
+
name?: string;
|
|
35
|
+
}) => StateHook<Derivate, StateMutator, Metadata>;
|
|
36
|
+
createObservable: <Fragment>(this: StateHook<State, StateMutator, Metadata>, mainSelector: (state: State) => Fragment, args?: {
|
|
37
|
+
isEqual?: (current: Fragment, next: Fragment) => boolean;
|
|
38
|
+
isEqualRoot?: (current: State, next: State) => boolean;
|
|
38
39
|
name?: string;
|
|
39
|
-
}) =>
|
|
40
|
+
}) => ObservableFragment<Fragment>;
|
|
40
41
|
};
|
|
41
|
-
export type
|
|
42
|
+
export type ObservableFragment<State> = StateGetter<State> & {
|
|
43
|
+
createObservable: <Fragment>(this: ObservableFragment<State>, mainSelector: (state: State) => Fragment, args?: {
|
|
44
|
+
isEqual?: (current: Fragment, next: Fragment) => boolean;
|
|
45
|
+
isEqualRoot?: (current: State, next: State) => boolean;
|
|
46
|
+
name?: string;
|
|
47
|
+
}) => ObservableFragment<Fragment>;
|
|
48
|
+
_name: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
export interface StateHook<State, StateMutator, Metadata extends BaseMetadata | unknown> extends HookExtensions<State, StateMutator, Metadata> {
|
|
51
|
+
(): Readonly<[state: State, stateMutator: StateMutator, metadata: Metadata]> & HookExtensions<State, StateMutator, Metadata>;
|
|
52
|
+
<Derivate>(selector: (state: State) => Derivate, config?: UseHookConfig<Derivate, State>): Readonly<[
|
|
53
|
+
state: Derivate,
|
|
54
|
+
stateMutator: StateMutator,
|
|
55
|
+
metadata: Metadata
|
|
56
|
+
]> & HookExtensions<Derivate, StateMutator, Metadata>;
|
|
57
|
+
}
|
|
58
|
+
export type MetadataSetter<Metadata extends BaseMetadata | unknown> = (setter: Metadata | ((metadata: Metadata) => Metadata)) => void;
|
|
42
59
|
export type StateChanges<State> = {
|
|
43
60
|
state: State;
|
|
44
|
-
previousState
|
|
45
|
-
identifier
|
|
61
|
+
previousState: State | undefined;
|
|
62
|
+
identifier: string | undefined;
|
|
46
63
|
};
|
|
47
64
|
/**
|
|
48
65
|
* API for the actions of the global states
|
|
49
66
|
**/
|
|
50
|
-
export type StoreTools<State, Metadata extends BaseMetadata = BaseMetadata, Actions
|
|
67
|
+
export type StoreTools<State, Metadata extends BaseMetadata | unknown = BaseMetadata, Actions extends undefined | unknown | Record<string, (...args: any[]) => any> = unknown> = {
|
|
51
68
|
setMetadata: MetadataSetter<Metadata>;
|
|
52
69
|
setState: StateSetter<State>;
|
|
53
70
|
getState: StateGetter<State>;
|
|
@@ -57,27 +74,23 @@ export type StoreTools<State, Metadata extends BaseMetadata = BaseMetadata, Acti
|
|
|
57
74
|
/**
|
|
58
75
|
* contract for the storeActionsConfig configuration
|
|
59
76
|
*/
|
|
60
|
-
export interface ActionCollectionConfig<State, Metadata extends BaseMetadata
|
|
61
|
-
readonly [key: string]:
|
|
77
|
+
export interface ActionCollectionConfig<State, Metadata extends BaseMetadata | unknown, ThisAPI = Record<string, (...parameters: any[]) => unknown>> {
|
|
78
|
+
readonly [key: string]: {
|
|
79
|
+
(this: ThisAPI, ...parameters: any[]): (this: ThisAPI, storeTools: StoreTools<State, Metadata, Record<string, (...parameters: any[]) => unknown | void>>) => unknown | void;
|
|
80
|
+
};
|
|
62
81
|
}
|
|
63
|
-
export type ActionCollectionResult<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>> = {
|
|
64
|
-
[key in keyof ActionsConfig]:
|
|
82
|
+
export type ActionCollectionResult<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>> = {
|
|
83
|
+
[key in keyof ActionsConfig]: {
|
|
84
|
+
(...params: Parameters<ActionsConfig[key]>): ReturnType<ReturnType<ActionsConfig[key]>>;
|
|
85
|
+
};
|
|
65
86
|
};
|
|
66
|
-
export type
|
|
67
|
-
/**
|
|
68
|
-
* non reactive information that you want to store in the store
|
|
69
|
-
* */
|
|
70
|
-
metadata?: Metadata;
|
|
87
|
+
export type GlobalStoreCallbacks<State, Metadata extends BaseMetadata | unknown> = {
|
|
71
88
|
onInit?: (args: StoreTools<State, Metadata>) => void;
|
|
72
89
|
onStateChanged?: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
|
|
73
90
|
onSubscribed?: (args: StoreTools<State, Metadata>) => void;
|
|
74
91
|
computePreventStateChange?: (args: StoreTools<State, Metadata> & StateChanges<State>) => boolean;
|
|
75
92
|
};
|
|
76
|
-
export type UseHookConfig<State, TRoot =
|
|
77
|
-
/**
|
|
78
|
-
* The callback to execute when the state is changed to check if the same really changed
|
|
79
|
-
* If the function is not provided the derived state will perform a shallow comparison
|
|
80
|
-
*/
|
|
93
|
+
export type UseHookConfig<State, TRoot = unknown> = {
|
|
81
94
|
isEqual?: (current: State, next: State) => boolean;
|
|
82
95
|
isEqualRoot?: (current: TRoot, next: TRoot) => boolean;
|
|
83
96
|
dependencies?: unknown[];
|
|
@@ -94,63 +107,29 @@ export type SubscribeCallbackConfig<State> = UseHookConfig<State> & {
|
|
|
94
107
|
*/
|
|
95
108
|
export type SubscribeCallback<State> = (state: State) => void;
|
|
96
109
|
/**
|
|
97
|
-
*
|
|
98
|
-
*/
|
|
99
|
-
export type SubscriberCallback<State> = (subscribe: SubscribeToEmitter<State>) => void;
|
|
100
|
-
/**
|
|
101
|
-
* Callback function to get the current state of the store or to subscribe to the store changes
|
|
102
|
-
* @template State - the type of the state
|
|
103
|
-
* @param {SubscriberCallback<State> | null} callback - the callback function to subscribe to the store changes (optional)
|
|
104
|
-
* use the methods subscribe and subscribeSelect to subscribe to the store changes
|
|
105
|
-
* if you don't pass a callback function the hook will return the current state of the store
|
|
106
|
-
* @returns {UnsubscribeCallback | State} result - the state or the unsubscribe callback if you pass a callback function
|
|
107
|
-
*/
|
|
108
|
-
export type StateGetter<State> = <Subscription extends Subscribe | false = false>(
|
|
109
|
-
/**
|
|
110
|
-
* @param {SubscriberCallback<State> | null} callback - the callback function to subscribe to the store changes (optional)
|
|
111
|
-
* use the methods subscribe and subscribeSelect to subscribe to the store changes
|
|
112
|
-
*/
|
|
113
|
-
callback?: Subscription extends Subscribe ? SubscriberCallback<State> : null) => Subscription extends Subscribe ? UnsubscribeCallback : State;
|
|
114
|
-
export type BaseMetadata = {
|
|
115
|
-
name?: string;
|
|
116
|
-
} & Record<string, any>;
|
|
117
|
-
export type MetadataGetter<Metadata extends BaseMetadata> = () => Metadata;
|
|
118
|
-
/**
|
|
119
|
-
* Constant value type to indicate that the getter is a subscription
|
|
110
|
+
* get the current state or subscribe to the state changes
|
|
120
111
|
*/
|
|
121
|
-
export type
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
export type StateGetter<State> = {
|
|
113
|
+
(): State;
|
|
114
|
+
(subscription: SubscribeCallback<State>, config?: SubscribeCallbackConfig<State>): UnsubscribeCallback;
|
|
115
|
+
<TDerivate>(selector: SelectorCallback<State, TDerivate>, subscription: SubscribeCallback<TDerivate>, config?: SubscribeCallbackConfig<TDerivate>): UnsubscribeCallback;
|
|
116
|
+
};
|
|
117
|
+
export type BaseMetadata = Record<string, unknown>;
|
|
118
|
+
export type MetadataGetter<Metadata extends BaseMetadata | unknown> = () => Metadata;
|
|
119
|
+
export type CustomGlobalHookBuilderParams<TCustomConfig extends BaseMetadata | unknown, Metadata extends BaseMetadata | unknown> = {
|
|
120
|
+
onInitialize?: (args: StoreTools<unknown, Metadata, unknown>, config: TCustomConfig | undefined) => void;
|
|
121
|
+
onChange?: (args: StoreTools<unknown, Metadata, unknown> & StateChanges<unknown>, config: TCustomConfig | undefined) => void;
|
|
125
122
|
};
|
|
126
123
|
export type SelectorCallback<State, TDerivate> = (state: State) => TDerivate;
|
|
127
|
-
/**
|
|
128
|
-
* @description
|
|
129
|
-
* Function to subscribe to the store changes
|
|
130
|
-
* @returns {UnsubscribeCallback} result - Function to unsubscribe from the store
|
|
131
|
-
*/
|
|
132
|
-
export type SubscribeToEmitter<State> = <TParam1 extends SubscribeCallback<State> | SelectorCallback<State, unknown>, TResult = ReturnType<TParam1>, TConfig = TResult extends void | null | undefined | never ? SubscribeCallbackConfig<State> : SubscribeCallbackConfig<TResult>, TParam2 extends SubscribeCallbackConfig<State> | SubscribeCallback<TResult> = TResult extends void | null | undefined | never ? TConfig : SubscribeCallback<TResult>, TParam3 = TResult extends void | null | undefined | never ? never : TConfig>(
|
|
133
|
-
/**
|
|
134
|
-
* @description
|
|
135
|
-
* The callback function to subscribe to the store changes or a selector function to derive the state
|
|
136
|
-
*/
|
|
137
|
-
param1: TParam1,
|
|
138
|
-
/**
|
|
139
|
-
* @description
|
|
140
|
-
* The configuration object or the callback function to subscribe to the store changes
|
|
141
|
-
*/
|
|
142
|
-
param2?: TParam2,
|
|
143
|
-
/**
|
|
144
|
-
* @description
|
|
145
|
-
* The configuration object
|
|
146
|
-
*/
|
|
147
|
-
param3?: TParam3) => UnsubscribeCallback;
|
|
148
124
|
export type SubscriberParameters = {
|
|
149
125
|
subscriptionId: string;
|
|
150
|
-
selector: SelectorCallback<
|
|
151
|
-
config: UseHookConfig<
|
|
126
|
+
selector: SelectorCallback<unknown, unknown> | undefined;
|
|
127
|
+
config: UseHookConfig<unknown> | SubscribeCallbackConfig<unknown> | undefined;
|
|
152
128
|
currentState: unknown;
|
|
153
|
-
callback: SubscriptionCallback
|
|
129
|
+
callback: SubscriptionCallback | React.Dispatch<React.SetStateAction<{
|
|
130
|
+
state: unknown;
|
|
131
|
+
}>>;
|
|
132
|
+
isSetStateCallback: boolean;
|
|
154
133
|
};
|
|
155
134
|
/**
|
|
156
135
|
* @description
|
|
@@ -159,10 +138,8 @@ export type SubscriberParameters = {
|
|
|
159
138
|
* @param {unknown} params.state - The new state
|
|
160
139
|
* @param {string} params.identifier - Optional identifier for the setState call
|
|
161
140
|
*/
|
|
162
|
-
export type SubscriptionCallback = (params: {
|
|
163
|
-
state:
|
|
141
|
+
export type SubscriptionCallback<State = unknown> = (params: {
|
|
142
|
+
state: State;
|
|
143
|
+
}, args: {
|
|
164
144
|
identifier?: string;
|
|
165
145
|
}) => void;
|
|
166
|
-
export type SetStateCallback = (parameters: {
|
|
167
|
-
state: unknown;
|
|
168
|
-
}) => void;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* Shallow compare two values and return true if they are equal.
|
|
3
|
-
* This function just compare the first level of the values.
|
|
4
|
-
* @param value1
|
|
5
|
-
* @param value2
|
|
6
|
-
* @returns {boolean} true if the values are equal, false otherwise
|
|
7
|
-
*/
|
|
1
|
+
/// <reference types="react" />
|
|
8
2
|
export declare const shallowCompare: <T>(value1: T, value2: T) => boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
3
|
+
export declare const debounce: <T extends (...args: Parameters<T>) => void>(callback: T, delay?: number) => (...args: Parameters<T>) => void;
|
|
4
|
+
export declare const uniqueId: (prefix?: string) => string;
|
|
5
|
+
export declare const throwWrongKeyOnActionCollectionConfig: (action_key: string) => never;
|
|
6
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
7
|
+
export declare const uniqueSymbol: unique symbol;
|
|
8
|
+
export type UniqueSymbol = typeof uniqueSymbol;
|
|
9
|
+
export declare const useConstantValueRef: <T>(initializer: () => T) => import("react").RefObject<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionCollectionConfig,
|
|
1
|
+
import { ActionCollectionConfig, StoreTools, BaseMetadata, StateChanges } from './GlobalStore.types';
|
|
2
2
|
import { GlobalStore } from './GlobalStore';
|
|
3
3
|
/**
|
|
4
4
|
* @description
|
|
@@ -6,8 +6,7 @@ import { GlobalStore } from './GlobalStore';
|
|
|
6
6
|
* by implementing the abstract methods onInitialize and onChange.
|
|
7
7
|
* You can use this class to create a store with async storage.
|
|
8
8
|
*/
|
|
9
|
-
export declare abstract class GlobalStoreAbstract<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> |
|
|
10
|
-
constructor(state: State, config: GlobalStoreConfig<State, Metadata>, actionsConfig: ActionsConfig);
|
|
9
|
+
export declare abstract class GlobalStoreAbstract<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | unknown> extends GlobalStore<State, Metadata, ActionsConfig> {
|
|
11
10
|
protected onInit: (args: StoreTools<State, Metadata>) => void;
|
|
12
11
|
protected onStateChanged: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
|
|
13
12
|
protected abstract onInitialize: (args: StoreTools<State, Metadata>) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hooks-global-states",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "This is a package to easily handling global-state across your react-components No-redux",
|
|
5
5
|
"main": "lib/bundle.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
|
54
54
|
"@typescript-eslint/parser": "^4.9.1",
|
|
55
55
|
"babel-loader": "^9.1.2",
|
|
56
|
-
"cancelable-promise-jq": "^1.0.4",
|
|
57
56
|
"clean-webpack-plugin": "^4.0.0",
|
|
57
|
+
"easy-cancelable-promise": "^1.0.1",
|
|
58
58
|
"eslint": "^7.15.0",
|
|
59
59
|
"eslint-config-airbnb": "^18.2.1",
|
|
60
60
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"json-storage-formatter": "^1.
|
|
83
|
+
"json-storage-formatter": "^1.1.2"
|
|
84
84
|
}
|
|
85
85
|
}
|