react-hooks-global-states 15.0.9 → 15.0.12
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 +39 -25
- package/GlobalStore.js +1 -1
- package/README.md +1438 -177
- package/README.proposal.md +1191 -0
- package/actions.d.ts +32 -0
- package/actions.js +1 -0
- package/bundle.js +1 -1
- package/createContext.d.ts +4 -549
- package/createContext.js +1 -1
- package/createGlobalState.d.ts +1 -191
- package/createGlobalState.js +1 -1
- package/index.d.ts +5 -4
- package/isRecord.js +1 -1
- package/package.json +10 -12
- package/shallowCompare.js +1 -1
- package/throwWrongKeyOnActionCollectionConfig.js +1 -1
- package/types.d.ts +878 -12
- package/uniqueId.d.ts +2 -71
- package/uniqueId.js +1 -1
- package/webpack.config.js +2 -16
package/GlobalStore.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { ActionCollectionConfig, GlobalStoreCallbacks, ActionCollectionResult, MetadataSetter, SubscriberParameters, StateHook, BaseMetadata, StateChanges, StoreTools, ObservableFragment, AnyFunction, ReadonlyHook, ReadonlyStateApi,
|
|
1
|
+
import type { ActionCollectionConfig, GlobalStoreCallbacks, ActionCollectionResult, MetadataSetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, StateHook, BaseMetadata, StateChanges, StoreTools, ObservableFragment, UnsubscribeCallback, AnyFunction, ReadonlyHook, ReadonlyStateApi, CleanupFunction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A unique symbol used as a default value placeholder.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT: unique symbol;
|
|
2
6
|
/**
|
|
3
7
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
4
8
|
* */
|
|
5
9
|
export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> {
|
|
10
|
+
protected cleanupFunctions: CleanupFunction[];
|
|
6
11
|
protected _name: string;
|
|
7
12
|
actionsConfig: ActionsConfig | null;
|
|
8
13
|
callbacks: GlobalStoreCallbacks<State, PublicStateMutator, Metadata> | null;
|
|
@@ -23,9 +28,11 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
23
28
|
*/
|
|
24
29
|
subscribers: Set<SubscriberParameters>;
|
|
25
30
|
state: State;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
protected stateCallback?: () => State;
|
|
32
|
+
protected metadataCallback?: () => Metadata;
|
|
33
|
+
constructor(state: State | (() => State));
|
|
34
|
+
constructor(state: State | (() => State), args: {
|
|
35
|
+
metadata?: Metadata | (() => Metadata);
|
|
29
36
|
callbacks?: GlobalStoreCallbacks<State, PublicStateMutator, Metadata>;
|
|
30
37
|
actions?: ActionsConfig;
|
|
31
38
|
name?: string;
|
|
@@ -33,7 +40,7 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
33
40
|
/**
|
|
34
41
|
* This method is meant to be overridden by the extended classes
|
|
35
42
|
*/
|
|
36
|
-
protected onInit?: () => void;
|
|
43
|
+
protected onInit?: () => void | CleanupFunction;
|
|
37
44
|
/**
|
|
38
45
|
* This method is meant to be overridden by the extended classes
|
|
39
46
|
*/
|
|
@@ -42,17 +49,17 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
42
49
|
* @description
|
|
43
50
|
* Initializes the global store, setting up the main hook and actions map if applicable,
|
|
44
51
|
*/
|
|
45
|
-
protected initialize
|
|
52
|
+
protected initialize(): Promise<void>;
|
|
46
53
|
/**
|
|
47
54
|
* set the state for a single subscriber
|
|
48
55
|
* validate if the state should be updated by comparing the previous state and the new state
|
|
49
56
|
*/
|
|
50
|
-
protected executeSetStateForSubscriber
|
|
57
|
+
protected executeSetStateForSubscriber(subscription: SubscriberParameters, args: {
|
|
51
58
|
forceUpdate: boolean | undefined;
|
|
52
59
|
newState: State;
|
|
53
60
|
currentState: State;
|
|
54
61
|
identifier: string | undefined;
|
|
55
|
-
})
|
|
62
|
+
}): {
|
|
56
63
|
didUpdate: boolean;
|
|
57
64
|
};
|
|
58
65
|
/**
|
|
@@ -62,49 +69,53 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
62
69
|
* @param {boolean} [options.forceUpdate] - Whether to force the update even if the state is the same
|
|
63
70
|
* @param {string} [options.identifier] - An optional identifier for the state change
|
|
64
71
|
* */
|
|
65
|
-
setActualStateWithoutValidations
|
|
72
|
+
setActualStateWithoutValidations(newState: State, { forceUpdate, identifier }: {
|
|
66
73
|
forceUpdate?: boolean;
|
|
67
74
|
identifier?: string;
|
|
68
|
-
})
|
|
75
|
+
}): void;
|
|
69
76
|
/**
|
|
70
77
|
* Set the value of the metadata property, this is no reactive and will not trigger a re-render
|
|
71
78
|
* @param {MetadataSetter<Metadata>} setter - The setter function or the value to set
|
|
72
79
|
* */
|
|
73
|
-
setMetadata: MetadataSetter<Metadata
|
|
80
|
+
setMetadata(setter: Parameters<MetadataSetter<Metadata>>[0]): void;
|
|
74
81
|
/**
|
|
75
82
|
* Returns the metadata [non-reactive additional information associated with the global state]
|
|
76
83
|
*/
|
|
77
|
-
getMetadata
|
|
84
|
+
getMetadata(): Metadata;
|
|
78
85
|
/**
|
|
79
86
|
* Get the current value of the state
|
|
80
87
|
*/
|
|
81
|
-
getState
|
|
88
|
+
getState(): State;
|
|
82
89
|
/**
|
|
83
90
|
* Subscribe an individual callback to state changes
|
|
84
91
|
*/
|
|
85
|
-
subscribe:
|
|
92
|
+
subscribe<TDerivate>(...[param1, param2, param3]: [
|
|
93
|
+
SubscribeCallback<State> | SelectorCallback<State, TDerivate>,
|
|
94
|
+
(SubscribeCallbackConfig<State> | SubscribeCallback<TDerivate>)?,
|
|
95
|
+
SubscribeCallbackConfig<State | TDerivate>?
|
|
96
|
+
]): UnsubscribeCallback;
|
|
86
97
|
/**
|
|
87
98
|
* Adds a subscription object to the subscribers set and returns the unsubscribe function
|
|
88
99
|
*/
|
|
89
|
-
protected subscribeCallback
|
|
90
|
-
partialUpdateSubscription
|
|
100
|
+
protected subscribeCallback(subscription: SubscriberParameters): () => void;
|
|
101
|
+
partialUpdateSubscription(subscription: SubscriberParameters, values: Partial<SubscriberParameters>): void;
|
|
91
102
|
/**
|
|
92
103
|
* Returns a custom hook that allows to handle a global state
|
|
93
104
|
* @returns {[State, StateMutator, Metadata]} - The state, the state setter or the actions map, the metadata
|
|
94
105
|
* */
|
|
95
|
-
getMainHook
|
|
96
|
-
protected reselectIfDependenciesChanged
|
|
106
|
+
getMainHook(): StateHook<State, PublicStateMutator, Metadata>;
|
|
107
|
+
protected reselectIfDependenciesChanged({ subscription, newDependencies, currentDependencies, }: {
|
|
97
108
|
subscription: SubscriberParameters;
|
|
98
109
|
newDependencies: unknown[] | undefined;
|
|
99
110
|
currentDependencies: unknown[] | undefined;
|
|
100
|
-
})
|
|
111
|
+
}): void;
|
|
101
112
|
createSelectorHook: typeof createSelectorHook;
|
|
102
113
|
createObservable: typeof createObservable;
|
|
103
114
|
/**
|
|
104
115
|
* Returns the state setter or the actions map
|
|
105
116
|
* @returns {StateMutator} - The state setter or the actions map
|
|
106
117
|
* */
|
|
107
|
-
protected getStateOrchestrator
|
|
118
|
+
protected getStateOrchestrator(): PublicStateMutator;
|
|
108
119
|
/**
|
|
109
120
|
* This is the only setState function that should be exposed outside the class
|
|
110
121
|
* This is responsible for defining whenever or not the state change should be allowed or prevented
|
|
@@ -112,19 +123,22 @@ export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsCo
|
|
|
112
123
|
* - onStateChanged (if defined) - this function is executed after the state change
|
|
113
124
|
* - computePreventStateChange (if defined) - this function is executed before the state change and it should return a boolean value that will be used to determine if the state change should be prevented or not
|
|
114
125
|
*/
|
|
115
|
-
setState
|
|
126
|
+
setState(setter: Parameters<React.Dispatch<React.SetStateAction<State>>>[0], { forceUpdate, identifier, }?: {
|
|
116
127
|
forceUpdate?: boolean;
|
|
117
128
|
identifier?: string;
|
|
118
|
-
})
|
|
129
|
+
}): void;
|
|
119
130
|
/**
|
|
120
131
|
* This creates storeTools and actions map if applicable
|
|
121
132
|
* */
|
|
122
|
-
getStoreActionsMap
|
|
133
|
+
getStoreActionsMap(): {
|
|
123
134
|
actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
|
|
124
135
|
storeTools: StoreTools<State, PublicStateMutator, Metadata>;
|
|
125
136
|
};
|
|
126
|
-
protected removeSubscriptions
|
|
127
|
-
|
|
137
|
+
protected removeSubscriptions(): void;
|
|
138
|
+
protected executeCleanupTasks(): void;
|
|
139
|
+
dispose(): void;
|
|
140
|
+
reset(): void;
|
|
141
|
+
reset(state: State, metadata: Metadata): void;
|
|
128
142
|
__devtools_getLifeCycleStoreToolsWrapper?: (logsPrefix: string) => StoreTools<State, PublicStateMutator, Metadata>;
|
|
129
143
|
__devtools_initialize_getStoreActionsMapWrapped?: () => {
|
|
130
144
|
actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
|
package/GlobalStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e;t=this,e=(t,e,r,n,o,i)=>(()=>{"use strict";var a={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},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var r=globalThis;r.isDevToolsPresent=Boolean(r.REACT_GLOBAL_STATE_HOOK_DEBUG),e.default=r}},s={};function u(t){var e=s[t];if(void 0!==e)return e.exports;var r=s[t]={exports:{}};return a[t](r,r.exports,u),r.exports}var c={};return(()=>{var t=c;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 P(n||[]);return a(i,"_invoke",{value:C(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",y="completed",g={};function m(){}function S(){}function w(){}var j={};f(j,u,(function(){return this}));var O=Object.getPrototypeOf,x=O&&O(O(q([])));x&&x!==n&&i.call(x,u)&&(j=x);var E=w.prototype=m.prototype=Object.create(j);function _(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function k(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 C(e,r,n){var o=v;return function(i,a){if(o===b)throw Error("Generator is already running");if(o===y){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=L(s,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=y,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?y:p,c.arg===g)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=y,n.method="throw",n.arg=c.arg)}}}function L(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,L(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;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,g):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function q(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(E,"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(E),t},r.awrap=function(t){return{__await:t}},_(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(d(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(E),f(E,l,"Generator"),f(E,u,(function(){return this})),f(E,"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=q,P.prototype={constructor:P,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(T),!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,g):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),g},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),T(r),g}},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;T(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:q(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},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+""}var l,f=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]},d=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e},h=(l=function(t){return l=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},l(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=l(t),n=0;n<r.length;n++)"default"!==r[n]&&f(e,t,r[n]);return d(e,t),e}),v=function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0,t.createObservable=O,t.createSelectorHook=x;var p=u(155),b=v(u(506)),y=v(u(487)),g=h(u(673)),m=v(u(361)),S=v(u(78)),w=v(u(811)),j=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,c,l,f,d,h;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u=null!==(r=null===(e=this.__devtools_initialize_getStoreActionsMapWrapped)||void 0===e?void 0:e.call(this))&&void 0!==r?r:this.getStoreActionsMap(),c=u.actions,l=u.storeTools,this.actions=c,this.storeTools=l,this.use=this.getMainHook(),null===(n=this.onInit)||void 0===n||n.call(this),f=null!==(i=this.callbacks)&&void 0!==i?i:{},d=f.onInit){t.next=9;break}return t.abrupt("return");case 9:h=null!==(s=null===(a=this.__devtools_getLifeCycleStoreToolsWrapper)||void 0===a?void 0:a.call(this,"config/onInit/"))&&void 0!==s?s:l,null==d||d(h);case 11: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=t.selector,n=t.onStoreChange,o=t.currentState,i=t.isEqualRoot,s=void 0===i?function(t,e){return t===e}:i,u=t.isEqual,c=void 0===u?function(t,e){return t===e}:u;if(!e.forceUpdate&&s(e.currentState,e.newState))return{didUpdate:!1};var l=r?r(e.newState):e.newState;return!e.forceUpdate&&c(o,l)?{didUpdate:!1}:(a.partialUpdateSubscription(t,{currentState:l}),n({state:l},{identifier:e.identifier}),{didUpdate:!0})},this.setActualStateWithoutValidations=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,b.default)(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,b.default)(i),c=u?o:void 0,l=u?i:o,f=null!==(n=u?s:i)&&void 0!==n?n:void 0,d=c?c(a.state):a.state;(null==f?void 0:f.skipFirst)||l(d);var h=Object.assign({selector:c,currentState:d,onStoreChange:function(t){var e=t.state;return l(e)}},f);return a.subscribeCallback(h),function(){a.subscribers.delete(h)}},this.subscribeCallback=function(t){var e,r;return null===(r=null===(e=a.callbacks)||void 0===e?void 0:e.onSubscribed)||void 0===r||r.call(e,a.storeTools,t),a.subscribers.add(t),function(){a.subscribers.delete(t)}},this.partialUpdateSubscription=function(t,e){Object.assign(t,e)},this.getMainHook=function(){var t="globalHook:".concat(a._name),e=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];(0,p.useDebugValue)(t);var n=(0,g.isArray)(r)?{dependencies:r}:null!=r?r:{},o=(0,p.useRef)(null),i=function(t){return(0,b.default)(e)?e(t):t};o.current=o.current?o.current:Object.assign({selector:i,currentState:i(a.state),onStoreChange:function(){throw new Error("Callback not set")}},n);var s=o.current.dependencies,u=null==n?void 0:n.dependencies,c=Object.assign(Object.assign({},n),{selector:i,dependencies:u});a.partialUpdateSubscription(o.current,c);var l=(0,p.useMemo)((function(){var t=function(){return o.current.currentState};return{subscribe:function(t){return o.current.onStoreChange=t,a.subscribeCallback(o.current)},getSnapshot:t,getServerSnapshot:t}}),[]),f=l.subscribe,d=l.getSnapshot,h=l.getServerSnapshot;return a.reselectIfDependenciesChanged({subscription:o.current,newDependencies:u,currentDependencies:s}),[(0,p.useSyncExternalStore)(f,d,h),a.getStateOrchestrator(),a.metadata]},r=a.setMetadata,n=a.getMetadata,o=a.actions,i=a.actions?null:a.setState.bind(a),s=a,u={actions:o,createObservable:a.createObservable.bind(s),createSelectorHook:a.createSelectorHook.bind(s),dispose:a.dispose.bind(a),getMetadata:n,getState:a.getState.bind(a),setMetadata:r,setState:i,subscribe:a.subscribe.bind(a),subscribers:a.subscribers,use:e,select:function(){return e.apply(void 0,arguments)[0]}};return Object.assign(e,u),e},this.reselectIfDependenciesChanged=function(t){var e=t.subscription,r=t.newDependencies,n=t.currentDependencies;e.selector&&n!==r&&((null==n?void 0:n.length)===(null==r?void 0:r.length)&&(0,g.default)(n,r)||a.partialUpdateSubscription(e,{currentState:e.selector(a.state)}))},this.createSelectorHook=x,this.createObservable=O,this.getStateOrchestrator=function(){return a.actions?a.actions:a.setState},this.setState=function(t){var e,r,n,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=i.forceUpdate,u=i.identifier,c=a.state,l=(0,b.default)(t)?t(c):t;if(s||a.state!==l){var f=a.setActualStateWithoutValidations,d={previousState:c,state:l,identifier:u},h=Object.assign(Object.assign(Object.assign({},a.storeTools),d),{setState:f});if((null===(e=a.callbacks)||void 0===e?void 0:e.computePreventStateChange)&&(null===(n=null===(r=a.callbacks)||void 0===r?void 0:r.computePreventStateChange)||void 0===n?void 0:n.call(r,h)))return;a.setActualStateWithoutValidations(l,{forceUpdate:s,identifier:u});var v=a.onStateChanged,p=null===(o=a.callbacks)||void 0===o?void 0:o.onStateChanged;null==v||v(h),null==p||p(h)}},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,y.default)(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,m.default)(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()};var c=u.metadata,l=u.callbacks,f=u.actions,d=u.name;if(this.state=e,this._name=null!=d?d:(0,S.default)("gs:"),this.metadata=null!=c?c:{},this.callbacks=null!=l?l:null,this.actionsConfig=null!=f?f:null,w.default.isDevToolsPresent){var h=null!==(n=(new Error).stack)&&void 0!==n?n:"";null===(i=w.default.REACT_GLOBAL_STATE_HOOK_DEBUG)||void 0===i||i.call(w.default,this,u,h)}this.constructor!==t||this.initialize()}));function O(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 j(a,{name:null!=r?r:(0,S.default)("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:x.bind(c),createObservable:O.bind(c),dispose:function(){u(),s.dispose()},subscribers:s.subscribers};return Object.assign(c,l),c}function x(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 j(s,{name:null!=n?n:(0,S.default)("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:x.bind(l),createObservable:O.bind(l),dispose:function(){c(),u.dispose()},subscribers:u.subscribers};return Object.assign(l,f),l}t.GlobalStore=j,t.default=j})(),c})(),"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")):"function"==typeof define&&define.amd?define(["./uniqueId.js","react","./throwWrongKeyOnActionCollectionConfig.js","./isRecord.js","json-storage-formatter/isFunction","./shallowCompare.js"],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")):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"]);
|
|
1
|
+
var t,e;t=this,e=(t,e,s,i,n,a)=>(()=>{"use strict";var o={78:e=>{e.exports=t},132:function(t,e,s){var i,n=this&&this.__createBinding||(Object.create?function(t,e,s,i){void 0===i&&(i=s);var n=Object.getOwnPropertyDescriptor(e,s);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[s]}}),Object.defineProperty(t,i,n)}:function(t,e,s,i){void 0===i&&(i=s),t[i]=e[s]}),a=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||(i=function(t){return i=Object.getOwnPropertyNames||function(t){var e=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[e.length]=s);return e},i(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var s=i(t),o=0;o<s.length;o++)"default"!==s[o]&&n(e,t,s[o]);return a(e,t),e}),r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStore=void 0,e.createObservable=v,e.createSelectorHook=g;const l=s(155),c=r(s(506)),u=r(s(487)),d=o(s(673)),h=r(s(361)),b=r(s(78)),p=r(s(627));class f{constructor(t,e={metadata:{}}){var s,i;this.cleanupFunctions=[],this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Set,this.createSelectorHook=g,this.createObservable=v;const{metadata:n,callbacks:a,actions:o,name:r}=e;if((0,c.default)(t)&&(this.stateCallback=t),(0,c.default)(n)&&(this.metadataCallback=n),this._name=null!=r?r:(0,b.default)("gs:"),this.state=this.stateCallback?this.stateCallback():t,this.metadata=this.metadataCallback?this.metadataCallback():null!=n?n:{},this.callbacks=null!=a?a:null,this.actionsConfig=null!=o?o:null,p.default.isDevToolsPresent){const t=null!==(s=(new Error).stack)&&void 0!==s?s:"";null===(i=p.default.REACT_GLOBAL_STATE_HOOK_DEBUG)||void 0===i||i.call(p.default,this,e,t)}this.constructor!==f||this.initialize()}async initialize(){var t,e,s,i,n,a,o,r;const l=null!==(e=null===(t=this.__devtools_initialize_getStoreActionsMapWrapped)||void 0===t?void 0:t.call(this))&&void 0!==e?e:this.getStoreActionsMap(),{actions:u,storeTools:d}=l;this.actions=u,this.storeTools=d,this.use=this.getMainHook();const h=null!==(i=null===(s=this.onInit)||void 0===s?void 0:s.call(this))&&void 0!==i?i:null;(0,c.default)(h)&&this.cleanupFunctions.push(h);const{onInit:b}=null!==(n=this.callbacks)&&void 0!==n?n:{};if(!b)return;const p=null!==(o=null===(a=this.__devtools_getLifeCycleStoreToolsWrapper)||void 0===a?void 0:a.call(this,"config/onInit/"))&&void 0!==o?o:d,f=null!==(r=null==b?void 0:b(p))&&void 0!==r?r:null;(0,c.default)(f)&&this.cleanupFunctions.push(f)}executeSetStateForSubscriber(t,e){const{selector:s,onStoreChange:i,currentState:n,isEqualRoot:a=(t,e)=>t===e,isEqual:o=(t,e)=>t===e}=t;if(!e.forceUpdate&&a(e.currentState,e.newState))return{didUpdate:!1};const r=s?s(e.newState):e.newState;return!e.forceUpdate&&o(n,r)?{didUpdate:!1}:(this.partialUpdateSubscription(t,{currentState:r}),i({state:r},{identifier:e.identifier}),{didUpdate:!0})}setActualStateWithoutValidations(t,{forceUpdate:e,identifier:s}){const i=this.state;if(!e&&i===t)return;this.state=t;const n=this.subscribers.values(),a={forceUpdate:e,newState:t,currentState:i,identifier:s};for(const t of n)this.executeSetStateForSubscriber(t,a)}setMetadata(t){const e=(0,c.default)(t)?t(this.metadata):t;this.metadata=e}getMetadata(){return this.metadata}getState(){return this.state}subscribe(...[t,e,s]){var i;const n=(0,c.default)(e),a=n?t:void 0,o=n?e:t,r=null!==(i=n?s:e)&&void 0!==i?i:void 0,l=a?a(this.state):this.state;(null==r?void 0:r.skipFirst)||o(l);const u=Object.assign({selector:a,currentState:l,onStoreChange:({state:t})=>o(t)},r);return this.subscribeCallback(u),()=>{this.subscribers.delete(u)}}subscribeCallback(t){var e,s;return null===(s=null===(e=this.callbacks)||void 0===e?void 0:e.onSubscribed)||void 0===s||s.call(e,this.storeTools,t),this.subscribers.add(t),()=>{this.subscribers.delete(t)}}partialUpdateSubscription(t,e){Object.assign(t,e)}getMainHook(){const t=`globalHook:${this._name}`,e=(e,s=[])=>{(0,l.useDebugValue)(t);const i=(0,d.isArray)(s)?{dependencies:s}:null!=s?s:{},n=(0,l.useRef)(null),a=t=>(0,c.default)(e)?e(t):t;n.current=(()=>n.current?n.current:Object.assign({selector:a,currentState:a(this.state),onStoreChange:()=>{throw new Error("Callback not set")}},i))();const o=n.current.dependencies,r=null==i?void 0:i.dependencies,u=Object.assign(Object.assign({},i),{selector:a,dependencies:r});this.partialUpdateSubscription(n.current,u);const{subscribe:h,getSnapshot:b,getServerSnapshot:p}=(0,l.useMemo)((()=>{const t=()=>n.current.currentState;return{subscribe:t=>(n.current.onStoreChange=t,this.subscribeCallback(n.current)),getSnapshot:t,getServerSnapshot:t}}),[]);return this.reselectIfDependenciesChanged({subscription:n.current,newDependencies:r,currentDependencies:o}),[(0,l.useSyncExternalStore)(h,b,p),this.getStateOrchestrator(),this.metadata]},s={actions:this.actions,createObservable:this.createObservable.bind(this),createSelectorHook:this.createSelectorHook.bind(this),dispose:this.dispose.bind(this),getMetadata:this.getMetadata.bind(this),getState:this.getState.bind(this),reset:this.reset.bind(this),setMetadata:this.setMetadata.bind(this),setState:this.setState.bind(this),subscribe:this.subscribe.bind(this),subscribers:this.subscribers,use:e,select:(...t)=>e(...t)[0]};return Object.assign(e,s),e}reselectIfDependenciesChanged({subscription:t,newDependencies:e,currentDependencies:s}){t.selector&&s!==e&&((null==s?void 0:s.length)===(null==e?void 0:e.length)&&(0,d.default)(s,e)||this.partialUpdateSubscription(t,{currentState:t.selector(this.state)}))}getStateOrchestrator(){return(()=>this.actions?this.actions:this.setState.bind(this))()}setState(t,{forceUpdate:e,identifier:s}={}){var i,n,a,o,r,l;const u=this.state,d=(0,c.default)(t)?t(u):t;if(!e&&this.state===d)return;const h=this.setActualStateWithoutValidations,b={previousState:u,state:d,identifier:s},p=Object.assign(Object.assign(Object.assign({},this.storeTools),b),{setState:h});(null===(i=this.callbacks)||void 0===i?void 0:i.computePreventStateChange)&&(null===(a=null===(n=this.callbacks)||void 0===n?void 0:n.computePreventStateChange)||void 0===a?void 0:a.call(n,p))||(this.setActualStateWithoutValidations(d,{forceUpdate:e,identifier:s}),null===(o=this.onStateChanged)||void 0===o||o.call(this,p),null===(l=null===(r=this.callbacks)||void 0===r?void 0:r.onStateChanged)||void 0===l||l.call(r,p))}getStoreActionsMap(){const t={setMetadata:this.setMetadata.bind(this),getMetadata:this.getMetadata.bind(this),getState:this.getState.bind(this),setState:this.setState.bind(this),subscribe:this.subscribe.bind(this),actions:null};if(!(0,u.default)(this.actionsConfig))return{actions:null,storeTools:t};const e=this.actionsConfig,s={};t.actions=s;const i=Object.keys(e);for(const n of i)Object.assign(s,{[n](...i){const a=e[n].apply(s,i);return"function"!=typeof a&&(0,h.default)(n),a.call(s,t)}});return{actions:s,storeTools:t}}removeSubscriptions(){this.subscribers.clear()}executeCleanupTasks(){this.cleanupFunctions.forEach((t=>{null==t||t()})),this.cleanupFunctions.length=0}dispose(){this.removeSubscriptions(),this.executeCleanupTasks()}reset(t,s){var i,n,a,o,r,l;this.executeCleanupTasks();const u=(()=>t===e.DEFAULT?this.state:this.stateCallback?this.stateCallback():t)(),d=(()=>s===e.DEFAULT?this.metadata:this.metadataCallback?this.metadataCallback():s)();this.setActualStateWithoutValidations(u,{forceUpdate:!0}),this.metadata=d;const h=null!==(n=null===(i=this.onInit)||void 0===i?void 0:i.call(this))&&void 0!==n?n:null;(0,c.default)(h)&&this.cleanupFunctions.push(h);const{onInit:b}=null!==(a=this.callbacks)&&void 0!==a?a:{};if(!b)return;const p=null!==(r=null===(o=this.__devtools_getLifeCycleStoreToolsWrapper)||void 0===o?void 0:o.call(this,"config/onInit/"))&&void 0!==r?r:this.storeTools,f=null!==(l=null==b?void 0:b(p))&&void 0!==l?l:null;(0,c.default)(f)&&this.cleanupFunctions.push(f)}}function v(t,e){const s=null==e?void 0:e.name,i=null==e?void 0:e.isEqualRoot,n=null==e?void 0:e.isEqual;let a=this.getState(),o=(null!=t?t:t=>t)(a);const r=new f(o,{name:null!=s?s:(0,b.default)("sh:")}),l=this.subscribe((e=>{if((null!=i?i:Object.is)(a,e))return;a=e;const s=t(e);(null!=n?n:Object.is)(o,s)||(o=s,r.setState(s))}),{skipFirst:!0}),c=r.subscribe.bind(r),u={getState:r.getState.bind(r),subscribe:r.subscribe.bind(r),createSelectorHook:g.bind(c),createObservable:v.bind(c),dispose:()=>{l(),r.dispose()},subscribers:r.subscribers};return Object.assign(c,u),c}function g(t,e){const s=null==e?void 0:e.name,i=null==e?void 0:e.isEqualRoot,n=null==e?void 0:e.isEqual;let a=this.getState(),o=(null!=t?t:t=>t)(a);const r=new f(o,{name:null!=s?s:(0,b.default)("sh:")}),l=this.subscribe((e=>{if((null!=i?i:Object.is)(a,e))return;a=e;const s=t(e);(null!=n?n:Object.is)(o,s)||(o=s,r.setState(s))}),{skipFirst:!0}),c=(...t)=>{const[e]=r.use(...t);return e},u={getState:()=>r.getState(),subscribe:r.subscribe.bind(r),createSelectorHook:g.bind(c),createObservable:v.bind(c),dispose:()=>{l(),r.dispose()},subscribers:r.subscribers};return Object.assign(c,u),c}e.GlobalStore=f,e.default=f},155:t=>{t.exports=e},361:t=>{t.exports=s},487:t=>{t.exports=i},506:t=>{t.exports=n},627:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});const s=globalThis;s.isDevToolsPresent=Boolean(s.REACT_GLOBAL_STATE_HOOK_DEBUG),e.default=s},673:t=>{t.exports=a}},r={};return function t(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}};return o[e].call(i.exports,i,i.exports,t),i.exports}(132)})(),"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")):"function"==typeof define&&define.amd?define(["./uniqueId.js","react","./throwWrongKeyOnActionCollectionConfig.js","./isRecord.js","json-storage-formatter/isFunction","./shallowCompare.js"],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")):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"]);
|