react-hooks-global-states 8.1.0 → 8.2.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/GlobalStore.js CHANGED
@@ -1 +1 @@
1
- var t,e;t=this,e=(t,e,r,n,o,i,a,s,u,c)=>(()=>{"use strict";var l={109:e=>{e.exports=t},664:t=>{t.exports=e},682:t=>{t.exports=r},286:t=>{t.exports=n},865:t=>{t.exports=o},69:t=>{t.exports=i},122:t=>{t.exports=a},538:t=>{t.exports=s},582:t=>{t.exports=u},156:t=>{t.exports=c}},f={};function p(t){var e=f[t];if(void 0!==e)return e.exports;var r=f[t]={exports:{}};return l[t](r,r.exports,p),r.exports}var d={};return(()=>{var t=d;function e(t){return e="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},e(t)}function r(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,s=[],u=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);u=!0);}catch(t){c=!0,o=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return s}}(t,e)||n(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 n(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}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(){i=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),s=new C(n||[]);return o(a,"_invoke",{value:j(t,r,s)}),a}function p(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 h(){}function v(){}function b(){}var g={};l(g,s,(function(){return this}));var y=Object.getPrototypeOf,S=y&&y(y(k([])));S&&S!==r&&n.call(S,s)&&(g=S);var m=b.prototype=h.prototype=Object.create(g);function w(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,r){function i(o,a,s,u){var c=p(t[o],t,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==e(f)&&n.call(f,"__await")?r.resolve(f.__await).then((function(t){i("next",t,s,u)}),(function(t){i("throw",t,s,u)})):r.resolve(f).then((function(t){l.value=t,s(l)}),(function(t){return i("throw",t,s,u)}))}u(c.arg)}var a;o(this,"_invoke",{value:function(t,e){function n(){return new r((function(r,n){i(t,e,r,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 s=E(a,r);if(s){if(s===d)continue;return s}}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 u=p(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.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=p(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 _(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(_,this),this.reset(!0)}function k(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return v.prototype=b,o(m,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:v,configurable:!0}),v.displayName=l(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(O.prototype),l(O.prototype,u,(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(m),l(m,c,"Generator"),l(m,s,(function(){return this})),l(m,"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(x),!t)for(var e in this)"t"===e.charAt(0)&&n.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 r(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 r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,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:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function a(t){var r=function(t){if("object"!==e(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!==e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===e(r)?r:String(r)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var s=p(156),u=p(122),c=p(538),l=p(582),f=p(664),h=p(682),v=p(286),b=p(865),g=p(69),y=p(109),S=globalThis;!function(){if(!S.REACT_GLOBAL_STATE_HOOK_DEBUG&&!(0,c.isNil)(S.sessionStorage)){try{if(!S.sessionStorage.getItem("REACT_GLOBAL_STATE_HOOK_DEBUG"))return}catch(t){return}S.REACT_GLOBAL_STATE_TEMP_HOOKS=new Map,setTimeout((function(){S.REACT_GLOBAL_STATE_TEMP_HOOKS=null}),6e4)}}();var m=function(){function t(e){var o,p=this,d=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.wasDisposed=!1,this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Map,this.initialize=function(){return t=p,e=void 0,r=i().mark((function t(){var e,r,n,o,a,s;return i().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:{},a=o.onInit,n||a){t.next=6;break}return t.abrupt("return");case 6:s=this.getConfigCallbackParam(),null==n||n(s),(0,c.isNil)(a)||null==a||a(s);case 9:case"end":return t.stop()}}),t,this)})),new(e||(e=Promise))((function(n,o){function i(t){try{s(r.next(t))}catch(t){o(t)}}function a(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){var r;t.done?n(t.value):(r=t.value,r instanceof e?r:new e((function(t){t(r)}))).then(i,a)}s((r=r.apply(t,[])).next())}));var t,e,r},this.executeSetStateForSubscriber=function(t,e){var r,n,o=t.selector,i=t.callback,a=t.currentState,s=t.config;if(!e.forceUpdate&&(null!==(r=null==s?void 0:s.isEqualRoot)&&void 0!==r?r:function(t,e){return t===e})(e.currentRootState,e.newRootState))return{didUpdate:!1};var u=o?o(e.newRootState):e.newRootState;return!e.forceUpdate&&(null!==(n=null==s?void 0:s.isEqual)&&void 0!==n?n:function(t,e){return t===e})(a,u)?{didUpdate:!1}:(p.partialUpdateSubscription(t.subscriptionId,{currentState:u}),i({state:u},{identifier:e.identifier}),{didUpdate:!0})},this.setState=function(t,e){var r=t.state,o=e.forceUpdate,i=e.identifier,a=p.stateWrapper.state;if(o||a!==r){p.stateWrapper={state:r};var s,u={forceUpdate:o,newRootState:r,currentRootState:a,identifier:i},c=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=n(t))){e&&(t=e);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},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 i,a=!0,s=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==e.return||e.return()}finally{if(s)throw i}}}}(p.subscribers.values());try{for(c.s();!(s=c.n()).done;){var l=s.value;p.executeSetStateForSubscriber(l,u)}}catch(t){c.e(t)}finally{c.f()}}},this.setMetadata=function(t){var e=(0,u.isFunction)(t)?t(p.metadata):t;p.metadata=e},this.getMetadata=function(){return p.metadata},this.getState=function(t,e,r){var n;if(!t)return p.stateWrapper.state;var o=(0,u.isFunction)(e),i=o?t:void 0,a=o?e:t,s=null!==(n=o?r:e)&&void 0!==n?n:void 0,c=i?i(p.stateWrapper.state):p.stateWrapper.state;(null==s?void 0:s.skipFirst)||a(c);var l=(0,b.uniqueId)("gs:");return p.setOrUpdateSubscription({subscriptionId:l,selector:i,config:s,currentState:c,callback:function(t){var e=t.state;return a(e)},isSetStateCallback:!1}),function(){p.subscribers.delete(l)}},this.getConfigCallbackParam=function(){var t=p.setMetadata,e=p.getMetadata,r=p.getState,n=p.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:p.setStateWrapper,actions:n}},this.lastSubscriptionId=null,this.setOrUpdateSubscription=function(t){var e=t.subscriptionId;if(!e)return{isNewSubscription:!1};var r=p.subscribers.get(e);return(0,f.isRecord)(r)?(Object.assign(r,t),{isNewSubscription:!1}):(p.executeOnSubscribed(),p.subscribers.set(e,t),p.lastSubscriptionId=e,{isNewSubscription:!0})},this.partialUpdateSubscription=function(t,e){var r=p.subscribers.get(t);(0,f.isRecord)(r)&&Object.assign(r,e)},this.executeOnSubscribed=function(){var t,e=p.onSubscribed,r=null===(t=p.callbacks)||void 0===t?void 0:t.onSubscribed;if(e||r){var n=p.getConfigCallbackParam();null==e||e(n),null==r||r(n)}},this.getHook=function(){var t=function(t){var e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(p.wasDisposed)throw new Error("The global state was disposed");var i=Array.isArray(o)?{dependencies:o}:null!=o?o:{},a=(0,s.useRef)({subscriptionId:null,tempInitialRootState:p.stateWrapper.state}),u=function(){return t?{state:t(p.stateWrapper.state)}:p.stateWrapper},f=r((0,s.useState)(u),2),d=f[0],h=f[1];(0,s.useEffect)((function(){if(!(0,c.isNil)(a.current)){(0,c.isNil)(a.current.subscriptionId)&&(a.current.subscriptionId=(0,b.uniqueId)("ss:"));var e=a.current.subscriptionId,r={subscriptionId:e,currentState:d.state,selector:t,config:i,callback:h,isSetStateCallback:!0};return p.setOrUpdateSubscription(r).isNewSubscription&&(p.executeSetStateForSubscriber(r,{forceUpdate:!1,newRootState:p.stateWrapper.state,currentRootState:a.current.tempInitialRootState===g.uniqueSymbol?p.stateWrapper.state:a.current.tempInitialRootState,identifier:"on mount state update"}),a.current.tempInitialRootState=g.uniqueSymbol),function(){p.subscribers.delete(e)}}}),[]);var v=(0,l.isString)(null===(e=a.current)||void 0===e?void 0:e.subscriptionId)?a.current.subscriptionId:"",y=p.subscribers.get(v),S=(null!==(n=null==y?void 0:y.config)&&void 0!==n?n:{dependencies:i.dependencies}).dependencies;return p.partialUpdateSubscription(v,{currentState:d.state,selector:t,config:i,callback:h}),[p.computeSelectedState({selector:t,subscriptionId:v,config:i,currentDependencies:S,computeChildState:u,stateWrapperRef:d}),p.getStateOrchestrator(),p.metadata]};return t.stateControls=p.stateControls,t.createSelectorHook=p.createSelectorHook,t.createObservable=p.createObservable,t.removeSubscriptions=p.removeSubscriptions,t.dispose=p.dispose,t},this.computeSelectedState=function(t){var e=t.selector,r=t.subscriptionId,n=t.config,o=t.currentDependencies,i=t.computeChildState,a=t.stateWrapperRef;if(!e||!r)return a.state;var s=n.dependencies;if(o===s)return a.state;if((null==o?void 0:o.length)===(null==s?void 0:s.length)&&(0,h.shallowCompare)(o,s))return a.state;var u=i().state;return p.partialUpdateSubscription(r,{currentState:u}),a.state=u,u},this.createSelectorHook=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.isEqualRoot,i=n.isEqual,a=n.name,s=r(p.stateControls(),3),c=s[0],l=s[1],f=s[2],d=c(),h=(null!=e?e:function(t){return t})(d),v=new t(h,{name:null!=a?a:(0,b.uniqueId)("sh:")}),g=r(v.stateControls(),2),y=g[0],S=g[1],m=c((function(t){if(!(null!=o?o:Object.is)(d,t)){d=t;var r=e(t);(null!=i?i:Object.is)(h,r)||(h=r,S(r))}}),{skipFirst:!0}),w=v.getHook(),O=function(t,e){return[r((0,u.isFunction)(t)?w(t,e):w(),1)[0],l,f]};return O.stateControls=function(){return[y,l,f]},O.createSelectorHook=v.createSelectorHook,O.createObservable=p.createObservable.bind(O),O.removeSubscriptions=function(){m(),v.removeSubscriptions()},O.dispose=function(){O.removeSubscriptions(),v.dispose()},O},this.stateControls=function(){var t=p.getStateOrchestrator(),e=p.getMetadata;return[p.getState,t,e]},this.getStateOrchestrator=function(){return p.actions?p.actions:p.setStateWrapper},this.setStateWrapper=function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.forceUpdate,i=n.identifier,a=p.stateWrapper.state,s=(0,u.isFunction)(t)?t(a):t;if(o||p.stateWrapper.state!==s){var c=p.setMetadata,l=p.getMetadata,f=p.getState,d=p.actions,h={setMetadata:c,getMetadata:l,setState:p.setState,getState:f,actions:d,previousState:a,state:s,identifier:i},v=p.computePreventStateChange,b=null===(e=p.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((v||b)&&((null==v?void 0:v(h))||(null==b?void 0:b(h))))return;p.setState({state:s},{forceUpdate:o,identifier:i});var g=p.onStateChanged,y=null===(r=p.callbacks)||void 0===r?void 0:r.onStateChanged;(g||y)&&(null==g||g(h),null==y||y(h))}},this.getStoreActionsMap=function(){if(!(0,f.isRecord)(p.actionsConfig))return null;var t=p.actionsConfig,e=p.setMetadata,r=p.setStateWrapper,n=p.getState,o=p.getMetadata,i=Object.keys(t).reduce((function(s,u){var c,l,f;return Object.assign(s,(c={},f=function(){for(var a=t[u],s=arguments.length,c=new Array(s),l=0;l<s;l++)c[l]=arguments[l];var f=a.apply(i,c);return"function"!=typeof f&&(0,v.throwWrongKeyOnActionCollectionConfig)(u),f.call(i,{setState:r,getState:n,setMetadata:e,getMetadata:o,actions:i})},(l=a(l=u))in c?Object.defineProperty(c,l,{value:f,enumerable:!0,configurable:!0,writable:!0}):c[l]=f,c)),s}),{});return i},this.removeSubscriptions=function(){p.subscribers.clear()},this.dispose=function(){p.wasDisposed=!0,p.removeSubscriptions(),p._name="",p.actionsConfig=null,p.callbacks=null,p.metadata={},p.actions=null,p.subscribers.clear(),p.stateWrapper={state:null}};var m=d.metadata,w=d.callbacks,O=d.actions,j=d.name;this.stateWrapper={state:e},this._name=null!=j?j:(0,b.uniqueId)("gs:"),this.metadata=null!=m?m:{},this.callbacks=null!=w?w:null,this.actionsConfig=null!=O?O:null;var E="";if((S.REACT_GLOBAL_STATE_HOOK_DEBUG||S.REACT_GLOBAL_STATE_TEMP_HOOKS)&&(E=(0,y.generateStackHash)(null!==(o=(new Error).stack)&&void 0!==o?o:"")),S.REACT_GLOBAL_STATE_HOOK_DEBUG)S.REACT_GLOBAL_STATE_HOOK_DEBUG(this,d,E);else if(S.REACT_GLOBAL_STATE_TEMP_HOOKS){var _=void 0!==globalThis.WeakRef?new globalThis.WeakRef(this):this,x=void 0!==globalThis.WeakRef?new globalThis.WeakRef(d):d;S.REACT_GLOBAL_STATE_TEMP_HOOKS.set(E,[_,x])}this.constructor!==t||this.initialize()}var e,o;return e=t,o=[{key:"createObservable",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.isEqualRoot,o=e.isEqual,i=e.name,a=r(this.stateControls(),1)[0],s=[],c=a(),l=(null!=t?t:function(t){return t})(a()),f=a((function(e){if(!(null!=n?n:Object.is)(c,e)){c=e;var r=t(e);(null!=o?o:Object.is)(l,r)||(l=r,s.forEach((function(t){return t()})))}}),{skipFirst:!0}),p=function(t,e,r){var n;if(!t)return l;var o=(0,u.isFunction)(e),i=o?t:void 0,a=o?e:t,c=null!==(n=o?r:e)&&void 0!==n?n:void 0,f=function(){return a(i?i(l):l)};(null==c?void 0:c.skipFirst)||f();var p=function(){f()};return s.push(p),function(){s.splice(s.indexOf(p),1)}};return p._name=null!=i?i:(0,b.uniqueId)("ob:"),p.createObservable=this.createObservable.bind(p),p.removeSubscriptions=function(){s.forEach((function(t){return t()})),s.length=0,f()},p.stateControls=function(){return[p]},p}}],o&&function(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,a(n.key),n)}}(e.prototype,o),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.GlobalStore=m,t.default=m})(),d})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isString"),require("react")):"function"==typeof define&&define.amd?define(["./generateStackHash.js","./isRecord.js","./shallowCompare.js","./throwWrongKeyOnActionCollectionConfig.js","./uniqueId.js","./uniqueSymbol.js","json-storage-formatter/isFunction","json-storage-formatter/isNil","json-storage-formatter/isString","react"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isString"),require("react")):t["react-hooks-global-states"]=e(t["./generateStackHash.js"],t["./isRecord.js"],t["./shallowCompare.js"],t["./throwWrongKeyOnActionCollectionConfig.js"],t["./uniqueId.js"],t["./uniqueSymbol.js"],t["json-storage-formatter/isFunction"],t["json-storage-formatter/isNil"],t["json-storage-formatter/isString"],t.react);
1
+ var t,e;t=this,e=(t,e,r,n,o,i,a,s,u,c)=>(()=>{"use strict";var l={109:e=>{e.exports=t},664:t=>{t.exports=e},682:t=>{t.exports=r},286:t=>{t.exports=n},865:t=>{t.exports=o},69:t=>{t.exports=i},122:t=>{t.exports=a},538:t=>{t.exports=s},582:t=>{t.exports=u},156:t=>{t.exports=c}},f={};function p(t){var e=f[t];if(void 0!==e)return e.exports;var r=f[t]={exports:{}};return l[t](r,r.exports,p),r.exports}var d={};return(()=>{var t=d;function e(t){return e="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},e(t)}function r(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,s=[],u=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);u=!0);}catch(t){c=!0,o=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return s}}(t,e)||n(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 n(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}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(){i=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),s=new C(n||[]);return o(a,"_invoke",{value:j(t,r,s)}),a}function p(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 h(){}function v(){}function b(){}var g={};l(g,s,(function(){return this}));var y=Object.getPrototypeOf,S=y&&y(y(k([])));S&&S!==r&&n.call(S,s)&&(g=S);var m=b.prototype=h.prototype=Object.create(g);function w(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,r){function i(o,a,s,u){var c=p(t[o],t,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==e(f)&&n.call(f,"__await")?r.resolve(f.__await).then((function(t){i("next",t,s,u)}),(function(t){i("throw",t,s,u)})):r.resolve(f).then((function(t){l.value=t,s(l)}),(function(t){return i("throw",t,s,u)}))}u(c.arg)}var a;o(this,"_invoke",{value:function(t,e){function n(){return new r((function(r,n){i(t,e,r,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 s=E(a,r);if(s){if(s===d)continue;return s}}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 u=p(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.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=p(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 _(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(_,this),this.reset(!0)}function k(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return v.prototype=b,o(m,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:v,configurable:!0}),v.displayName=l(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(O.prototype),l(O.prototype,u,(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(m),l(m,c,"Generator"),l(m,s,(function(){return this})),l(m,"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(x),!t)for(var e in this)"t"===e.charAt(0)&&n.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 r(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 r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,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:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function a(t){var r=function(t){if("object"!==e(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!==e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===e(r)?r:String(r)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var s=p(156),u=p(122),c=p(538),l=p(582),f=p(664),h=p(682),v=p(286),b=p(865),g=p(69),y=p(109),S=globalThis;!function(){if(!S.REACT_GLOBAL_STATE_HOOK_DEBUG&&!(0,c.isNil)(S.sessionStorage)){try{if(!S.sessionStorage.getItem("REACT_GLOBAL_STATE_HOOK_DEBUG"))return}catch(t){return}S.REACT_GLOBAL_STATE_TEMP_HOOKS=new Map,setTimeout((function(){S.REACT_GLOBAL_STATE_TEMP_HOOKS=null}),6e4)}}();var m=function(){function t(e){var o,p=this,d=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.wasDisposed=!1,this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Map,this.initialize=function(){return t=p,e=void 0,r=i().mark((function t(){var e,r,n,o,a,s;return i().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:{},a=o.onInit,n||a){t.next=6;break}return t.abrupt("return");case 6:s=this.getConfigCallbackParam(),null==n||n(s),(0,c.isNil)(a)||null==a||a(s);case 9:case"end":return t.stop()}}),t,this)})),new(e||(e=Promise))((function(n,o){function i(t){try{s(r.next(t))}catch(t){o(t)}}function a(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){var r;t.done?n(t.value):(r=t.value,r instanceof e?r:new e((function(t){t(r)}))).then(i,a)}s((r=r.apply(t,[])).next())}));var t,e,r},this.executeSetStateForSubscriber=function(t,e){var r,n,o=t.selector,i=t.callback,a=t.currentState,s=t.config;if(!e.forceUpdate&&(null!==(r=null==s?void 0:s.isEqualRoot)&&void 0!==r?r:function(t,e){return t===e})(e.currentRootState,e.newRootState))return{didUpdate:!1};var u=o?o(e.newRootState):e.newRootState;return!e.forceUpdate&&(null!==(n=null==s?void 0:s.isEqual)&&void 0!==n?n:function(t,e){return t===e})(a,u)?{didUpdate:!1}:(p.partialUpdateSubscription(t.subscriptionId,{currentState:u}),i({state:u},{identifier:e.identifier}),{didUpdate:!0})},this.setState=function(t,e){var r=t.state,o=e.forceUpdate,i=e.identifier,a=p.stateWrapper.state;if(o||a!==r){p.stateWrapper={state:r};var s,u={forceUpdate:o,newRootState:r,currentRootState:a,identifier:i},c=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=n(t))){e&&(t=e);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},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 i,a=!0,s=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==e.return||e.return()}finally{if(s)throw i}}}}(p.subscribers.values());try{for(c.s();!(s=c.n()).done;){var l=s.value;p.executeSetStateForSubscriber(l,u)}}catch(t){c.e(t)}finally{c.f()}}},this.setMetadata=function(t){var e=(0,u.isFunction)(t)?t(p.metadata):t;p.metadata=e},this.getMetadata=function(){return p.metadata},this.getState=function(t,e,r){var n;if(!t)return p.stateWrapper.state;var o=(0,u.isFunction)(e),i=o?t:void 0,a=o?e:t,s=null!==(n=o?r:e)&&void 0!==n?n:void 0,c=i?i(p.stateWrapper.state):p.stateWrapper.state;(null==s?void 0:s.skipFirst)||a(c);var l=(0,b.uniqueId)("gs:");return p.setOrUpdateSubscription({subscriptionId:l,selector:i,config:s,currentState:c,callback:function(t){var e=t.state;return a(e)},isSetStateCallback:!1}),function(){p.subscribers.delete(l)}},this.getConfigCallbackParam=function(){var t=p.setMetadata,e=p.getMetadata,r=p.getState,n=p.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:p.setStateWrapper,actions:n}},this.lastSubscriptionId=null,this.setOrUpdateSubscription=function(t){var e=t.subscriptionId;if(!e)return{isNewSubscription:!1};var r=p.subscribers.get(e);return(0,f.isRecord)(r)?(Object.assign(r,t),{isNewSubscription:!1}):(p.executeOnSubscribed(),p.subscribers.set(e,t),p.lastSubscriptionId=e,{isNewSubscription:!0})},this.partialUpdateSubscription=function(t,e){var r=p.subscribers.get(t);(0,f.isRecord)(r)&&Object.assign(r,e)},this.executeOnSubscribed=function(){var t,e=p.onSubscribed,r=null===(t=p.callbacks)||void 0===t?void 0:t.onSubscribed;if(e||r){var n=p.getConfigCallbackParam();null==e||e(n),null==r||r(n)}},this.getHook=function(){var t=function(t){var e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(p.wasDisposed)throw new Error("The global state was disposed");var i=Array.isArray(o)?{dependencies:o}:null!=o?o:{},a=(0,s.useRef)({subscriptionId:null,tempInitialRootState:p.stateWrapper.state}),u=function(){return t?{state:t(p.stateWrapper.state)}:p.stateWrapper},f=r((0,s.useState)(u),2),d=f[0],h=f[1];(0,s.useEffect)((function(){if(!(0,c.isNil)(a.current)){(0,c.isNil)(a.current.subscriptionId)&&(a.current.subscriptionId=(0,b.uniqueId)("ss:"));var e=a.current.subscriptionId,r={subscriptionId:e,currentState:d.state,selector:t,config:i,callback:h,isSetStateCallback:!0};return p.setOrUpdateSubscription(r).isNewSubscription&&(p.executeSetStateForSubscriber(r,{forceUpdate:!1,newRootState:p.stateWrapper.state,currentRootState:a.current.tempInitialRootState===g.uniqueSymbol?p.stateWrapper.state:a.current.tempInitialRootState,identifier:"on mount state update"}),a.current.tempInitialRootState=g.uniqueSymbol),function(){p.subscribers.delete(e)}}}),[]);var v=(0,l.isString)(null===(e=a.current)||void 0===e?void 0:e.subscriptionId)?a.current.subscriptionId:"",y=p.subscribers.get(v),S=(null!==(n=null==y?void 0:y.config)&&void 0!==n?n:{dependencies:i.dependencies}).dependencies;return p.partialUpdateSubscription(v,{currentState:d.state,selector:t,config:i,callback:h}),[p.computeSelectedState({selector:t,subscriptionId:v,config:i,currentDependencies:S,computeChildState:u,stateWrapperRef:d}),p.getStateOrchestrator(),p.metadata]};return t.stateControls=p.stateControls,t.createSelectorHook=p.createSelectorHook,t.createObservable=p.createObservable,t.removeSubscriptions=p.removeSubscriptions,t.dispose=p.dispose,t},this.computeSelectedState=function(t){var e=t.selector,r=t.subscriptionId,n=t.config,o=t.currentDependencies,i=t.computeChildState,a=t.stateWrapperRef;if(!e||!r)return a.state;var s=n.dependencies;if(o===s)return a.state;if((null==o?void 0:o.length)===(null==s?void 0:s.length)&&(0,h.shallowCompare)(o,s))return a.state;var u=i().state;return p.partialUpdateSubscription(r,{currentState:u}),a.state=u,u},this.createSelectorHook=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.isEqualRoot,i=n.isEqual,a=n.name,s=r(p.stateControls(),3),c=s[0],l=s[1],f=s[2],d=c(),h=(null!=e?e:function(t){return t})(d),v=new t(h,{name:null!=a?a:(0,b.uniqueId)("sh:")}),g=r(v.stateControls(),2),y=g[0],S=g[1],m=c((function(t){if(!(null!=o?o:Object.is)(d,t)){d=t;var r=e(t);(null!=i?i:Object.is)(h,r)||(h=r,S(r))}}),{skipFirst:!0}),w=v.getHook(),O=function(t,e){return[r((0,u.isFunction)(t)?w(t,e):w(),1)[0],l,f]};return O.stateControls=function(){return[y,l,f]},O.createSelectorHook=v.createSelectorHook,O.createObservable=p.createObservable.bind(O),O.removeSubscriptions=function(){m(),v.removeSubscriptions()},O.dispose=function(){O.removeSubscriptions(),v.dispose()},O},this.stateControls=function(){var t=p.getStateOrchestrator(),e=p.getMetadata;return[p.getState,t,e]},this.getStateOrchestrator=function(){return p.actions?p.actions:p.setStateWrapper},this.setStateWrapper=function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.forceUpdate,i=n.identifier,a=p.stateWrapper.state,s=(0,u.isFunction)(t)?t(a):t;if(o||p.stateWrapper.state!==s){var c=p.setMetadata,l=p.getMetadata,f=p.getState,d=p.actions,h={setMetadata:c,getMetadata:l,setState:p.setState,getState:f,actions:d,previousState:a,state:s,identifier:i},v=p.computePreventStateChange,b=null===(e=p.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((v||b)&&((null==v?void 0:v(h))||(null==b?void 0:b(h))))return;p.setState({state:s},{forceUpdate:o,identifier:i});var g=p.onStateChanged,y=null===(r=p.callbacks)||void 0===r?void 0:r.onStateChanged;(g||y)&&(null==g||g(h),null==y||y(h))}},this.getStoreActionsMap=function(){if(!(0,f.isRecord)(p.actionsConfig))return null;var t=p.actionsConfig,e=p.setMetadata,r=p.setStateWrapper,n=p.getState,o=p.getMetadata,i=Object.keys(t).reduce((function(s,u){var c,l,f;return Object.assign(s,(c={},f=function(){for(var a=t[u],s=arguments.length,c=new Array(s),l=0;l<s;l++)c[l]=arguments[l];var f=a.apply(i,c);return"function"!=typeof f&&(0,v.throwWrongKeyOnActionCollectionConfig)(u),f.call(i,{setState:r,getState:n,setMetadata:e,getMetadata:o,actions:i})},(l=a(l=u))in c?Object.defineProperty(c,l,{value:f,enumerable:!0,configurable:!0,writable:!0}):c[l]=f,c)),s}),{});return i},this.removeSubscriptions=function(){p.subscribers.clear()},this.dispose=function(){p.wasDisposed=!0,p.removeSubscriptions(),p._name="",p.actionsConfig=null,p.callbacks=null,p.metadata={},p.actions=null,p.stateWrapper={state:null}};var m=d.metadata,w=d.callbacks,O=d.actions,j=d.name;this.stateWrapper={state:e},this._name=null!=j?j:(0,b.uniqueId)("gs:"),this.metadata=null!=m?m:{},this.callbacks=null!=w?w:null,this.actionsConfig=null!=O?O:null;var E="";if((S.REACT_GLOBAL_STATE_HOOK_DEBUG||S.REACT_GLOBAL_STATE_TEMP_HOOKS)&&(E=(0,y.generateStackHash)(null!==(o=(new Error).stack)&&void 0!==o?o:"")),S.REACT_GLOBAL_STATE_HOOK_DEBUG)S.REACT_GLOBAL_STATE_HOOK_DEBUG(this,d,E);else if(S.REACT_GLOBAL_STATE_TEMP_HOOKS){var _=void 0!==globalThis.WeakRef?new globalThis.WeakRef(this):this,x=void 0!==globalThis.WeakRef?new globalThis.WeakRef(d):d;S.REACT_GLOBAL_STATE_TEMP_HOOKS.set(E,[_,x])}this.constructor!==t||this.initialize()}var e,o;return e=t,o=[{key:"createObservable",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.isEqualRoot,o=e.isEqual,i=e.name,a=r(this.stateControls(),1)[0],s=[],c=a(),l=(null!=t?t:function(t){return t})(a()),f=a((function(e){if(!(null!=n?n:Object.is)(c,e)){c=e;var r=t(e);(null!=o?o:Object.is)(l,r)||(l=r,s.forEach((function(t){return t()})))}}),{skipFirst:!0}),p=function(t,e,r){var n;if(!t)return l;var o=(0,u.isFunction)(e),i=o?t:void 0,a=o?e:t,c=null!==(n=o?r:e)&&void 0!==n?n:void 0,f=function(){return a(i?i(l):l)};(null==c?void 0:c.skipFirst)||f();var p=function(){f()};return s.push(p),function(){s.splice(s.indexOf(p),1)}};return p._name=null!=i?i:(0,b.uniqueId)("ob:"),p.createObservable=this.createObservable.bind(p),p.removeSubscriptions=function(){s.forEach((function(t){return t()})),s.length=0,f()},p.stateControls=function(){return[p]},p}}],o&&function(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,a(n.key),n)}}(e.prototype,o),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.GlobalStore=m,t.default=m})(),d})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isString"),require("react")):"function"==typeof define&&define.amd?define(["./generateStackHash.js","./isRecord.js","./shallowCompare.js","./throwWrongKeyOnActionCollectionConfig.js","./uniqueId.js","./uniqueSymbol.js","json-storage-formatter/isFunction","json-storage-formatter/isNil","json-storage-formatter/isString","react"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isString"),require("react")):t["react-hooks-global-states"]=e(t["./generateStackHash.js"],t["./isRecord.js"],t["./shallowCompare.js"],t["./throwWrongKeyOnActionCollectionConfig.js"],t["./uniqueId.js"],t["./uniqueSymbol.js"],t["json-storage-formatter/isFunction"],t["json-storage-formatter/isNil"],t["json-storage-formatter/isString"],t.react);
package/createContext.js CHANGED
@@ -1 +1 @@
1
- var t,e;t=this,e=(t,e,r,o,n)=>(()=>{"use strict";var a={564:(t,e,r)=>{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 o,n,a,i,u=[],s=!0,l=!1;try{if(a=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(o=a.call(r)).done)&&(u.push(o.value),u.length!==e);s=!0);}catch(t){l=!0,n=t}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(l)throw n}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(t,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 n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}Object.defineProperty(e,"__esModule",{value:!0}),e.createContext=void 0;var a=r(156),i=r(352),u=r(122),s=r(538),l=r(503);e.createContext=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(0,a.createContext)(null),n=function(){var t=(0,a.useContext)(r);if(!t)throw new Error("ContextHook must be used within a ContextProvider");return t()};n.createSelectorHook=function(t,e){return function(){var n=(0,a.useContext)(r);if((0,s.isNil)(n))throw new Error("SelectorHook must be used within a ContextProvider");return o((0,l.useStableState)((function(){var r=n.createSelectorHook(t,e);return[r,function(){return r.dispose()}]}),[n]),1)[0].current.apply(void 0,arguments)}};var c=function(){var t=(0,a.useContext)(r);if((0,s.isNil)(t))throw new Error("useStateControls must be used within a ContextProvider");return t.stateControls()},f=function(t,e){var o=(0,a.useContext)(r);if((0,s.isNil)(o))throw new Error("useObservableBuilder must be used within a ContextProvider");return o.createObservable(t,e)};return n.stateControls=function(){return[c,f]},[n,function(n){var c=n.children,f=n.value,d=n.ref,v=(0,l.useStableState)((function(){var r,o=function(){return(0,u.isFunction)(t)?t():t},n=(0,s.isNil)(f)?o():(0,u.isFunction)(f)?f(o()):f,a=new i.GlobalStore(n,Object.assign(Object.assign({},e),{metadata:null!==(r=(0,u.isFunction)(e.metadata)?e.metadata():e.metadata)&&void 0!==r?r:{}})),l=a.getHook();return[{store:a,parentHook:l},function(){var t,e,r,o;null===(e=null===(t=a.callbacks)||void 0===t?void 0:t.onUnMount)||void 0===e||e.call(t),null===(o=(r=a).__onUnMountContext)||void 0===o||o.call(r,a,l),a.dispose()}]}),[]),b=o(v,1)[0].current;return(0,a.useImperativeHandle)(d,(function(){return d?b.store.getConfigCallbackParam():{}}),[b.store,d]),(0,a.createElement)(r.Provider,{value:b.parentHook},c)}]},e.default=e.createContext},352:e=>{e.exports=t},503:t=>{t.exports=e},122:t=>{t.exports=r},538:t=>{t.exports=o},156:t=>{t.exports=n}},i={};return function t(e){var r=i[e];if(void 0!==r)return r.exports;var o=i[e]={exports:{}};return a[e](o,o.exports,t),o.exports}(564)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./GlobalStore.js"),require("./useStableState.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("react")):"function"==typeof define&&define.amd?define(["./GlobalStore.js","./useStableState.js","json-storage-formatter/isFunction","json-storage-formatter/isNil","react"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./GlobalStore.js"),require("./useStableState.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("react")):t["react-hooks-global-states"]=e(t["./GlobalStore.js"],t["./useStableState.js"],t["json-storage-formatter/isFunction"],t["json-storage-formatter/isNil"],t.react);
1
+ var e,t;e=this,t=(e,t,r,o,n)=>(()=>{"use strict";var a={564:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createContext=void 0;var o=r(156),n=r(352),a=r(122),i=r(538),s=r(503);t.createContext=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(0,o.createContext)(null),u=function(){var e=(0,o.useContext)(r);if(!e)throw new Error("ContextHook must be used within a ContextProvider");return e()};u.createSelectorHook=function(e,t){var n=null;return function(){var a=(0,o.useContext)(r);if((0,i.isNil)(a))throw new Error("SelectorHook must be used within a ContextProvider");var s=(0,o.useRef)(!1);return(0,i.isNil)(n)&&(n=a.createSelectorHook(e,t)),(0,o.useEffect)((function(){if(s.current)return function(){null==n||n.dispose(),n=null};s.current=!0}),[]),n.apply(void 0,arguments)}};var l=function(){var e=(0,o.useContext)(r);if((0,i.isNil)(e))throw new Error("useStateControls must be used within a ContextProvider");return e.stateControls()},c=function(e,t){var n=(0,o.useContext)(r);if((0,i.isNil)(n))throw new Error("useObservableBuilder must be used within a ContextProvider");return n.createObservable(e,t)};return u.stateControls=function(){return[l,c]},[u,function(u){var l=u.children,c=u.value,f=u.ref,v=(0,s.useStableState)((function(){var r,o=function(){return(0,a.isFunction)(e)?e():e},s=(0,i.isNil)(c)?o():(0,a.isFunction)(c)?c(o()):c,u=new n.GlobalStore(s,Object.assign(Object.assign({},t),{metadata:null!==(r=(0,a.isFunction)(t.metadata)?t.metadata():t.metadata)&&void 0!==r?r:{}})),l=u.getHook();return[{store:u,parentHook:l},function(){var e,t,r,o;null===(t=null===(e=u.callbacks)||void 0===e?void 0:e.onUnMount)||void 0===t||t.call(e),null===(o=(r=u).__onUnMountContext)||void 0===o||o.call(r,u,l),u.dispose()}]}),[]);if((0,o.useImperativeHandle)(f,(function(){var e;return f?null!==(e=null==v?void 0:v.current.store.getConfigCallbackParam())&&void 0!==e?e:null:{}}),[f,v]),(0,i.isNil)(v))return null;var d=v.current.parentHook;return(0,o.createElement)(r.Provider,{value:d},l)}]},t.default=t.createContext},352:t=>{t.exports=e},503:e=>{e.exports=t},122:e=>{e.exports=r},538:e=>{e.exports=o},156:e=>{e.exports=n}},i={};return function e(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return a[t](o,o.exports,e),o.exports}(564)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./GlobalStore.js"),require("./useStableState.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("react")):"function"==typeof define&&define.amd?define(["./GlobalStore.js","./useStableState.js","json-storage-formatter/isFunction","json-storage-formatter/isNil","react"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("./GlobalStore.js"),require("./useStableState.js"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("react")):e["react-hooks-global-states"]=t(e["./GlobalStore.js"],e["./useStableState.js"],e["json-storage-formatter/isFunction"],e["json-storage-formatter/isNil"],e.react);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "This is a package to easily handling global-state across your react-components using hooks.",
5
5
  "main": "./bundle.js",
6
6
  "types": "./index.d.ts",
@@ -1,8 +1,13 @@
1
- type StateBuilder<T> = () => [state: T, cleanup?: CleanupArg];
1
+ type Cleanup = () => void;
2
+ type StateBuilder<T> = () => [state: T, cleanup?: Cleanup];
2
3
  type RefObject<T> = {
3
4
  current: T;
4
5
  };
5
- type Recompute = () => void;
6
- type CleanupArg = (() => void) | null;
7
- export declare const useStableState: <T>(builder: StateBuilder<T>, dependencies?: unknown[]) => [ref: RefObject<T>, recompute: Recompute];
6
+ /**
7
+ * - Only one stable initial render
8
+ * - Only one stable cleanup every time dependencies change
9
+ * - Initial render doesn't trigger cleanup
10
+ * - Starts cold, returns null until the first render or fallback if provided
11
+ */
12
+ export declare const useStableState: <T, F extends T>(builder: StateBuilder<T>, dependencies: unknown[], fallbackArg?: F | undefined) => F extends T ? RefObject<T> : RefObject<T> | null;
8
13
  export default useStableState;
package/useStableState.js CHANGED
@@ -1 +1 @@
1
- var e,r;e=this,r=(e,r,t)=>(()=>{"use strict";var n={965:(e,r,t)=>{function n(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,u,a,l=[],i=!0,c=!1;try{if(u=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;i=!1}else for(;!(i=(n=u.call(t)).done)&&(l.push(n.value),l.length!==r);i=!0);}catch(e){c=!0,o=e}finally{try{if(!i&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,r)||function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e,r)||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(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}Object.defineProperty(r,"__esModule",{value:!0}),r.useStableState=void 0;var u=t(156),a=t(538),l=t(682),i=t(156),c=t(156);r.useStableState=function(e,r){var t,o,s=(0,u.useRef)({refObject:null,builder:null,cleanup:null,dependencies:r});s.current.builder=function(){var r=n(e(),2),t=r[0],o=r[1],u=void 0===o?null:o;return s.current.cleanup=u,{current:t}},t=(0,a.isNil)(s.current.refObject),o=(0,a.isNil)(r),(t||o||!(0,l.shallowCompare)(s.current.dependencies,r))&&(s.current.refObject=s.current.builder()),s.current.dependencies=r;var f=n((0,i.useState)(!0),2)[1],p=(0,c.useCallback)((function(){s.current.refObject=s.current.builder(),f((function(e){return!e}))}),[]);return(0,u.useEffect)((function(){var e=s.current.cleanup;if(e){var r=s.current.refObject;return function(){r!==s.current.refObject&&e()}}}),[s.current.refObject]),[s.current.refObject,p]},r.default=r.useStableState},682:r=>{r.exports=e},538:e=>{e.exports=r},156:e=>{e.exports=t}},o={};return function e(r){var t=o[r];if(void 0!==t)return t.exports;var u=o[r]={exports:{}};return n[r](u,u.exports,e),u.exports}(965)})(),"object"==typeof exports&&"object"==typeof module?module.exports=r(require("./shallowCompare.js"),require("json-storage-formatter/isNil"),require("react")):"function"==typeof define&&define.amd?define(["./shallowCompare.js","json-storage-formatter/isNil","react"],r):"object"==typeof exports?exports["react-hooks-global-states"]=r(require("./shallowCompare.js"),require("json-storage-formatter/isNil"),require("react")):e["react-hooks-global-states"]=r(e["./shallowCompare.js"],e["json-storage-formatter/isNil"],e.react);
1
+ var t;t=t=>(()=>{"use strict";var e={965:(t,e,r)=>{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,a,u,l=[],i=!0,c=!1;try{if(a=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;i=!1}else for(;!(i=(n=a.call(r)).done)&&(l.push(n.value),l.length!==e);i=!0);}catch(t){c=!0,o=t}finally{try{if(!i&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return l}}(t,e)||o(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){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}Object.defineProperty(e,"__esModule",{value:!0}),e.useStableState=void 0;var u=r(156);e.useStableState=function(t,e,r){var l,i,c=n((0,u.useState)({}),2)[1],f=(0,u.useCallback)((function(){c({})}),[]),s=(0,u.useRef)({builder:t,stateRef:null,fallback:r?{current:r}:void 0,isMounted:!1});s.current.builder=t,(0,u.useEffect)((function(){var t=n((0,s.current.builder)(),2),e=t[0],r=t[1];if(s.current.stateRef={current:e},f(),s.current.isMounted)return function(){null==r||r()};s.current.isMounted=!0}),[f].concat(function(t){if(Array.isArray(t))return a(t)}(i=e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(i)||o(i)||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.")}()));var d=s.current,b=d.stateRef,y=d.fallback;return null!==(l=null!=b?b:y)&&void 0!==l?l:null},e.default=e.useStableState},156:e=>{e.exports=t}},r={};return function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n](a,a.exports,t),a.exports}(965)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("react")):this["react-hooks-global-states"]=t(this.react);