react-hooks-global-states 12.0.6 → 14.0.1

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
@@ -11,15 +11,11 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
11
11
  * @description If the actionsConfig is defined, this will be a map of actions that can be used to modify or interact with the state
12
12
  * */
13
13
  actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
14
+ storeTools: StoreTools<State, PublicStateMutator, Metadata>;
14
15
  /**
15
16
  * @description The main hook that will be used to interact with the global state
16
17
  */
17
18
  use: StateHook<State, PublicStateMutator, Metadata>;
18
- /**
19
- * @description
20
- * Access to the store api that will be passed to the actions and callbacks
21
- */
22
- private configurationCallbackParam;
23
19
  subscribers: Set<SubscriberParameters>;
24
20
  state: State;
25
21
  constructor(state: State);
@@ -78,11 +74,6 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
78
74
  * Subscribe to the state changes
79
75
  */
80
76
  subscribe: SubscribeToState<State>;
81
- /**
82
- * get the parameters object to pass to the callback functions:
83
- * onInit, onStateChanged, onSubscribed, computePreventStateChange
84
- * */
85
- getConfigCallbackParam: () => StoreTools<State, PublicStateMutator, Metadata>;
86
77
  protected subscribeCallback: (subscription: SubscriberParameters) => () => void;
87
78
  protected partialUpdateSubscription: (subscription: SubscriberParameters, values: Partial<SubscriberParameters>) => void;
88
79
  protected executeOnSubscribed: (subscription: SubscriberParameters) => void;
@@ -117,7 +108,10 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
117
108
  * This creates a map of actions that can be used to modify or interact with the state
118
109
  * @returns {ActionCollectionResult<State, Metadata, StateMutator>} - The actions map result of the configuration object passed to the constructor
119
110
  * */
120
- getStoreActionsMap: () => typeof this.actions;
111
+ getStoreActionsMap: () => {
112
+ actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
113
+ storeTools: StoreTools<State, PublicStateMutator, Metadata>;
114
+ };
121
115
  protected removeSubscriptions: () => void;
122
116
  dispose: () => void;
123
117
  }
package/GlobalStore.js CHANGED
@@ -1 +1 @@
1
- var t,e;t=this,e=(t,e,r,n,o,i,a)=>(()=>{"use strict";var u={78:e=>{e.exports=t},155:t=>{t.exports=e},361:t=>{t.exports=r},487:t=>{t.exports=n},506:t=>{t.exports=o},673:t=>{t.exports=i},773:t=>{t.exports=a},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var r=globalThis;r.isDevToolsPresent=Boolean(r.REACT_GLOBAL_STATE_HOOK_DEBUG),e.default=r}},c={};function s(t){var e=c[t];if(void 0!==e)return e.exports;var r=c[t]={exports:{}};return u[t](r,r.exports,s),r.exports}var l={};return(()=>{var t=l;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){if(t){if("string"==typeof t)return n(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)?n(t,e):void 0}}function n(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 o(){o=function(){return r};var t,r={},n=Object.prototype,i=n.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},u="function"==typeof Symbol?Symbol:{},c=u.iterator||"@@iterator",s=u.asyncIterator||"@@asyncIterator",l=u.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 d(t,e,r,n){var o=e&&e.prototype instanceof m?e:m,i=Object.create(o.prototype),u=new A(n||[]);return a(i,"_invoke",{value:L(t,r,u)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=d;var b="suspendedStart",v="suspendedYield",p="executing",g="completed",y={};function m(){}function S(){}function w(){}var j={};f(j,c,(function(){return this}));var O=Object.getPrototypeOf,k=O&&O(O(P([])));k&&k!==n&&i.call(k,c)&&(j=k);var x=w.prototype=m.prototype=Object.create(j);function C(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,r){function n(o,a,u,c){var s=h(t[o],t,a);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==e(f)&&i.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,u,c)}),(function(t){n("throw",t,u,c)})):r.resolve(f).then((function(t){l.value=t,u(l)}),(function(t){return n("throw",t,u,c)}))}c(s.arg)}var o;a(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function L(e,r,n){var o=b;return function(i,a){if(o===p)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 u=n.delegate;if(u){var c=_(u,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===b)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=p;var s=h(e,r,n);if("normal"===s.type){if(o=n.done?g:v,s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=g,n.method="throw",n.arg=s.arg)}}}function _(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,_(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=h(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 q(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 M(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(q,this),this.reset(!0)}function P(r){if(r||""===r){var n=r[c];if(n)return n.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,a=function e(){for(;++o<r.length;)if(i.call(r,o))return e.value=r[o],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 S.prototype=w,a(x,"constructor",{value:w,configurable:!0}),a(w,"constructor",{value:S,configurable:!0}),S.displayName=f(w,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===S||"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(x),t},r.awrap=function(t){return{__await:t}},C(E.prototype),f(E.prototype,s,(function(){return this})),r.AsyncIterator=E,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new E(d(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},C(x),f(x,l,"Generator"),f(x,c,(function(){return this})),f(x,"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=P,A.prototype={constructor:A,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(M),!e)for(var r in this)"t"===r.charAt(0)&&i.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 u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=i.call(a,"catchLoc"),s=i.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)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&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.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),M(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;M(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:P(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,u(n.key),n)}}function a(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function u(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,t.createObservable=S,t.createSelectorHook=w;var c,f=s(155),d=s(506),h=s(773),b=s(487),v=s(673),p=s(361),g=s(78),y=(c=s(811))&&c.__esModule?c:{default:c},m=a((function t(e){var n,i,a=this,c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Set,this.initialize=function(){return t=a,e=void 0,r=o().mark((function t(){var e,r,n,i,a;return o().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()),this.use=this.getMainHook(),this.configurationCallbackParam=this.getConfigCallbackParam(),n=this.onInit,i=null!==(r=this.callbacks)&&void 0!==r?r:{},a=i.onInit,n||a){t.next=8;break}return t.abrupt("return");case 8:null==n||n(this.configurationCallbackParam),(0,h.isNil)(a)||null==a||a(this.configurationCallbackParam);case 10:case"end":return t.stop()}}),t,this)})),new(e||(e=Promise))((function(n,o){function i(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var r;t.done?n(t.value):(r=t.value,r instanceof e?r:new e((function(t){t(r)}))).then(i,a)}u((r=r.apply(t,[])).next())}));var t,e,r},this.executeSetStateForSubscriber=function(t,e){var r,n,o,i=t.selector,u=t.callback,c=t.currentState,s=t.getConfig,l=null!==(r=null==s?void 0:s())&&void 0!==r?r:{};if(!e.forceUpdate&&(null!==(n=null==l?void 0:l.isEqualRoot)&&void 0!==n?n:function(t,e){return t===e})(e.currentState,e.newState))return{didUpdate:!1};var f=i?i(e.newState):e.newState;return!e.forceUpdate&&(null!==(o=null==l?void 0:l.isEqual)&&void 0!==o?o:function(t,e){return t===e})(c,f)?{didUpdate:!1}:(a.partialUpdateSubscription(t,{currentState:f}),u({state:f},{identifier:e.identifier}),{didUpdate:!0})},this.setSubscribersState=function(t,e){var n=e.forceUpdate,o=e.identifier,i=a.state;if(n||i!==t){a.state=t;var u,c={forceUpdate:n,newState:t,currentState:i,identifier:o},s=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=r(t))){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,u=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return a=t.done,t},e:function(t){u=!0,i=t},f:function(){try{a||null==e.return||e.return()}finally{if(u)throw i}}}}(a.subscribers.values());try{for(s.s();!(u=s.n()).done;){var l=u.value;a.executeSetStateForSubscriber(l,c)}}catch(t){s.e(t)}finally{s.f()}}},this.setMetadata=function(t){var e=(0,d.isFunction)(t)?t(a.metadata):t;a.metadata=e},this.getMetadata=function(){return a.metadata},this.getState=function(){return a.state},this.subscribe=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n,o=e[0],i=e[1],u=e[2],c=(0,d.isFunction)(i),s=c?o:void 0,l=c?i:o,f=null!==(n=c?u:i)&&void 0!==n?n:void 0,h=s?s(a.state):a.state;(null==f?void 0:f.skipFirst)||l(h);var b={selector:s,getConfig:function(){return f},currentState:h,callback:function(t){var e=t.state;return l(e)}};return a.subscribeCallback(b),function(){a.subscribers.delete(b)}},this.getConfigCallbackParam=function(){var t=a.setMetadata,e=a.getMetadata,r=a.getState,n=a.subscribe,o=a.actions;return{setMetadata:t,getMetadata:e,getState:r,subscribe:n,setState:a.setState,actions:o}},this.subscribeCallback=function(t){return a.executeOnSubscribed(t),a.subscribers.add(t),function(){a.subscribers.delete(t)}},this.partialUpdateSubscription=function(t,e){(0,b.isRecord)(t)&&Object.assign(t,e)},this.executeOnSubscribed=function(t){var e,r=a.onSubscribed,n=null===(e=a.callbacks)||void 0===e?void 0:e.onSubscribed;(r||n)&&(null==r||r(a.configurationCallbackParam,t),null==n||n(a.configurationCallbackParam,t))},this.getMainHook=function(){var t=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=(0,v.isArray)(e)?{dependencies:e}:null!=e?e:{},n=(0,f.useRef)({selector:t,config:r}),o=n.current.config.dependencies;n.current.selector=t,n.current.config=r;var i=(0,f.useMemo)((function(){var t=function(t){var e=n.current.selector;return(0,d.isFunction)(e)?e(t):t},e={currentState:t(a.state),selector:t,getConfig:function(){return n.current.config},callback:function(){throw new Error("Callback not set")}},r=function(){return e.currentState};return{subscribe:function(t){return e.callback=t,a.subscribeCallback(e)},getSnapshot:r,getServerSnapshot:r,subscription:e}}),[]),u=i.subscribe,c=i.getSnapshot,s=i.getServerSnapshot,l=i.subscription;return(0,f.useSyncExternalStore)(u,c,s),[a.computeSelectedState({subscription:l,currentDependencies:o}),a.getStateOrchestrator(),a.metadata]},e=a.setMetadata,r=a.getMetadata,n=a.actions,o=a.actions?null:a.setState.bind(a),i=a,u={actions:n,createObservable:a.createObservable.bind(i),createSelectorHook:a.createSelectorHook.bind(i),dispose:a.dispose.bind(a),getMetadata:r,getState:a.getState.bind(a),setMetadata:e,setState:o,subscribe:a.subscribe.bind(a),use:t,select:function(){return t.apply(void 0,arguments)[0]}};return Object.assign(t,u),t},this.computeSelectedState=function(t){var e,r=t.subscription,n=t.currentDependencies;if(!r.selector)return r.currentState;var o=(null!==(e=r.getConfig())&&void 0!==e?e:{}).dependencies;return n===o||(null==n?void 0:n.length)===(null==o?void 0:o.length)&&(0,v.shallowCompare)(n,o)||a.partialUpdateSubscription(r,{currentState:r.selector(a.state)}),r.currentState},this.createSelectorHook=w,this.createObservable=S,this.getStateOrchestrator=function(){return a.actions?a.actions:a.setState},this.setState=function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.forceUpdate,i=n.identifier,u=a.state,c=(0,d.isFunction)(t)?t(u):t;if(o||a.state!==c){var s=a.setMetadata,l=a.getMetadata,f=a.getState,h=a.actions,b={setMetadata:s,getMetadata:l,setState:a.setSubscribersState,getState:f,actions:h,previousState:u,state:c,identifier:i},v=a.computePreventStateChange,p=null===(e=a.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((v||p)&&((null==v?void 0:v(b))||(null==p?void 0:p(b))))return;a.setSubscribersState(c,{forceUpdate:o,identifier:i});var g=a.onStateChanged,y=null===(r=a.callbacks)||void 0===r?void 0:r.onStateChanged;(g||y)&&(null==g||g(b),null==y||y(b))}},this.getStoreActionsMap=function(){if(!(0,b.isRecord)(a.actionsConfig))return null;var t=a.actionsConfig,e=a.setMetadata,r=a.setState,n=a.getState,o=a.getMetadata,i=Object.keys(t).reduce((function(a,c){var s,l,f;return Object.assign(a,(s={},f=function(){for(var a=t[c],u=arguments.length,s=new Array(u),l=0;l<u;l++)s[l]=arguments[l];var f=a.apply(i,s);return"function"!=typeof f&&(0,p.throwWrongKeyOnActionCollectionConfig)(c),f.call(i,{setState:r,getState:n,setMetadata:e,getMetadata:o,actions:i})},(l=u(l=c))in s?Object.defineProperty(s,l,{value:f,enumerable:!0,configurable:!0,writable:!0}):s[l]=f,s)),a}),{});return i},this.removeSubscriptions=function(){a.subscribers.clear()},this.dispose=function(){a.removeSubscriptions(),a._name="",a.actionsConfig=null,a.callbacks=null,a.metadata={},a.actions=null,a.state=Object.create(null)};var s=c.metadata,l=c.callbacks,m=c.actions,j=c.name;if(this.state=e,this._name=null!=j?j:(0,g.uniqueId)("gs:"),this.metadata=null!=s?s:{},this.callbacks=null!=l?l:null,this.actionsConfig=null!=m?m:null,y.default.isDevToolsPresent){var O=null!==(n=(new Error).stack)&&void 0!==n?n:"";null===(i=y.default.REACT_GLOBAL_STATE_HOOK_DEBUG)||void 0===i||i.call(y.default,this,c,O)}this.constructor!==t||this.initialize()}));function S(t,e){var r=null==e?void 0:e.name,n=null==e?void 0:e.isEqualRoot,o=null==e?void 0:e.isEqual,i=this.getState(),a=(null!=t?t:function(t){return t})(i),u=new m(a,{name:null!=r?r:(0,g.uniqueId)("sh:")}),c=this.subscribe((function(e){if(!(null!=n?n:Object.is)(i,e)){i=e;var r=t(e);(null!=o?o:Object.is)(a,r)||(a=r,u.setState(r))}}),{skipFirst:!0}),s=u.subscribe.bind(u),l={getState:u.getState.bind(u),subscribe:u.subscribe.bind(u),createSelectorHook:w.bind(s),createObservable:S.bind(s),dispose:function(){c(),u.dispose()}};return Object.assign(s,l),s}function w(t,e){var n=null==e?void 0:e.name,o=null==e?void 0:e.isEqualRoot,i=null==e?void 0:e.isEqual,a=this.getState(),u=(null!=t?t:function(t){return t})(a),c=new m(u,{name:null!=n?n:(0,g.uniqueId)("sh:")}),s=this.subscribe((function(e){if(!(null!=o?o:Object.is)(a,e)){a=e;var r=t(e);(null!=i?i:Object.is)(u,r)||(u=r,c.setState(r))}}),{skipFirst:!0}),l=function(){return(t=c.use.apply(c,arguments),function(t){if(Array.isArray(t))return t}(t)||function(t){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var r,n,o,i,a=[],u=!0,c=!1;try{for(o=(e=e.call(t)).next;!(u=(r=o.call(e)).done)&&(a.push(r.value),1!==a.length);u=!0);}catch(t){c=!0,n=t}finally{try{if(!u&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(c)throw n}}return a}}(t)||r(t,1)||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.")}())[0];var t},f={getState:function(){return c.getState()},subscribe:c.subscribe.bind(c),createSelectorHook:w.bind(l),createObservable:S.bind(l),dispose:function(){s(),c.dispose()}};return Object.assign(l,f),l}t.GlobalStore=m,t.default=m})(),l})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./uniqueId.js"),require("react"),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(["./uniqueId.js","react","./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("./uniqueId.js"),require("react"),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["./uniqueId.js"],t.react,t["./throwWrongKeyOnActionCollectionConfig.js"],t["./isRecord.js"],t["json-storage-formatter/isFunction"],t["./shallowCompare.js"],t["json-storage-formatter/isNil"]);
1
+ var t,e;t=this,e=(t,e,r,n,o,i,a)=>(()=>{"use strict";var s={78:e=>{e.exports=t},155:t=>{t.exports=e},361:t=>{t.exports=r},487:t=>{t.exports=n},506:t=>{t.exports=o},673:t=>{t.exports=i},773:t=>{t.exports=a},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var r=globalThis;r.isDevToolsPresent=Boolean(r.REACT_GLOBAL_STATE_HOOK_DEBUG),e.default=r}},u={};function c(t){var e=u[t];if(void 0!==e)return e.exports;var r=u[t]={exports:{}};return s[t](r,r.exports,c),r.exports}var l={};return(()=>{var t=l;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){if(t){if("string"==typeof t)return n(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)?n(t,e):void 0}}function n(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 o(){o=function(){return r};var t,r={},n=Object.prototype,i=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 d(t,e,r,n){var o=e&&e.prototype instanceof m?e:m,i=Object.create(o.prototype),s=new T(n||[]);return a(i,"_invoke",{value:L(t,r,s)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=d;var v="suspendedStart",p="suspendedYield",b="executing",g="completed",y={};function m(){}function S(){}function w(){}var j={};f(j,u,(function(){return this}));var O=Object.getPrototypeOf,x=O&&O(O(M([])));x&&x!==n&&i.call(x,u)&&(j=x);var k=w.prototype=m.prototype=Object.create(j);function E(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function C(t,r){function n(o,a,s,u){var c=h(t[o],t,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==e(f)&&i.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 o;a(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function L(e,r,n){var o=v;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=_(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===v)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=b;var c=h(e,r,n);if("normal"===c.type){if(o=n.done?g:p,c.arg===y)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=g,n.method="throw",n.arg=c.arg)}}}function _(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,_(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=h(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 q(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(q,this),this.reset(!0)}function M(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 o=-1,a=function e(){for(;++o<r.length;)if(i.call(r,o))return e.value=r[o],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 S.prototype=w,a(k,"constructor",{value:w,configurable:!0}),a(w,"constructor",{value:S,configurable:!0}),S.displayName=f(w,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===S||"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(k),t},r.awrap=function(t){return{__await:t}},E(C.prototype),f(C.prototype,c,(function(){return this})),r.AsyncIterator=C,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new C(d(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(k),f(k,l,"Generator"),f(k,u,(function(){return this})),f(k,"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=M,T.prototype={constructor:T,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(A),!e)for(var r in this)"t"===r.charAt(0)&&i.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 o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=i.call(a,"catchLoc"),c=i.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&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.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),A(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;A(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:M(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function i(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,s(n.key),n)}}function a(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(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,t.createObservable=S,t.createSelectorHook=w;var u,f=c(155),d=c(506),h=c(773),v=c(487),p=c(673),b=c(361),g=c(78),y=(u=c(811))&&u.__esModule?u:{default:u},m=a((function t(e){var n,i,a=this,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Set,this.initialize=function(){return t=a,e=void 0,r=o().mark((function t(){var e,r,n,i,a,s,u;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.getStoreActionsMap(),n=r.actions,i=r.storeTools,this.actions=n,this.storeTools=i,this.use=this.getMainHook(),a=this.onInit,s=null!==(e=this.callbacks)&&void 0!==e?e:{},u=s.onInit,a||u){t.next=8;break}return t.abrupt("return");case 8:null==a||a(i),(0,h.isNil)(u)||null==u||u(i);case 10: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,i=t.selector,s=t.callback,u=t.currentState,c=t.getConfig,l=null!==(r=null==c?void 0:c())&&void 0!==r?r:{};if(!e.forceUpdate&&(null!==(n=null==l?void 0:l.isEqualRoot)&&void 0!==n?n:function(t,e){return t===e})(e.currentState,e.newState))return{didUpdate:!1};var f=i?i(e.newState):e.newState;return!e.forceUpdate&&(null!==(o=null==l?void 0:l.isEqual)&&void 0!==o?o:function(t,e){return t===e})(u,f)?{didUpdate:!1}:(a.partialUpdateSubscription(t,{currentState:f}),s({state:f},{identifier:e.identifier}),{didUpdate:!0})},this.setSubscribersState=function(t,e){var n=e.forceUpdate,o=e.identifier,i=a.state;if(n||i!==t){a.state=t;var s,u={forceUpdate:n,newState:t,currentState:i,identifier:o},c=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=r(t))){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var 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}}}}(a.subscribers.values());try{for(c.s();!(s=c.n()).done;){var l=s.value;a.executeSetStateForSubscriber(l,u)}}catch(t){c.e(t)}finally{c.f()}}},this.setMetadata=function(t){var e=(0,d.isFunction)(t)?t(a.metadata):t;a.metadata=e},this.getMetadata=function(){return a.metadata},this.getState=function(){return a.state},this.subscribe=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n,o=e[0],i=e[1],s=e[2],u=(0,d.isFunction)(i),c=u?o:void 0,l=u?i:o,f=null!==(n=u?s:i)&&void 0!==n?n:void 0,h=c?c(a.state):a.state;(null==f?void 0:f.skipFirst)||l(h);var v={selector:c,getConfig:function(){return f},currentState:h,callback:function(t){var e=t.state;return l(e)}};return a.subscribeCallback(v),function(){a.subscribers.delete(v)}},this.subscribeCallback=function(t){return a.executeOnSubscribed(t),a.subscribers.add(t),function(){a.subscribers.delete(t)}},this.partialUpdateSubscription=function(t,e){(0,v.isRecord)(t)&&Object.assign(t,e)},this.executeOnSubscribed=function(t){var e,r=a.onSubscribed,n=null===(e=a.callbacks)||void 0===e?void 0:e.onSubscribed;(r||n)&&(null==r||r(a.storeTools,t),null==n||n(a.storeTools,t))},this.getMainHook=function(){var t=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=(0,p.isArray)(e)?{dependencies:e}:null!=e?e:{},n=(0,f.useRef)({selector:t,config:r}),o=n.current.config.dependencies;n.current.selector=t,n.current.config=r;var i=(0,f.useMemo)((function(){var t=function(t){var e=n.current.selector;return(0,d.isFunction)(e)?e(t):t},e={currentState:t(a.state),selector:t,getConfig:function(){return n.current.config},callback:function(){throw new Error("Callback not set")}},r=function(){return e.currentState};return{subscribe:function(t){return e.callback=t,a.subscribeCallback(e)},getSnapshot:r,getServerSnapshot:r,subscription:e}}),[]),s=i.subscribe,u=i.getSnapshot,c=i.getServerSnapshot,l=i.subscription;return(0,f.useSyncExternalStore)(s,u,c),[a.computeSelectedState({subscription:l,currentDependencies:o}),a.getStateOrchestrator(),a.metadata]},e=a.setMetadata,r=a.getMetadata,n=a.actions,o=a.actions?null:a.setState.bind(a),i=a,s={actions:n,createObservable:a.createObservable.bind(i),createSelectorHook:a.createSelectorHook.bind(i),dispose:a.dispose.bind(a),getMetadata:r,getState:a.getState.bind(a),setMetadata:e,setState:o,subscribe:a.subscribe.bind(a),use:t,select:function(){return t.apply(void 0,arguments)[0]}};return Object.assign(t,s),t},this.computeSelectedState=function(t){var e,r=t.subscription,n=t.currentDependencies;if(!r.selector)return r.currentState;var o=(null!==(e=r.getConfig())&&void 0!==e?e:{}).dependencies;return n===o||(null==n?void 0:n.length)===(null==o?void 0:o.length)&&(0,p.shallowCompare)(n,o)||a.partialUpdateSubscription(r,{currentState:r.selector(a.state)}),r.currentState},this.createSelectorHook=w,this.createObservable=S,this.getStateOrchestrator=function(){return a.actions?a.actions:a.setState},this.setState=function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.forceUpdate,i=n.identifier,s=a.state,u=(0,d.isFunction)(t)?t(s):t;if(o||a.state!==u){var c=a.setMetadata,l=a.getMetadata,f=a.getState,h=a.actions,v={setMetadata:c,getMetadata:l,setState:a.setSubscribersState,getState:f,actions:h,previousState:s,state:u,identifier:i},p=a.computePreventStateChange,b=null===(e=a.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((p||b)&&((null==p?void 0:p(v))||(null==b?void 0:b(v))))return;a.setSubscribersState(u,{forceUpdate:o,identifier:i});var g=a.onStateChanged,y=null===(r=a.callbacks)||void 0===r?void 0:r.onStateChanged;(g||y)&&(null==g||g(v),null==y||y(v))}},this.getStoreActionsMap=function(){var t=a.actionsConfig,e=a.getMetadata,r=a.getState,n={setMetadata:a.setMetadata,getMetadata:e,getState:r,setState:a.setState,subscribe:a.subscribe,actions:null};if(!(0,v.isRecord)(t))return{actions:null,storeTools:n};var o={};n.actions=o;for(var i=Object.keys(t),u=function(){var e,r,i,a=l[c];Object.assign(o,(e={},i=function(){for(var e=t[a],r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];var u=e.apply(o,i);return"function"!=typeof u&&(0,b.throwWrongKeyOnActionCollectionConfig)(a),u.call(o,n)},(r=s(r=a))in e?Object.defineProperty(e,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[r]=i,e))},c=0,l=i;c<l.length;c++)u();return{actions:o,storeTools:n}},this.removeSubscriptions=function(){a.subscribers.clear()},this.dispose=function(){a.removeSubscriptions(),a._name="",a.actionsConfig=null,a.callbacks=null,a.metadata={},a.actions=null,a.state=Object.create(null)};var c=u.metadata,l=u.callbacks,m=u.actions,j=u.name;if(this.state=e,this._name=null!=j?j:(0,g.uniqueId)("gs:"),this.metadata=null!=c?c:{},this.callbacks=null!=l?l:null,this.actionsConfig=null!=m?m:null,y.default.isDevToolsPresent){var O=null!==(n=(new Error).stack)&&void 0!==n?n:"";null===(i=y.default.REACT_GLOBAL_STATE_HOOK_DEBUG)||void 0===i||i.call(y.default,this,u,O)}this.constructor!==t||this.initialize()}));function S(t,e){var r=null==e?void 0:e.name,n=null==e?void 0:e.isEqualRoot,o=null==e?void 0:e.isEqual,i=this.getState(),a=(null!=t?t:function(t){return t})(i),s=new m(a,{name:null!=r?r:(0,g.uniqueId)("sh:")}),u=this.subscribe((function(e){if(!(null!=n?n:Object.is)(i,e)){i=e;var r=t(e);(null!=o?o:Object.is)(a,r)||(a=r,s.setState(r))}}),{skipFirst:!0}),c=s.subscribe.bind(s),l={getState:s.getState.bind(s),subscribe:s.subscribe.bind(s),createSelectorHook:w.bind(c),createObservable:S.bind(c),dispose:function(){u(),s.dispose()}};return Object.assign(c,l),c}function w(t,e){var n=null==e?void 0:e.name,o=null==e?void 0:e.isEqualRoot,i=null==e?void 0:e.isEqual,a=this.getState(),s=(null!=t?t:function(t){return t})(a),u=new m(s,{name:null!=n?n:(0,g.uniqueId)("sh:")}),c=this.subscribe((function(e){if(!(null!=o?o:Object.is)(a,e)){a=e;var r=t(e);(null!=i?i:Object.is)(s,r)||(s=r,u.setState(r))}}),{skipFirst:!0}),l=function(){return(t=u.use.apply(u,arguments),function(t){if(Array.isArray(t))return t}(t)||function(t){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var r,n,o,i,a=[],s=!0,u=!1;try{for(o=(e=e.call(t)).next;!(s=(r=o.call(e)).done)&&(a.push(r.value),1!==a.length);s=!0);}catch(t){u=!0,n=t}finally{try{if(!s&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(u)throw n}}return a}}(t)||r(t,1)||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.")}())[0];var t},f={getState:function(){return u.getState()},subscribe:u.subscribe.bind(u),createSelectorHook:w.bind(l),createObservable:S.bind(l),dispose:function(){c(),u.dispose()}};return Object.assign(l,f),l}t.GlobalStore=m,t.default=m})(),l})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./uniqueId.js"),require("react"),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(["./uniqueId.js","react","./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("./uniqueId.js"),require("react"),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["./uniqueId.js"],t.react,t["./throwWrongKeyOnActionCollectionConfig.js"],t["./isRecord.js"],t["json-storage-formatter/isFunction"],t["./shallowCompare.js"],t["json-storage-formatter/isNil"]);
@@ -1,5 +1,66 @@
1
1
  import React, { type PropsWithChildren, Context as ReactContext } from 'react';
2
- import type { ActionCollectionConfig, ActionCollectionResult, BaseMetadata, GlobalStoreCallbacks, UseHookOptions, AnyFunction, StateApi, StoreTools, ReadonlyStateApi, SelectHook, ObservableFragment } from './types';
2
+ import type { BaseMetadata, GlobalStoreCallbacks, UseHookOptions, AnyFunction, StoreTools as StoreToolsBase, ReadonlyStateApi, SelectHook, ObservableFragment, StateApi, StoreTools } from './types';
3
+ /**
4
+ * @description Resulting type of the action collection configuration
5
+ */
6
+ export type ContextActionCollectionResult<State, Metadata extends BaseMetadata, ActionsConfig extends ContextActionCollectionConfig<State, Metadata>> = {
7
+ [key in keyof ActionsConfig]: {
8
+ (...params: Parameters<ActionsConfig[key]>): ReturnType<ReturnType<ActionsConfig[key]>>;
9
+ };
10
+ };
11
+ /**
12
+ * contract for the storeActionsConfig configuration
13
+ */
14
+ export interface ContextActionCollectionConfig<State, Metadata extends BaseMetadata, ThisAPI = Record<string, (...parameters: any[]) => unknown>> {
15
+ readonly [key: string]: {
16
+ (this: ThisAPI, ...parameters: any[]): (this: ThisAPI, storeTools: ContextStoreTools<State, Record<string, (...parameters: any[]) => unknown | void>, Metadata>) => unknown | void;
17
+ };
18
+ }
19
+ /**
20
+ * @description Extensions methods for the context store tools
21
+ */
22
+ export type ContextStoreToolsExtensions<State, StateMutator, Metadata extends BaseMetadata> = {
23
+ /**
24
+ * @description Main hook of the context
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * type CounterContext = import('../../stores/counter').CounterContext;
29
+ *
30
+ * const useLogCount = () => {
31
+ * return ({ use }: CounterContext) => {
32
+ * const count = use.select(s => s.count);
33
+ *
34
+ * console.log('Count changed:', count);
35
+ * };
36
+ * }
37
+ *
38
+ * // Usage in store
39
+ * import useLogCount from './actions/useLogCount';
40
+ *
41
+ * const counter = createContext({ count: 0 }, {
42
+ * actions: {
43
+ * useLogCount,
44
+ * }
45
+ * });
46
+ *
47
+ * // Usage in component
48
+ * import counter from '../stores/counter';
49
+ *
50
+ * const CounterLogger = () => {
51
+ * // access to the actions is NOT-REACTIVE
52
+ * const { useLogCount } = counter.use.actions();
53
+ *
54
+ * useLogCount();
55
+ * }
56
+ * ```
57
+ */
58
+ use: ContextHook<State, StateMutator, Metadata>;
59
+ };
60
+ /**
61
+ * @description Store tools specialized for context usage
62
+ */
63
+ export type ContextStoreTools<State, StateMutator, Metadata extends BaseMetadata> = StoreToolsBase<State, StateMutator, Metadata> & ContextStoreToolsExtensions<State, StateMutator, Metadata>;
3
64
  /**
4
65
  * @description Extensions methods for the ContextProvider component
5
66
  */
@@ -309,7 +370,7 @@ interface CreateContext {
309
370
  * - **`Context`** — The raw React `Context` object for advanced usage, such as integration with
310
371
  * external tools or non-React consumers.
311
372
  */
312
- <State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, StateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(
373
+ <State, Metadata extends BaseMetadata, ActionsConfig extends ContextActionCollectionConfig<State, Metadata> | null | {}, StateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ContextActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(
313
374
  /**
314
375
  * @description Initial state value or initializer function.
315
376
  */
@@ -390,7 +451,7 @@ interface CreateContext {
390
451
  * - **`Context`** — The raw React `Context` object for advanced usage, such as integration with
391
452
  * external tools or non-React consumers.
392
453
  */
393
- <State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>, StateMutator = React.Dispatch<React.SetStateAction<State>>>(
454
+ <State, Metadata extends BaseMetadata, ActionsConfig extends ContextActionCollectionConfig<State, Metadata>, StateMutator = React.Dispatch<React.SetStateAction<State>>>(
394
455
  /**
395
456
  * @description Initial state value or initializer function.
396
457
  */
@@ -445,15 +506,15 @@ interface CreateContext {
445
506
  * // ...
446
507
  * }
447
508
  */
448
- use: ContextHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
509
+ use: ContextHook<State, ContextActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
449
510
  /**
450
511
  * @description Provider for the context
451
512
  */
452
- Provider: ContextProvider<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
513
+ Provider: ContextProvider<State, ContextActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
453
514
  /**
454
515
  * @description Raw React Context object
455
516
  */
456
- Context: ReactContext<ContextHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata> | null>;
517
+ Context: ReactContext<ContextHook<State, ContextActionCollectionResult<State, Metadata, ActionsConfig>, Metadata> | null>;
457
518
  };
458
519
  }
459
520
  /**
@@ -478,5 +539,5 @@ export declare const createContext: CreateContext;
478
539
  * ContextApi<number, React.Dispatch<React.SetStateAction<number>>, BaseMetadata>;
479
540
  * ```
480
541
  */
481
- export type InferContextApi<Context extends ReactContext<ContextHook<any, any, any> | null>> = NonNullable<React.ContextType<Context>> extends ContextHook<infer State, infer StateMutator, infer Metadata> ? StoreTools<State, StateMutator extends AnyFunction ? null : StateMutator, Metadata> : never;
542
+ export type InferContextApi<Context extends ReactContext<ContextHook<any, any, any> | null>> = NonNullable<React.ContextType<Context>> extends ContextHook<infer State, infer StateMutator, infer Metadata> ? ContextStoreTools<State, StateMutator extends AnyFunction ? null : StateMutator, Metadata> : never;
482
543
  export default createContext;
package/createContext.js CHANGED
@@ -1 +1 @@
1
- var e,t;e=this,t=(e,t,r,o)=>(()=>{"use strict";var n={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);function u(e,t){var r=this,a=function(){var n=r.api();return(0,o.useMemo)((function(){return n.createSelectorHook(e,t)}),[n]).apply(void 0,arguments)},i={createSelectorHook:u.bind(a),api:function(){var a=r.api();return(0,o.useMemo)((function(){var r=a.createObservable(e,t);return Object.assign(Object.assign({},a),{getState:function(){return r.getState()},subscribe:r.subscribe.bind(r),createSelectorHook:n.createSelectorHook.bind(r),createObservable:n.createObservable.bind(r)})}),[a])}};return Object.assign(a,i),a}t.createContext=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(0,o.createContext)(null),s=function(u){var s=u.children,l=u.value,c=u.onCreated,v=(0,o.useMemo)((function(){var r,o=function(){return(0,a.isFunction)(e)?e():e},u=(0,i.isNil)(l)?o():(0,a.isFunction)(l)?l(o()):l;return new n.GlobalStore(u,Object.assign(Object.assign({},t),{metadata:null!==(r=(0,a.isFunction)(t.metadata)?t.metadata():t.metadata)&&void 0!==r?r:{}}))}),[]);return(0,o.useEffect)((function(){return function(){var e,t,r,o;null===(t=null===(e=v.callbacks)||void 0===e?void 0:e.onUnMount)||void 0===t||t.call(e,v),null===(o=(r=v).__onUnMountContext)||void 0===o||o.call(r,v),v.dispose()}}),[v]),null==c||c(v.getConfigCallbackParam()),(0,o.createElement)(r.Provider,{value:v.use},s)},l={makeProviderWrapper:function(e){var t={current:void 0};return{wrapper:function(r){var n=r.children;return(0,o.createElement)(s,{value:null==e?void 0:e.value,onCreated:function(r){var o;t.current=r,null===(o=null==e?void 0:e.onCreated)||void 0===o||o.call(e,r)}},n)},context:t}}},c=function(){var e=(0,o.useContext)(r);if(!e)throw new Error("use hook must be used within a ContextProvider");return e.apply(void 0,arguments)},v=function(){var e=(0,o.useContext)(r);if(!e)throw new Error("api hook must be used within a ContextProvider");return e},d={createSelectorHook:u.bind(c),api:v,select:function(){return c.apply(void 0,arguments)[0]},observable:function(){for(var e=v(),t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var a=(0,o.useRef)(r);return a.current=r,(0,o.useMemo)((function(){var t,r,o;return e.createObservable((function(e){return(0,a.current[0])(e)}),{isEqualRoot:Boolean(null===(t=a.current[1])||void 0===t?void 0:t.isEqualRoot)?function(e,t){var r,o=null===(r=a.current[1])||void 0===r?void 0:r.isEqualRoot;return Boolean(o(e,t))}:void 0,isEqual:Boolean(null===(r=a.current[1])||void 0===r?void 0:r.isEqual)?function(e,t){var r,o=null===(r=a.current[1])||void 0===r?void 0:r.isEqual;return Boolean(o(e,t))}:void 0,name:null===(o=a.current[1])||void 0===o?void 0:o.name})}),[e])},actions:function(){return v().actions}};return Object.assign(s,l),Object.assign(c,d),{use:c,Provider:s,Context:r}},t.default=t.createContext},773:e=>{e.exports=r},778:e=>{e.exports=o}},a={};return function e(t){var r=a[t];if(void 0!==r)return r.exports;var o=a[t]={exports:{}};return n[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")):"function"==typeof define&&define.amd?define(["react","json-storage-formatter/isFunction","json-storage-formatter/isNil","./GlobalStore.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")):e["react-hooks-global-states"]=t(e.react,e["json-storage-formatter/isFunction"],e["json-storage-formatter/isNil"],e["./GlobalStore.js"]);
1
+ var e,t;e=this,t=(e,t,r,o)=>(()=>{"use strict";var n={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);function u(e,t){var r=this,a=function(){var n=r.api();return(0,o.useMemo)((function(){return n.createSelectorHook(e,t)}),[n]).apply(void 0,arguments)},i={createSelectorHook:u.bind(a),api:function(){var a=r.api();return(0,o.useMemo)((function(){var r=a.createObservable(e,t);return Object.assign(Object.assign({},a),{getState:function(){return r.getState()},subscribe:r.subscribe.bind(r),createSelectorHook:n.createSelectorHook.bind(r),createObservable:n.createObservable.bind(r)})}),[a])}};return Object.assign(a,i),a}t.createContext=function(e){var t=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[]),r=(0,o.createContext)(null),s=function(u){var s=u.children,l=u.value,v=u.onCreated,d=(0,o.useMemo)((function(){var r,o=function(){return(0,a.isFunction)(e)?e():e},u=(0,i.isNil)(l)?o():(0,a.isFunction)(l)?l(o()):l,s=new n.GlobalStore(u,Object.assign(Object.assign({},t),{metadata:null!==(r=(0,a.isFunction)(t.metadata)?t.metadata():t.metadata)&&void 0!==r?r:{}})),v={use:c};return Object.assign(s.storeTools,v),s}),[]);return(0,o.useEffect)((function(){return function(){var e,t,r,o;null===(t=null===(e=d.callbacks)||void 0===e?void 0:e.onUnMount)||void 0===t||t.call(e,d),null===(o=(r=d).__onUnMountContext)||void 0===o||o.call(r,d),d.dispose()}}),[d]),null==v||v(d.storeTools),(0,o.createElement)(r.Provider,{value:d.use},s)},l={makeProviderWrapper:function(e){var t={current:void 0};return{wrapper:function(r){var n=r.children;return(0,o.createElement)(s,{value:null==e?void 0:e.value,onCreated:function(r){var o;t.current=r,null===(o=null==e?void 0:e.onCreated)||void 0===o||o.call(e,r)}},n)},context:t}}},c=function(){var e=(0,o.useContext)(r);if(!e)throw new Error("use hook must be used within a ContextProvider");return e.apply(void 0,arguments)},v=function(){var e=(0,o.useContext)(r);if(!e)throw new Error("api hook must be used within a ContextProvider");return e},d={createSelectorHook:u.bind(c),api:v,select:function(){return c.apply(void 0,arguments)[0]},observable:function(){for(var e=v(),t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var a=(0,o.useRef)(r);return a.current=r,(0,o.useMemo)((function(){var t,r,o;return e.createObservable((function(e){return(0,a.current[0])(e)}),{isEqualRoot:Boolean(null===(t=a.current[1])||void 0===t?void 0:t.isEqualRoot)?function(e,t){var r,o=null===(r=a.current[1])||void 0===r?void 0:r.isEqualRoot;return Boolean(o(e,t))}:void 0,isEqual:Boolean(null===(r=a.current[1])||void 0===r?void 0:r.isEqual)?function(e,t){var r,o=null===(r=a.current[1])||void 0===r?void 0:r.isEqual;return Boolean(o(e,t))}:void 0,name:null===(o=a.current[1])||void 0===o?void 0:o.name})}),[e])},actions:function(){return v().actions}};return Object.assign(s,l),Object.assign(c,d),{use:c,Provider:s,Context:r}},t.default=t.createContext},773:e=>{e.exports=r},778:e=>{e.exports=o}},a={};return function e(t){var r=a[t];if(void 0!==r)return r.exports;var o=a[t]={exports:{}};return n[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")):"function"==typeof define&&define.amd?define(["react","json-storage-formatter/isFunction","json-storage-formatter/isNil","./GlobalStore.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")):e["react-hooks-global-states"]=t(e.react,e["json-storage-formatter/isFunction"],e["json-storage-formatter/isNil"],e["./GlobalStore.js"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "12.0.6",
3
+ "version": "14.0.1",
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",