react-hooks-global-states 8.2.2 → 8.2.4

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.d.ts CHANGED
@@ -41,8 +41,8 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata | unknown,
41
41
  protected setState: ({ state: newRootState, }: {
42
42
  state: State;
43
43
  }, { forceUpdate, identifier }: {
44
- forceUpdate?: boolean | undefined;
45
- identifier?: string | undefined;
44
+ forceUpdate?: boolean;
45
+ identifier?: string;
46
46
  }) => void;
47
47
  /**
48
48
  * Set the value of the metadata property, this is no reactive and will not trigger a re-render
@@ -83,10 +83,10 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata | unknown,
83
83
  * @description
84
84
  * Use this function to create a custom global hook which contains a fragment of the state of another hook
85
85
  */
86
- createSelectorHook: <RootState, StateMutator, Metadata_1 extends BaseMetadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector: (state: RootState) => RootSelectorResult, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
87
- isEqual?: ((current: RootDerivate, next: RootDerivate) => boolean) | undefined;
88
- isEqualRoot?: ((current: RootState, next: RootState) => boolean) | undefined;
89
- name?: string | undefined;
86
+ createSelectorHook: <RootState, StateMutator, Metadata extends BaseMetadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector: (state: RootState) => RootSelectorResult, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
87
+ isEqual?: (current: RootDerivate, next: RootDerivate) => boolean;
88
+ isEqualRoot?: (current: RootState, next: RootState) => boolean;
89
+ name?: string;
90
90
  }) => StateHook<RootDerivate, StateMutator, Metadata_1>;
91
91
  stateControls: () => [retriever: StateGetter<State>, mutator: PublicStateMutator, metadata: MetadataGetter<Metadata>];
92
92
  /**
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.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={45:e=>{e.exports=t},78:t=>{t.exports=e},155:t=>{t.exports=r},187:t=>{t.exports=n},293:t=>{t.exports=o},361:t=>{t.exports=i},487:t=>{t.exports=a},506:t=>{t.exports=s},673:t=>{t.exports=u},773: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={}.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=Array(e);r<e;r++)n[r]=t[r];return n}function i(){i=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},s="function"==typeof Symbol?Symbol:{},u=s.iterator||"@@iterator",c=s.asyncIterator||"@@asyncIterator",l=s.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function p(t,e,r,n){var o=e&&e.prototype instanceof S?e:S,i=Object.create(o.prototype),s=new q(n||[]);return a(i,"_invoke",{value:x(t,r,s)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=p;var h="suspendedStart",v="suspendedYield",b="executing",g="completed",y={};function S(){}function m(){}function w(){}var O={};f(O,u,(function(){return this}));var j=Object.getPrototypeOf,E=j&&j(j(R([])));E&&E!==n&&o.call(E,u)&&(O=E);var _=w.prototype=S.prototype=Object.create(O);function C(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,r){function n(i,a,s,u){var c=d(t[i],t,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==e(f)&&o.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,s,u)}),(function(t){n("throw",t,s,u)})):r.resolve(f).then((function(t){l.value=t,s(l)}),(function(t){return n("throw",t,s,u)}))}u(c.arg)}var i;a(this,"_invoke",{value:function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return i=i?i.then(o,o):o()}})}function x(e,r,n){var o=h;return function(i,a){if(o===b)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var u=T(s,n);if(u){if(u===y)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=b;var c=d(e,r,n);if("normal"===c.type){if(o=n.done?g:v,c.arg===y)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=g,n.method="throw",n.arg=c.arg)}}}function T(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,T(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=d(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function A(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 L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function q(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function R(r){if(r||""===r){var n=r[u];if(n)return n.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,a=function e(){for(;++i<r.length;)if(o.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return a.next=a}}throw new TypeError(e(r)+" is not iterable")}return m.prototype=w,a(_,"constructor",{value:w,configurable:!0}),a(w,"constructor",{value:m,configurable:!0}),m.displayName=f(w,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,f(t,l,"GeneratorFunction")),t.prototype=Object.create(_),t},r.awrap=function(t){return{__await:t}},C(k.prototype),f(k.prototype,c,(function(){return this})),r.AsyncIterator=k,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new k(p(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},C(_),f(_,l,"Generator"),f(_,u,(function(){return this})),f(_,"toString",(function(){return"[object Generator]"})),r.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}},r.values=R,q.prototype={constructor:q,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(L),!e)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return s.type="throw",s.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),c=o.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;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,y):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),y},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),L(r),y}},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;L(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:R(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function a(t){var r=function(t){if("object"!=e(t)||!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:r+""}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var s=p(155),u=p(506),c=p(773),l=p(187),f=p(487),h=p(673),v=p(361),b=p(78),g=p(293),y=p(45),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(){return t=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,C=void 0!==globalThis.WeakRef?new globalThis.WeakRef(d):d;S.REACT_GLOBAL_STATE_TEMP_HOOKS.set(E,[_,C])}this.constructor!==t||this.initialize()},e=[{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}}],e&&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)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();t.GlobalStore=m,t.default=m})(),d})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./generateStackHash.js"),require("./uniqueId.js"),require("react"),require("json-storage-formatter/isString"),require("./uniqueSymbol.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./isRecord.js"),require("json-storage-formatter/isFunction"),require("./shallowCompare.js"),require("json-storage-formatter/isNil")):"function"==typeof define&&define.amd?define(["./generateStackHash.js","./uniqueId.js","react","json-storage-formatter/isString","./uniqueSymbol.js","./throwWrongKeyOnActionCollectionConfig.js","./isRecord.js","json-storage-formatter/isFunction","./shallowCompare.js","json-storage-formatter/isNil"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./generateStackHash.js"),require("./uniqueId.js"),require("react"),require("json-storage-formatter/isString"),require("./uniqueSymbol.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./isRecord.js"),require("json-storage-formatter/isFunction"),require("./shallowCompare.js"),require("json-storage-formatter/isNil")):t["react-hooks-global-states"]=e(t["./generateStackHash.js"],t["./uniqueId.js"],t.react,t["json-storage-formatter/isString"],t["./uniqueSymbol.js"],t["./throwWrongKeyOnActionCollectionConfig.js"],t["./isRecord.js"],t["json-storage-formatter/isFunction"],t["./shallowCompare.js"],t["json-storage-formatter/isNil"]);
@@ -1 +1 @@
1
- var t;t=t=>(()=>{"use strict";var e={352:e=>{e.exports=t}},o={};function r(t){var n=o[t];if(void 0!==n)return n.exports;var i=o[t]={exports:{}};return e[t](i,i.exports,r),i.exports}var n={};return(()=>{var t=n;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 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(t,"__esModule",{value:!0}),t.GlobalStoreAbstract=void 0;var c=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)}(f,t);var r,n,c,u=(n=f,c=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,o=i(n);if(c){var r=i(this).constructor;t=Reflect.construct(o,arguments,r)}else t=o.apply(this,arguments);return function(t,o){if(o&&("object"===e(o)||"function"==typeof o))return o;if(void 0!==o)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 f(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,f),(t=u.apply(this,arguments)).onInit=function(e){t.onInitialize(e)},t.onStateChanged=function(e){t.onChange(e)},t}return r=f,Object.defineProperty(r,"prototype",{writable:!1}),r}(r(352).GlobalStore);t.GlobalStoreAbstract=c,t.default=c})(),n})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("./GlobalStore.js")):this["react-hooks-global-states"]=t(this["./GlobalStore.js"]);
1
+ var t;t=t=>(()=>{"use strict";var e={778:e=>{e.exports=t}},o={};function r(t){var n=o[t];if(void 0!==n)return n.exports;var i=o[t]={exports:{}};return e[t](i,i.exports,r),i.exports}var n={};return(()=>{var t=n;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 o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStoreAbstract=void 0;var u=function(t){function r(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(t=function(t,r,n){return r=i(r),function(t,o){if(o&&("object"==e(o)||"function"==typeof o))return o;if(void 0!==o)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)}(t,o()?Reflect.construct(r,n||[],i(t).constructor):r.apply(t,n))}(this,r,arguments)).onInit=function(e){t.onInitialize(e)},t.onStateChanged=function(e){t.onChange(e)},t}return 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&&c(t,e)}(r,t),n=r,Object.defineProperty(n,"prototype",{writable:!1}),n;var n}(r(778).GlobalStore);t.GlobalStoreAbstract=u,t.default=u})(),n})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("./GlobalStore.js")):this["react-hooks-global-states"]=t(this["./GlobalStore.js"]);
package/README.md CHANGED
@@ -19,6 +19,26 @@ Works seamlessly with **React & React Native**:
19
19
 
20
20
  ---
21
21
 
22
+ ## 🚀 React Hooks Global States - DevTools Extension
23
+
24
+ React Hooks Global States includes a dedicated, `devTools extension` to streamline your development workflow! Easily visualize, inspect, debug, and modify your application's global state in real-time right within your browser.
25
+
26
+ ### 🔗 [Install the DevTools Extension for Chrome](https://chromewebstore.google.com/detail/bafojplmkpejhglhjpibpdhoblickpee/preview?hl=en&authuser=0)
27
+
28
+ ### 📸 DevTools Highlights
29
+
30
+ | **Track State Changes** | **Modify the State** |
31
+ | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
32
+ | ![Track State Changes](https://github.com/johnny-quesada-developer/react-hooks-global-states/raw/main/public/track-state-changes.png) | ![Modify the State](https://github.com/johnny-quesada-developer/react-hooks-global-states/raw/main/public/modify-the-state.png) |
33
+ | Effortlessly monitor state updates and history. | Instantly edit global states directly from the extension. |
34
+
35
+ ---
36
+
37
+ | **Restore the State** | **Custom Actions Granularity** |
38
+ | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
39
+ | ![Restore the State](https://github.com/johnny-quesada-developer/react-hooks-global-states/raw/main/public/restore-the-state.png) | ![Custom Actions Granularity](https://github.com/johnny-quesada-developer/react-hooks-global-states/raw/main/public/custom-actions-granularity.png) |
40
+ | Quickly revert your application to a previous state. | Precisely debug specific actions affecting state changes. |
41
+
22
42
  ## 🛠 Creating a Global State
23
43
 
24
44
  Define a **global state** in **one line**:
package/bundle.js CHANGED
@@ -1 +1 @@
1
- var e,t;e=this,t=(e,t,r,o,a,n,s,l,u,i,c,b)=>(()=>{"use strict";var j={352:t=>{t.exports=e},674:e=>{e.exports=t},104:e=>{e.exports=r},842:e=>{e.exports=o},963:e=>{e.exports=a},109:e=>{e.exports=n},664:e=>{e.exports=s},682:e=>{e.exports=l},286:e=>{e.exports=u},865:e=>{e.exports=i},69:e=>{e.exports=c},503:e=>{e.exports=b}},S={};function p(e){var t=S[e];if(void 0!==t)return t.exports;var r=S[e]={exports:{}};return j[e](r,r.exports,p),r.exports}var f={};return(()=>{var e=f;Object.defineProperty(e,"__esModule",{value:!0}),e.generateStackHash=e.createContext=e.useStableState=e.uniqueSymbol=e.isRecord=e.throwWrongKeyOnActionCollectionConfig=e.uniqueId=e.shallowCompare=e.createCustomGlobalState=e.createGlobalState=e.GlobalStoreAbstract=e.GlobalStore=void 0;var t=p(352);Object.defineProperty(e,"GlobalStore",{enumerable:!0,get:function(){return t.GlobalStore}});var r=p(674);Object.defineProperty(e,"GlobalStoreAbstract",{enumerable:!0,get:function(){return r.GlobalStoreAbstract}});var o=p(963);Object.defineProperty(e,"createGlobalState",{enumerable:!0,get:function(){return o.createGlobalState}});var a=p(842);Object.defineProperty(e,"createCustomGlobalState",{enumerable:!0,get:function(){return a.createCustomGlobalState}});var n=p(682);Object.defineProperty(e,"shallowCompare",{enumerable:!0,get:function(){return n.shallowCompare}});var s=p(865);Object.defineProperty(e,"uniqueId",{enumerable:!0,get:function(){return s.uniqueId}});var l=p(286);Object.defineProperty(e,"throwWrongKeyOnActionCollectionConfig",{enumerable:!0,get:function(){return l.throwWrongKeyOnActionCollectionConfig}});var u=p(664);Object.defineProperty(e,"isRecord",{enumerable:!0,get:function(){return u.isRecord}});var i=p(69);Object.defineProperty(e,"uniqueSymbol",{enumerable:!0,get:function(){return i.uniqueSymbol}});var c=p(503);Object.defineProperty(e,"useStableState",{enumerable:!0,get:function(){return c.useStableState}});var b=p(104);Object.defineProperty(e,"createContext",{enumerable:!0,get:function(){return b.createContext}});var j=p(109);Object.defineProperty(e,"generateStackHash",{enumerable:!0,get:function(){return j.generateStackHash}})})(),f})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./createContext.js"),require("./createCustomGlobalState.js"),require("./createGlobalState.js"),require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("./useStableState.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js","./GlobalStoreAbstract.js","./createContext.js","./createCustomGlobalState.js","./createGlobalState.js","./generateStackHash.js","./isRecord.js","./shallowCompare.js","./throwWrongKeyOnActionCollectionConfig.js","./uniqueId.js","./uniqueSymbol.js","./useStableState.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./createContext.js"),require("./createCustomGlobalState.js"),require("./createGlobalState.js"),require("./generateStackHash.js"),require("./isRecord.js"),require("./shallowCompare.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("./useStableState.js")):e["react-hooks-global-states"]=t(e["./GlobalStore.js"],e["./GlobalStoreAbstract.js"],e["./createContext.js"],e["./createCustomGlobalState.js"],e["./createGlobalState.js"],e["./generateStackHash.js"],e["./isRecord.js"],e["./shallowCompare.js"],e["./throwWrongKeyOnActionCollectionConfig.js"],e["./uniqueId.js"],e["./uniqueSymbol.js"],e["./useStableState.js"]);
1
+ var e,t;e=this,t=(e,t,r,o,a,n,s,l,u,i,c,b)=>(()=>{"use strict";var j={45:t=>{t.exports=e},78:e=>{e.exports=t},293:e=>{e.exports=r},361:e=>{e.exports=o},417:e=>{e.exports=a},487:e=>{e.exports=n},623:e=>{e.exports=s},670:e=>{e.exports=l},673:e=>{e.exports=u},778:e=>{e.exports=i},804:e=>{e.exports=c},923:e=>{e.exports=b}},S={};function p(e){var t=S[e];if(void 0!==t)return t.exports;var r=S[e]={exports:{}};return j[e](r,r.exports,p),r.exports}var f={};return(()=>{var e=f;Object.defineProperty(e,"__esModule",{value:!0}),e.generateStackHash=e.createContext=e.useStableState=e.uniqueSymbol=e.isRecord=e.throwWrongKeyOnActionCollectionConfig=e.uniqueId=e.shallowCompare=e.createCustomGlobalState=e.createGlobalState=e.GlobalStoreAbstract=e.GlobalStore=void 0;var t=p(778);Object.defineProperty(e,"GlobalStore",{enumerable:!0,get:function(){return t.GlobalStore}});var r=p(804);Object.defineProperty(e,"GlobalStoreAbstract",{enumerable:!0,get:function(){return r.GlobalStoreAbstract}});var o=p(670);Object.defineProperty(e,"createGlobalState",{enumerable:!0,get:function(){return o.createGlobalState}});var a=p(417);Object.defineProperty(e,"createCustomGlobalState",{enumerable:!0,get:function(){return a.createCustomGlobalState}});var n=p(673);Object.defineProperty(e,"shallowCompare",{enumerable:!0,get:function(){return n.shallowCompare}});var s=p(78);Object.defineProperty(e,"uniqueId",{enumerable:!0,get:function(){return s.uniqueId}});var l=p(361);Object.defineProperty(e,"throwWrongKeyOnActionCollectionConfig",{enumerable:!0,get:function(){return l.throwWrongKeyOnActionCollectionConfig}});var u=p(487);Object.defineProperty(e,"isRecord",{enumerable:!0,get:function(){return u.isRecord}});var i=p(293);Object.defineProperty(e,"uniqueSymbol",{enumerable:!0,get:function(){return i.uniqueSymbol}});var c=p(923);Object.defineProperty(e,"useStableState",{enumerable:!0,get:function(){return c.useStableState}});var b=p(623);Object.defineProperty(e,"createContext",{enumerable:!0,get:function(){return b.createContext}});var j=p(45);Object.defineProperty(e,"generateStackHash",{enumerable:!0,get:function(){return j.generateStackHash}})})(),f})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("./generateStackHash.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./createCustomGlobalState.js"),require("./isRecord.js"),require("./createContext.js"),require("./createGlobalState.js"),require("./shallowCompare.js"),require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./useStableState.js")):"function"==typeof define&&define.amd?define(["./generateStackHash.js","./uniqueId.js","./uniqueSymbol.js","./throwWrongKeyOnActionCollectionConfig.js","./createCustomGlobalState.js","./isRecord.js","./createContext.js","./createGlobalState.js","./shallowCompare.js","./GlobalStore.js","./GlobalStoreAbstract.js","./useStableState.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("./generateStackHash.js"),require("./uniqueId.js"),require("./uniqueSymbol.js"),require("./throwWrongKeyOnActionCollectionConfig.js"),require("./createCustomGlobalState.js"),require("./isRecord.js"),require("./createContext.js"),require("./createGlobalState.js"),require("./shallowCompare.js"),require("./GlobalStore.js"),require("./GlobalStoreAbstract.js"),require("./useStableState.js")):e["react-hooks-global-states"]=t(e["./generateStackHash.js"],e["./uniqueId.js"],e["./uniqueSymbol.js"],e["./throwWrongKeyOnActionCollectionConfig.js"],e["./createCustomGlobalState.js"],e["./isRecord.js"],e["./createContext.js"],e["./createGlobalState.js"],e["./shallowCompare.js"],e["./GlobalStore.js"],e["./GlobalStoreAbstract.js"],e["./useStableState.js"]);
@@ -46,26 +46,29 @@ export type HookExtensions<State, StateMutator, Metadata extends BaseMetadata |
46
46
  }) => ContextBaseHook<Derivate, StateMutator, Metadata>;
47
47
  };
48
48
  export interface CreateContext {
49
- <State, Hook = ContextHook<State, StateSetter<State>, BaseMetadata>>(state: State): readonly [
50
- Hook,
51
- ContextProvider<Hook, BaseMetadata>
49
+ <State>(value: State | (() => State)): [
50
+ ContextHook<State, StateSetter<State>, BaseMetadata>,
51
+ ContextProvider<State, BaseMetadata>
52
52
  ];
53
- <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>, Hook = ContextHook<State, PublicStateMutator, Metadata>>(value: State | (() => State), args: {
53
+ <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(value: State | (() => State), args: {
54
54
  name?: string;
55
55
  metadata?: Metadata | (() => Metadata);
56
56
  callbacks?: GlobalStoreCallbacks<State, Metadata> & {
57
57
  onUnMount?: () => void;
58
58
  };
59
- actions?: ActionCollectionConfig<State, Metadata>;
60
- }): readonly [Hook, ContextProvider<Hook, Metadata>];
61
- <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>, Hook = ContextHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>>(value: State | (() => State), args: {
59
+ actions?: ActionsConfig;
60
+ }): [ContextHook<State, PublicStateMutator, Metadata>, ContextProvider<State, Metadata>];
61
+ <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>>(value: State | (() => State), args: {
62
62
  name?: string;
63
63
  metadata?: Metadata | (() => Metadata);
64
64
  callbacks?: GlobalStoreCallbacks<State, Metadata> & {
65
65
  onUnMount?: () => void;
66
66
  };
67
- actions: ActionCollectionConfig<State, Metadata>;
68
- }): readonly [Hook, ContextProvider<Hook, Metadata>];
67
+ actions: ActionsConfig;
68
+ }): [
69
+ ContextHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>,
70
+ ContextProvider<State, Metadata>
71
+ ];
69
72
  }
70
73
  export declare const createContext: CreateContext;
71
74
  export default createContext;
package/createContext.js CHANGED
@@ -1 +1 @@
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,a=new WeakRef({});return function(){var s=(0,o.useContext)(r);if((0,i.isNil)(s))throw new Error("SelectorHook must be used within a ContextProvider");return(null==a?void 0:a.deref())!==s&&(null==n||n.dispose(),n=null,a=new WeakRef(s)),(0,i.isNil)(n)&&(n=s.createSelectorHook(e,t)),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,d=(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==d?void 0:d.current.store.getConfigCallbackParam())&&void 0!==e?e:null:{}}),[f,d]),(0,i.isNil)(d))return null;var v=d.current.parentHook;return(0,o.createElement)(r.Provider,{value:v},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);
1
+ var e,t;e=this,t=(e,t,r,o,n)=>(()=>{"use strict";var a={155:t=>{t.exports=e},506:e=>{e.exports=t},639:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createContext=void 0;var o=r(155),n=r(778),a=r(506),i=r(773),s=r(923);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,a=new WeakRef({});return function(){var s=(0,o.useContext)(r);if((0,i.isNil)(s))throw new Error("SelectorHook must be used within a ContextProvider");return(null==a?void 0:a.deref())!==s&&(null==n||n.dispose(),n=null,a=new WeakRef(s)),(0,i.isNil)(n)&&(n=s.createSelectorHook(e,t)),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,d=(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==d?void 0:d.current.store.getConfigCallbackParam())&&void 0!==e?e:null:{}}),[f,d]),(0,i.isNil)(d))return null;var v=d.current.parentHook;return(0,o.createElement)(r.Provider,{value:v},l)}]},t.default=t.createContext},773:e=>{e.exports=r},778:e=>{e.exports=o},923: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}(639)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("./GlobalStore.js"),require("./useStableState.js")):"function"==typeof define&&define.amd?define(["react","json-storage-formatter/isFunction","json-storage-formatter/isNil","./GlobalStore.js","./useStableState.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("react"),require("json-storage-formatter/isFunction"),require("json-storage-formatter/isNil"),require("./GlobalStore.js"),require("./useStableState.js")):e["react-hooks-global-states"]=t(e.react,e["json-storage-formatter/isFunction"],e["json-storage-formatter/isNil"],e["./GlobalStore.js"],e["./useStableState.js"]);
@@ -19,5 +19,5 @@ export interface CustomCreateGlobalState<TCustomConfig extends BaseMetadata | un
19
19
  /**
20
20
  * @description Simple custom global state hook builder
21
21
  */
22
- export declare const createCustomGlobalState: <TCustomConfig extends unknown, InheritMetadata extends unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>;
22
+ export declare const createCustomGlobalState: <TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>;
23
23
  export default createCustomGlobalState;
@@ -1 +1 @@
1
- var e;e=e=>(()=>{"use strict";var t={362:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createCustomGlobalState=void 0;var a=o(963);t.createCustomGlobalState=function(e){var t=e.onInitialize,o=e.onChange;return function(e){var l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=l.callbacks,r=function(e,t){var o={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(o[a[l]]=e[a[l]])}return o}(l,["callbacks"]);return(0,a.createGlobalState)(e,Object.assign(Object.assign({},r),{callbacks:Object.assign(Object.assign({},null!=n?n:{}),{onInit:function(e){var o;null==t||t(e,null==r?void 0:r.config),null===(o=null==n?void 0:n.onInit)||void 0===o||o.call(n,e)},onStateChanged:function(e){var t;null==o||o(e,null==r?void 0:r.config),null===(t=null==n?void 0:n.onStateChanged)||void 0===t||t.call(n,e)}})}))}},t.default=t.createCustomGlobalState},963:t=>{t.exports=e}},o={};return function e(a){var l=o[a];if(void 0!==l)return l.exports;var n=o[a]={exports:{}};return t[a](n,n.exports,e),n.exports}(362)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./createGlobalState.js")):"function"==typeof define&&define.amd?define(["./createGlobalState.js"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./createGlobalState.js")):this["react-hooks-global-states"]=e(this["./createGlobalState.js"]);
1
+ var e;e=e=>(()=>{"use strict";var t={154:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createCustomGlobalState=void 0;var a=o(670);t.createCustomGlobalState=function(e){var t=e.onInitialize,o=e.onChange;return function(e){var l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=l.callbacks,r=function(e,t){var o={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(o[a[l]]=e[a[l]])}return o}(l,["callbacks"]);return(0,a.createGlobalState)(e,Object.assign(Object.assign({},r),{callbacks:Object.assign(Object.assign({},null!=n?n:{}),{onInit:function(e){var o;null==t||t(e,null==r?void 0:r.config),null===(o=null==n?void 0:n.onInit)||void 0===o||o.call(n,e)},onStateChanged:function(e){var t;null==o||o(e,null==r?void 0:r.config),null===(t=null==n?void 0:n.onStateChanged)||void 0===t||t.call(n,e)}})}))}},t.default=t.createCustomGlobalState},670:t=>{t.exports=e}},o={};return function e(a){var l=o[a];if(void 0!==l)return l.exports;var n=o[a]={exports:{}};return t[a](n,n.exports,e),n.exports}(154)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./createGlobalState.js")):"function"==typeof define&&define.amd?define(["./createGlobalState.js"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./createGlobalState.js")):this["react-hooks-global-states"]=e(this["./createGlobalState.js"]);
@@ -1 +1 @@
1
- var e;e=e=>(()=>{"use strict";var t={196:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createGlobalState=void 0;var r=o(352);t.createGlobalState=function(e,t){return new r.GlobalStore(e,t).getHook()},t.default=t.createGlobalState},352:t=>{t.exports=e}},o={};return function e(r){var a=o[r];if(void 0!==a)return a.exports;var l=o[r]={exports:{}};return t[r](l,l.exports,e),l.exports}(196)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./GlobalStore.js")):this["react-hooks-global-states"]=e(this["./GlobalStore.js"]);
1
+ var e;e=e=>(()=>{"use strict";var t={778:t=>{t.exports=e},840:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createGlobalState=void 0;var r=o(778);t.createGlobalState=function(e,t){return new r.GlobalStore(e,t).getHook()},t.default=t.createGlobalState}},o={};return function e(r){var a=o[r];if(void 0!==a)return a.exports;var l=o[r]={exports:{}};return t[r](l,l.exports,e),l.exports}(840)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["./GlobalStore.js"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./GlobalStore.js")):this["react-hooks-global-states"]=e(this["./GlobalStore.js"]);
package/isRecord.js CHANGED
@@ -1 +1 @@
1
- var o;o=o=>(()=>{"use strict";var t={143:(o,t,e)=>{function r(o){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},r(o)}Object.defineProperty(t,"__esModule",{value:!0}),t.isRecord=void 0;var s=e(538);t.isRecord=function(o){return!(0,s.isNil)(o)&&"object"===r(o)},t.default=t.isRecord},538:t=>{t.exports=o}},e={};return function o(r){var s=e[r];if(void 0!==s)return s.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,o),i.exports}(143)})(),"object"==typeof exports&&"object"==typeof module?module.exports=o(require("json-storage-formatter/isNil")):"function"==typeof define&&define.amd?define(["json-storage-formatter/isNil"],o):"object"==typeof exports?exports["react-hooks-global-states"]=o(require("json-storage-formatter/isNil")):this["react-hooks-global-states"]=o(this["json-storage-formatter/isNil"]);
1
+ var o;o=o=>(()=>{"use strict";var t={35:(o,t,e)=>{function r(o){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},r(o)}Object.defineProperty(t,"__esModule",{value:!0}),t.isRecord=void 0;var s=e(773);t.isRecord=function(o){return!(0,s.isNil)(o)&&"object"===r(o)},t.default=t.isRecord},773:t=>{t.exports=o}},e={};return function o(r){var s=e[r];if(void 0!==s)return s.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,o),i.exports}(35)})(),"object"==typeof exports&&"object"==typeof module?module.exports=o(require("json-storage-formatter/isNil")):"function"==typeof define&&define.amd?define(["json-storage-formatter/isNil"],o):"object"==typeof exports?exports["react-hooks-global-states"]=o(require("json-storage-formatter/isNil")):this["react-hooks-global-states"]=o(this["json-storage-formatter/isNil"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "8.2.2",
3
+ "version": "8.2.4",
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",
@@ -117,6 +117,8 @@
117
117
  "homepage": "https://github.com/johnny-quesada-developer/react-hooks-global-states#readme",
118
118
  "devDependencies": {
119
119
  "@babel/core": "^7.21.3",
120
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
121
+ "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
120
122
  "@babel/plugin-transform-modules-commonjs": "^7.21.2",
121
123
  "@babel/preset-env": "^7.20.2",
122
124
  "@babel/preset-react": "^7.18.6",
@@ -137,19 +139,19 @@
137
139
  "eslint-plugin-react": "^7.21.5",
138
140
  "eslint-plugin-react-hooks": "^4.2.0",
139
141
  "jest": "^26.6.3",
142
+ "json-storage-formatter": "^2.0.9",
140
143
  "react": ">=17.0.0",
141
144
  "react-test-renderer": "^17.0.1",
142
145
  "ts-jest": "^26.4.4",
143
146
  "ts-loader": "^9.5.1",
144
147
  "tslib": "^2.6.2",
145
- "typescript": "^5.3.3",
148
+ "typescript": "^5.8.2",
146
149
  "webpack": "^5.76.3",
147
- "webpack-cli": "^5.0.1",
148
- "json-storage-formatter": "^2.0.9"
150
+ "webpack-cli": "^5.0.1"
149
151
  },
150
152
  "peerDependencies": {
151
- "react": ">=17.0.0",
152
- "json-storage-formatter": "^2.0.9"
153
+ "json-storage-formatter": "^2.0.9",
154
+ "react": ">=17.0.0"
153
155
  },
154
156
  "peerDependenciesMeta": {
155
157
  "react": {
package/shallowCompare.js CHANGED
@@ -1 +1 @@
1
- var r,e;r=this,e=(r,e,t,o)=>(()=>{"use strict";var n={561:(r,e,t)=>{function o(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var o,n,i,a,s=[],f=!0,u=!1;try{if(i=(t=t.call(r)).next,0===e){if(Object(t)!==t)return;f=!1}else for(;!(f=(o=i.call(t)).done)&&(s.push(o.value),s.length!==e);f=!0);}catch(r){u=!0,n=r}finally{try{if(!f&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(u)throw n}}return s}}(r,e)||i(r,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(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=i(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var o=0,n=function(){};return{s:n,n:function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}},e:function(r){throw r},f:n}}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,s=!0,f=!1;return{s:function(){t=t.call(r)},n:function(){var r=t.next();return s=r.done,r},e:function(r){f=!0,a=r},f:function(){try{s||null==t.return||t.return()}finally{if(f)throw a}}}}function i(r,e){if(r){if("string"==typeof r)return a(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,e):void 0}}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}function s(r){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},s(r)}Object.defineProperty(e,"__esModule",{value:!0}),e.shallowCompare=void 0;var f=t(834),u=t(266),l=t(538),c=t(664);e.shallowCompare=function(r,e){if(r===e)return!0;var t=s(r),i=s(e);if(t!==i)return!1;if((0,l.isNil)(r)||(0,l.isNil)(e)||(0,f.isPrimitive)(r)&&(0,f.isPrimitive)(e)||(0,u.isDate)(r)&&(0,u.isDate)(e)||"function"===t&&"function"===i)return r===e;if(Array.isArray(r)){var a=r,y=e;if(a.length!==y.length)return!1;for(var m=0;m<a.length;m++)if(a[m]!==y[m])return!1}if(r instanceof Map){var v=r,p=e;if(v.size!==p.size)return!1;var d,b=n(v);try{for(b.s();!(d=b.n()).done;){var h=o(d.value,2),g=h[0];if(h[1]!==p.get(g))return!1}}catch(r){b.e(r)}finally{b.f()}}if(r instanceof Set){var j=r,x=e;if(j.size!==x.size)return!1;var S,w=n(j);try{for(w.s();!(S=w.n()).done;){var A=S.value;if(!x.has(A))return!1}}catch(r){w.e(r)}finally{w.f()}}if(!(0,c.isRecord)(r)||!(0,c.isRecord)(e))return r===e;var q=Object.keys(r),O=Object.keys(e);if(q.length!==O.length)return!1;for(var P=0,D=q;P<D.length;P++){var N=D[P];if(r[N]!==e[N])return!1}return!0},e.default=e.shallowCompare},664:e=>{e.exports=r},266:r=>{r.exports=e},538:r=>{r.exports=t},834:r=>{r.exports=o}},i={};return function r(e){var t=i[e];if(void 0!==t)return t.exports;var o=i[e]={exports:{}};return n[e](o,o.exports,r),o.exports}(561)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./isRecord.js"),require("json-storage-formatter/isDate"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isPrimitive")):"function"==typeof define&&define.amd?define(["./isRecord.js","json-storage-formatter/isDate","json-storage-formatter/isNil","json-storage-formatter/isPrimitive"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("./isRecord.js"),require("json-storage-formatter/isDate"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isPrimitive")):r["react-hooks-global-states"]=e(r["./isRecord.js"],r["json-storage-formatter/isDate"],r["json-storage-formatter/isNil"],r["json-storage-formatter/isPrimitive"]);
1
+ var r,t;r=this,t=(r,t,e,o)=>(()=>{"use strict";var n={38:t=>{t.exports=r},487:r=>{r.exports=t},773:r=>{r.exports=e},955:r=>{r.exports=o},973:(r,t,e)=>{function o(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!e){if(Array.isArray(r)||(e=n(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var o=0,i=function(){};return{s:i,n:function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}},e:function(r){throw r},f:i}}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,s=!0,f=!1;return{s:function(){e=e.call(r)},n:function(){var r=e.next();return s=r.done,r},e:function(r){f=!0,a=r},f:function(){try{s||null==e.return||e.return()}finally{if(f)throw a}}}}function n(r,t){if(r){if("string"==typeof r)return i(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(r,t):void 0}}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,o=Array(t);e<t;e++)o[e]=r[e];return o}function a(r){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},a(r)}Object.defineProperty(t,"__esModule",{value:!0}),t.shallowCompare=void 0;var s=e(955),f=e(38),u=e(773),l=e(487);t.shallowCompare=function(r,t){if(r===t)return!0;var e,i=a(r),c=a(t);if(i!==c)return!1;if((0,u.isNil)(r)||(0,u.isNil)(t)||(0,s.isPrimitive)(r)&&(0,s.isPrimitive)(t)||(0,f.isDate)(r)&&(0,f.isDate)(t)||"function"===i&&"function"===c)return r===t;if(Array.isArray(r)){var y=r,m=t;if(y.length!==m.length)return!1;for(var v=0;v<y.length;v++)if(y[v]!==m[v])return!1}if(r instanceof Map){var p=r,d=t;if(p.size!==d.size)return!1;var b,h=o(p);try{for(h.s();!(b=h.n()).done;){var g=function(r){if(Array.isArray(r))return r}(e=b.value)||function(r){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,o,n,i,a=[],s=!0,f=!1;try{for(n=(t=t.call(r)).next;!(s=(e=n.call(t)).done)&&(a.push(e.value),2!==a.length);s=!0);}catch(r){f=!0,o=r}finally{try{if(!s&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(f)throw o}}return a}}(e)||n(e,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.")}(),j=g[0];if(g[1]!==d.get(j))return!1}}catch(r){h.e(r)}finally{h.f()}}if(r instanceof Set){var x=r,S=t;if(x.size!==S.size)return!1;var w,A=o(x);try{for(A.s();!(w=A.n()).done;){var q=w.value;if(!S.has(q))return!1}}catch(r){A.e(r)}finally{A.f()}}if(!(0,l.isRecord)(r)||!(0,l.isRecord)(t))return r===t;var P=Object.keys(r),D=Object.keys(t);if(P.length!==D.length)return!1;for(var N=0,R=P;N<R.length;N++){var I=R[N];if(r[I]!==t[I])return!1}return!0},t.default=t.shallowCompare}},i={};return function r(t){var e=i[t];if(void 0!==e)return e.exports;var o=i[t]={exports:{}};return n[t](o,o.exports,r),o.exports}(973)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("json-storage-formatter/isDate"),require("./isRecord.js"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isPrimitive")):"function"==typeof define&&define.amd?define(["json-storage-formatter/isDate","./isRecord.js","json-storage-formatter/isNil","json-storage-formatter/isPrimitive"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("json-storage-formatter/isDate"),require("./isRecord.js"),require("json-storage-formatter/isNil"),require("json-storage-formatter/isPrimitive")):r["react-hooks-global-states"]=t(r["json-storage-formatter/isDate"],r["./isRecord.js"],r["json-storage-formatter/isNil"],r["json-storage-formatter/isPrimitive"]);
package/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type StateSetter<State> = (setter: State | ((state: State) => State), meta?: {
3
2
  /**
4
3
  * @description you can add an identifier to the state call
@@ -9,5 +9,5 @@ type RefObject<T> = {
9
9
  * - Initial render doesn't trigger cleanup
10
10
  * - Starts cold, returns null until the first render or fallback if provided
11
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;
12
+ export declare const useStableState: <T, F extends T | never>(builder: StateBuilder<T>, dependencies: unknown[], fallbackArg?: F) => F extends T ? RefObject<T> : RefObject<T> | null;
13
13
  export default useStableState;
package/useStableState.js CHANGED
@@ -1 +1 @@
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);
1
+ var t;t=t=>(()=>{"use strict";var e={155:e=>{e.exports=t},163:(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={}.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=Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.useStableState=void 0;var u=r(155);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}},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}(163)})(),"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);