react-hooks-global-states 16.0.0 → 16.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.
Files changed (46) hide show
  1. package/jest.config.js +50 -0
  2. package/package.json +52 -2
  3. package/GlobalStore.cjs +0 -525
  4. package/GlobalStore.d.ts +0 -160
  5. package/GlobalStore.debugProps.cjs +0 -28
  6. package/GlobalStore.debugProps.d.ts +0 -5
  7. package/GlobalStore.debugProps.js +0 -28
  8. package/GlobalStore.debugProps.mjs +0 -7
  9. package/GlobalStore.js +0 -525
  10. package/GlobalStore.mjs +0 -497
  11. package/actions.cjs +0 -61
  12. package/actions.d.ts +0 -32
  13. package/actions.js +0 -61
  14. package/actions.mjs +0 -30
  15. package/bundle.cjs +0 -40
  16. package/bundle.js +0 -40
  17. package/bundle.mjs +0 -19
  18. package/createContext.cjs +0 -253
  19. package/createContext.d.ts +0 -15
  20. package/createContext.js +0 -253
  21. package/createContext.mjs +0 -235
  22. package/createGlobalState.cjs +0 -29
  23. package/createGlobalState.d.ts +0 -7
  24. package/createGlobalState.js +0 -29
  25. package/createGlobalState.mjs +0 -8
  26. package/index.d.ts +0 -9
  27. package/isRecord.cjs +0 -46
  28. package/isRecord.d.ts +0 -2
  29. package/isRecord.js +0 -46
  30. package/isRecord.mjs +0 -15
  31. package/shallowCompare.cjs +0 -115
  32. package/shallowCompare.d.ts +0 -52
  33. package/shallowCompare.js +0 -115
  34. package/shallowCompare.mjs +0 -84
  35. package/throwWrongKeyOnActionCollectionConfig.cjs +0 -41
  36. package/throwWrongKeyOnActionCollectionConfig.d.ts +0 -2
  37. package/throwWrongKeyOnActionCollectionConfig.js +0 -41
  38. package/throwWrongKeyOnActionCollectionConfig.mjs +0 -20
  39. package/types.cjs +0 -18
  40. package/types.d.ts +0 -1250
  41. package/types.js +0 -18
  42. package/types.mjs +0 -0
  43. package/uniqueId.cjs +0 -72
  44. package/uniqueId.d.ts +0 -7
  45. package/uniqueId.js +0 -72
  46. package/uniqueId.mjs +0 -51
package/GlobalStore.d.ts DELETED
@@ -1,160 +0,0 @@
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
- * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
4
- * */
5
- 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>>> {
6
- protected cleanupFunctions: CleanupFunction[];
7
- protected _name: string;
8
- actionsConfig: ActionsConfig | null;
9
- callbacks: GlobalStoreCallbacks<State, PublicStateMutator, Metadata> | null;
10
- metadata: Metadata;
11
- /**
12
- * @description If the actionsConfig is defined, this will be a map of actions that can be used to modify or interact with the state
13
- * */
14
- actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
15
- storeTools: StoreTools<State, PublicStateMutator, Metadata>;
16
- /**
17
- * @description The main hook that will be used to interact with the global state
18
- */
19
- use: StateHook<State, PublicStateMutator, Metadata>;
20
- /**
21
- * @deprecated
22
- * @description Set of subscribers that are listening to state changes
23
- * Useful for debugging purposes... You'll probably not need to use this in your application
24
- */
25
- subscribers: Set<SubscriberParameters>;
26
- state: State;
27
- protected stateCallback?: () => State;
28
- protected metadataCallback?: () => Metadata;
29
- constructor(state: State | (() => State));
30
- constructor(state: State | (() => State), args: {
31
- metadata?: Metadata | (() => Metadata);
32
- callbacks?: GlobalStoreCallbacks<State, PublicStateMutator, Metadata>;
33
- actions?: ActionsConfig;
34
- name?: string;
35
- });
36
- /**
37
- * This method is meant to be overridden by the extended classes
38
- */
39
- protected onInit?: () => void | CleanupFunction;
40
- /**
41
- * This method is meant to be overridden by the extended classes
42
- */
43
- protected onStateChanged?: (args: StateChanges<State>) => void;
44
- /**
45
- * @description
46
- * Initializes the global store, setting up the main hook and actions map if applicable,
47
- */
48
- protected initialize(): Promise<void>;
49
- /**
50
- * set the state for a single subscriber
51
- * validate if the state should be updated by comparing the previous state and the new state
52
- */
53
- protected executeSetStateForSubscriber(subscription: SubscriberParameters, args: {
54
- forceUpdate: boolean | undefined;
55
- newState: State;
56
- currentState: State;
57
- identifier: string | undefined;
58
- }): {
59
- didUpdate: boolean;
60
- };
61
- /**
62
- * set the state and update all the subscribers
63
- * @param {State} newState - The new state to set
64
- * @param {object} options - The options for setting the state
65
- * @param {boolean} [options.forceUpdate] - Whether to force the update even if the state is the same
66
- * @param {string} [options.identifier] - An optional identifier for the state change
67
- * */
68
- setActualStateWithoutValidations(newState: State, { forceUpdate, identifier }: {
69
- forceUpdate?: boolean;
70
- identifier?: string;
71
- }): void;
72
- /**
73
- * Set the value of the metadata property, this is no reactive and will not trigger a re-render
74
- * @param {MetadataSetter<Metadata>} setter - The setter function or the value to set
75
- * */
76
- setMetadata(setter: Parameters<MetadataSetter<Metadata>>[0]): void;
77
- /**
78
- * Returns the metadata [non-reactive additional information associated with the global state]
79
- */
80
- getMetadata(): Metadata;
81
- /**
82
- * Get the current value of the state
83
- */
84
- getState(): State;
85
- /**
86
- * Subscribe an individual callback to state changes
87
- */
88
- subscribe<TDerivate>(...[param1, param2, param3]: [
89
- SubscribeCallback<State> | SelectorCallback<State, TDerivate>,
90
- (SubscribeCallbackConfig<State> | SubscribeCallback<TDerivate>)?,
91
- SubscribeCallbackConfig<State | TDerivate>?
92
- ]): UnsubscribeCallback;
93
- /**
94
- * Adds a subscription object to the subscribers set and returns the unsubscribe function
95
- */
96
- protected subscribeCallback(subscription: SubscriberParameters): () => void;
97
- partialUpdateSubscription(subscription: SubscriberParameters, values: Partial<SubscriberParameters>): void;
98
- /**
99
- * Returns a custom hook that allows to handle a global state
100
- * @returns {[State, StateMutator, Metadata]} - The state, the state setter or the actions map, the metadata
101
- * */
102
- getMainHook(): StateHook<State, PublicStateMutator, Metadata>;
103
- protected reselectIfDependenciesChanged({ subscription, newDependencies, currentDependencies, }: {
104
- subscription: SubscriberParameters;
105
- newDependencies: unknown[] | undefined;
106
- currentDependencies: unknown[] | undefined;
107
- }): void;
108
- createSelectorHook: typeof createSelectorHook;
109
- createObservable: typeof createObservable;
110
- /**
111
- * Returns the state setter or the actions map
112
- * @returns {StateMutator} - The state setter or the actions map
113
- * */
114
- protected getStateOrchestrator(): PublicStateMutator;
115
- /**
116
- * This is the only setState function that should be exposed outside the class
117
- * This is responsible for defining whenever or not the state change should be allowed or prevented
118
- * the function also execute the functions:
119
- * - onStateChanged (if defined) - this function is executed after the state change
120
- * - 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
121
- */
122
- setState(setter: Parameters<React.Dispatch<React.SetStateAction<State>>>[0], { forceUpdate, identifier, }?: {
123
- forceUpdate?: boolean;
124
- identifier?: string;
125
- }): void;
126
- /**
127
- * This creates storeTools and actions map if applicable
128
- * */
129
- getStoreActionsMap(): {
130
- actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
131
- storeTools: StoreTools<State, PublicStateMutator, Metadata>;
132
- };
133
- protected removeSubscriptions(): void;
134
- protected executeCleanupTasks(): void;
135
- dispose(): void;
136
- reset(): void;
137
- reset(state: State, metadata: Metadata): void;
138
- __devtools_getLifeCycleStoreToolsWrapper?: (logsPrefix: string) => StoreTools<State, PublicStateMutator, Metadata>;
139
- __devtools_initialize_getStoreActionsMapWrapped?: () => {
140
- actions: PublicStateMutator extends AnyFunction ? null : PublicStateMutator;
141
- storeTools: StoreTools<State, PublicStateMutator, Metadata>;
142
- };
143
- }
144
- export declare function createObservable<RootState, PublicStateMutator, Metadata extends BaseMetadata, Selected>(this: Pick<ReadonlyStateApi<RootState, PublicStateMutator, Metadata>, 'getState' | 'subscribe'>, selector: (state: RootState) => Selected, options?: {
145
- isEqual?: (current: Selected, next: Selected) => boolean;
146
- isEqualRoot?: (current: RootState, next: RootState) => boolean;
147
- name?: string;
148
- }): ObservableFragment<Selected, PublicStateMutator, Metadata>;
149
- /**
150
- * @description
151
- * Creates a derived hook bound to a selected fragment of the root state.
152
- * The derived hook re-renders only when the selected value changes and
153
- * exposes the same API as the parent state hook.
154
- */
155
- export declare function createSelectorHook<RootState, PublicStateMutator, Metadata extends BaseMetadata, Selected>(this: Pick<ReadonlyStateApi<RootState, PublicStateMutator, Metadata>, 'getState' | 'subscribe'>, selector: (state: RootState) => Selected, options?: {
156
- isEqual?: (current: Selected, next: Selected) => boolean;
157
- isEqualRoot?: (current: RootState, next: RootState) => boolean;
158
- name?: string;
159
- }): ReadonlyHook<Selected, PublicStateMutator, Metadata>;
160
- export default GlobalStore;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/GlobalStore.debugProps.ts
21
- var GlobalStore_debugProps_exports = {};
22
- __export(GlobalStore_debugProps_exports, {
23
- default: () => GlobalStore_debugProps_default
24
- });
25
- module.exports = __toCommonJS(GlobalStore_debugProps_exports);
26
- var debugProps = globalThis;
27
- debugProps.isDevToolsPresent = Boolean(debugProps.REACT_GLOBAL_STATE_HOOK_DEBUG);
28
- var GlobalStore_debugProps_default = debugProps;
@@ -1,5 +0,0 @@
1
- declare const debugProps: typeof globalThis & {
2
- REACT_GLOBAL_STATE_HOOK_DEBUG?: ($this: unknown, args: undefined | {}, invokerStackHash: string) => void;
3
- isDevToolsPresent: boolean;
4
- };
5
- export default debugProps;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/GlobalStore.debugProps.ts
21
- var GlobalStore_debugProps_exports = {};
22
- __export(GlobalStore_debugProps_exports, {
23
- default: () => GlobalStore_debugProps_default
24
- });
25
- module.exports = __toCommonJS(GlobalStore_debugProps_exports);
26
- var debugProps = globalThis;
27
- debugProps.isDevToolsPresent = Boolean(debugProps.REACT_GLOBAL_STATE_HOOK_DEBUG);
28
- var GlobalStore_debugProps_default = debugProps;
@@ -1,7 +0,0 @@
1
- // src/GlobalStore.debugProps.ts
2
- var debugProps = globalThis;
3
- debugProps.isDevToolsPresent = Boolean(debugProps.REACT_GLOBAL_STATE_HOOK_DEBUG);
4
- var GlobalStore_debugProps_default = debugProps;
5
- export {
6
- GlobalStore_debugProps_default as default
7
- };