react-hooks-global-states 1.0.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ setter: TState | ((state: TState) => TState),
26
26
  * The hook to use the global state
27
27
  * @returns {[State, StateSetter<TState>, TMetadata]} result - the state, the setter and the metadata
28
28
  */
29
- export type StateHook<TState, TSetter, TMetadata> = <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State, setter: TSetter, metadata: TMetadata];
29
+ export type StateHook<TState, TSetter, TMetadata> = <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State, stateMutator: TSetter, metadata: TMetadata];
30
30
  /**
31
31
  * @description
32
32
  * Type that prevent ts issues with merging never with other types
@@ -113,7 +113,7 @@ export interface ActionCollectionConfig<TState, TMetadata = null> {
113
113
  * whatever data manipulation of the state should be executed through the custom actions with as access to the state and metadata
114
114
  * @template {TState} TState - The state type
115
115
  * @template {TMetadata} TMetadata - The metadata type
116
- * @template {TStateSetter} TStateSetter - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
116
+ * @template {TStateMutator} TStateMutator - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
117
117
  *
118
118
  * @example
119
119
  *
@@ -133,8 +133,8 @@ export interface ActionCollectionConfig<TState, TMetadata = null> {
133
133
  *
134
134
  * console.log(state); // 0
135
135
  */
136
- export type ActionCollectionResult<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = TStateSetter extends ActionCollectionConfig<TState, TMetadata> ? {
137
- [key in keyof TStateSetter]: (...params: Parameters<TStateSetter[key]>) => ReturnType<ReturnType<TStateSetter[key]>>;
136
+ export type ActionCollectionResult<TState, TMetadata, TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = TStateMutator extends ActionCollectionConfig<TState, TMetadata> ? {
137
+ [key in keyof TStateMutator]: (...params: Parameters<TStateMutator[key]>) => ReturnType<ReturnType<TStateMutator[key]>>;
138
138
  } : null;
139
139
  /**
140
140
  * Common parameters of the store configuration callback functions
@@ -145,19 +145,19 @@ export type ActionCollectionResult<TState, TMetadata, TStateSetter extends Actio
145
145
  * @param {ActionCollectionResult<TState, ActionCollectionConfig<TState, TMetadata>> | null} actions - the actions object returned by the hook when you pass an storeActionsConfig configuration otherwise null
146
146
  * @template {TState} TState - The state type
147
147
  * @template {TMetadata} TMetadata - The metadata type
148
- * @template {TStateSetter} TStateSetter - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
149
- * @template {ActionCollectionResult<TState, TStateSetter>} TStateSetter - the result of the API (optional) - if you don't pass an API as a parameter, you can pass null
148
+ * @template {TStateMutator} TStateMutator - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
149
+ * @template {ActionCollectionResult<TState, TStateMutator>} TStateMutator - the result of the API (optional) - if you don't pass an API as a parameter, you can pass null
150
150
  * */
151
- export type StateConfigCallbackParam<TState = any, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
152
- actions: ActionCollectionResult<TState, TMetadata, TStateSetter>;
151
+ export type StateConfigCallbackParam<TState = any, TMetadata = null, TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
152
+ actions: ActionCollectionResult<TState, TMetadata, TStateMutator>;
153
153
  } & StoreTools<TState, TMetadata>;
154
154
  /**
155
155
  * Parameters of the onStateChanged callback function
156
156
  * @template {TState} TState - The state type
157
157
  * @template {TMetadata} TMetadata - The metadata type
158
- * @template {TStateSetter} TStateSetter - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
158
+ * @template {TStateMutator} TStateMutator - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
159
159
  */
160
- export type StateChangesParam<TState = any, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = StateConfigCallbackParam<TState, TMetadata, TStateSetter> & StateChanges<TState>;
160
+ export type StateChangesParam<TState = any, TMetadata = null, TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = StateConfigCallbackParam<TState, TMetadata, TStateMutator> & StateChanges<TState>;
161
161
  /**
162
162
  * Configuration of the store (optional) - if you don't need to use the store configuration you don't need to pass this parameter
163
163
  * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
@@ -166,9 +166,9 @@ export type StateChangesParam<TState = any, TMetadata = null, TStateSetter exten
166
166
  * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
167
167
  * @template TState - the type of the state
168
168
  * @template TMetadata - the type of the metadata (optional) - if you don't pass an metadata as a parameter, you can pass null
169
- * @template {ActionCollectionConfig<TState,TMetadata> | null} TStateSetter - the configuration of the API (optional) - if you don't pass an API as a parameter, you can pass null
169
+ * @template {ActionCollectionConfig<TState,TMetadata> | null} TStateMutator - the configuration of the API (optional) - if you don't pass an API as a parameter, you can pass null
170
170
  * */
171
- export type GlobalStoreConfig<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
171
+ export type GlobalStoreConfig<TState, TMetadata, TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
172
172
  /**
173
173
  * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
174
174
  * */
@@ -177,22 +177,22 @@ export type GlobalStoreConfig<TState, TMetadata, TStateSetter extends ActionColl
177
177
  * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
178
178
  * @returns {void} result - void
179
179
  * */
180
- onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
180
+ onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateMutator>) => void;
181
181
  /**
182
182
  * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
183
183
  * @returns {void} result - void
184
184
  */
185
- onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
185
+ onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TStateMutator>) => void;
186
186
  /**
187
187
  * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
188
188
  * @returns {void} result - void
189
189
  */
190
- onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
190
+ onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateMutator>) => void;
191
191
  /**
192
192
  * @param {StateChangesParam<TState, TMetadata> => boolean} computePreventStateChange - callback function called every time the state is about to change and it allows you to prevent the state change
193
193
  * @returns {boolean} result - true if you want to prevent the state change, false otherwise
194
194
  */
195
- computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => boolean;
195
+ computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TStateMutator>) => boolean;
196
196
  } | null;
197
197
  export type UseHookConfig<TState> = {
198
198
  /**
@@ -200,6 +200,8 @@ export type UseHookConfig<TState> = {
200
200
  * If the function is not provided the derived state will perform a shallow comparison
201
201
  */
202
202
  isEqual?: (current: TState, next: TState) => boolean;
203
+ isEqualRoot?: (current: any, next: any) => boolean;
204
+ dependencies?: unknown[];
203
205
  };
204
206
  /**
205
207
  * Callback function to unsubscribe from the store
@@ -261,7 +263,7 @@ export type CustomGlobalHookBuilderParams<TInheritMetadata = null, TCustomConfig
261
263
  * @description
262
264
  * This function is called when the state is changed.
263
265
  */
264
- onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<any, TInheritMetadata>, config: TCustomConfig) => void;
266
+ onChange: ({ setState, setMetadata, getMetadata, getState, actions }: StateChangesParam<any, TInheritMetadata>, config: TCustomConfig) => void;
265
267
  };
266
268
  /**
267
269
  * @description
@@ -1,15 +1,15 @@
1
- import { StateSetter, StateConfigCallbackParam, StateChangesParam, ActionCollectionConfig, GlobalStoreConfig } from "./GlobalStore.types";
2
- import { GlobalStore } from "./GlobalStore";
1
+ import { StateSetter, StateConfigCallbackParam, StateChangesParam, ActionCollectionConfig, GlobalStoreConfig } from './GlobalStore.types';
2
+ import { GlobalStore } from './GlobalStore';
3
3
  /**
4
4
  * @description
5
5
  * Use this class to extends the capabilities of the GlobalStore.
6
6
  * by implementing the abstract methods onInitialize and onChange.
7
7
  * You can use this class to create a store with async storage.
8
8
  */
9
- export declare abstract class GlobalStoreAbstract<TState, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> extends GlobalStore<TState, TMetadata, TStateSetter> {
10
- constructor(state: TState, config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>, actionsConfig?: TStateSetter | null);
11
- protected onInit: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
12
- protected onStateChanged: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
13
- protected abstract onInitialize: ({ setState, setMetadata, getMetadata, getState, actions, }: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
14
- protected abstract onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
9
+ export declare abstract class GlobalStoreAbstract<TState, TMetadata = null, TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> extends GlobalStore<TState, TMetadata, TStateMutator> {
10
+ constructor(state: TState, config?: GlobalStoreConfig<TState, TMetadata, TStateMutator>, actionsConfig?: TStateMutator | null);
11
+ protected onInit: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateMutator>) => void;
12
+ protected onStateChanged: (parameters: StateChangesParam<TState, TMetadata, TStateMutator>) => void;
13
+ protected abstract onInitialize: ({ setState, setMetadata, getMetadata, getState, actions, }: StateConfigCallbackParam<TState, TMetadata, TStateMutator>) => void;
14
+ protected abstract onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<TState, TMetadata, TStateMutator>) => void;
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "This is a package to easily handling global-state across your react-components No-redux",
5
5
  "main": "lib/bundle.js",
6
6
  "types": "lib/src/index.d.ts",
@@ -1 +0,0 @@
1
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */