react-native-global-state-hooks 3.0.6 → 3.0.8

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.
@@ -1,13 +1,13 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam } from './GlobalStore.types';
2
+ import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, StateChangesParam, MetadataSetter } from './GlobalStore.types';
3
3
  /**
4
4
  * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
5
5
  * @template {TState} TState - The type of the state object
6
6
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
7
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
7
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
8
8
  * */
9
- export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> | null = StateSetter<TState>> {
10
- protected setterConfig: TStateSetter | null;
9
+ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> {
10
+ protected actionsConfig: TStateSetter | null;
11
11
  /**
12
12
  * list of all the subscribers setState functions
13
13
  * @template {TState} TState - The type of the state object
@@ -19,7 +19,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
19
19
  * additional configuration for the store
20
20
  * @template {TState} TState - The type of the state object
21
21
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
22
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
22
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
23
23
  * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
24
24
  * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
25
25
  * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
@@ -31,7 +31,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
31
31
  * execute once the store is created
32
32
  * @template {TState} TState - The type of the state object
33
33
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
34
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
34
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
35
35
  * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
36
36
  * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
37
37
  * @param {() => TState} parameters.getState - The getState function to get the state
@@ -43,7 +43,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
43
43
  * execute every time the state is changed
44
44
  * @template {TState} TState - The type of the state object
45
45
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
46
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
46
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
47
47
  * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
48
48
  * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
49
49
  * @param {() => TState} parameters.getState - The getState function to get the state
@@ -55,7 +55,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
55
55
  * Execute each time a new component gets subscribed to the store
56
56
  * @template {TState} TState - The type of the state object
57
57
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
58
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
58
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
59
59
  * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
60
60
  * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
61
61
  * @param {() => TState} parameters.getState - The getState function to get the state
@@ -67,7 +67,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
67
67
  * Execute everytime a state change is triggered and before the state is updated, it allows to prevent the state change by returning true
68
68
  * @template {TState} TState - The type of the state object
69
69
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
70
- * @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
70
+ * @template {TStateSetter} TStateSetter - The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
71
71
  * @param {StateConfigCallbackParam<TState, TMetadata, TStateSetter>} parameters - The parameters object brings the following properties: setState, getState, setMetadata, getMetadata
72
72
  * @param {Dispatch<SetStateAction<TState>>} parameters.setState - The setState function to update the state
73
73
  * @param {() => TState} parameters.getState - The getState function to get the state
@@ -96,7 +96,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
96
96
  * The metadata object could be null if not needed
97
97
  * The setter Object is used to define the actions that will be used to manipulate the state
98
98
  * @param {TState} state - The initial state
99
- * @param {TStateSetter} setterConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
99
+ * @param {TStateSetter} actionsConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
100
100
  * */
101
101
  constructor(state: TState, config: GlobalStoreConfig<TState, TMetadata, TStateSetter>);
102
102
  /**
@@ -112,10 +112,10 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
112
112
  * @param {GlobalStoreConfig<TState, TMetadata>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
113
113
  * @param {GlobalStoreConfig<TState, TMetadata>} config.onSubscribed - The callback to execute when a new component gets subscribed to the store (optional) (default: null)
114
114
  * @param {GlobalStoreConfig<TState, TMetadata>} config.computePreventStateChange - The callback to execute everytime a state change is triggered and before the state is updated, it allows to prevent the state change by returning true (optional) (default: null)
115
- * @param {TStateSetter} setterConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
115
+ * @param {TStateSetter} actionsConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
116
116
  * */
117
- constructor(state: TState, config: GlobalStoreConfig<TState, TMetadata, TStateSetter>, setterConfig: TStateSetter);
118
- protected initialize: () => void;
117
+ constructor(state: TState, config: GlobalStoreConfig<TState, TMetadata, TStateSetter>, actionsConfig: TStateSetter);
118
+ protected initialize: () => Promise<void>;
119
119
  /**
120
120
  * set the state and update all the subscribers
121
121
  * @param {StateSetter<TState>} setter - The setter function or the value to set
@@ -129,9 +129,11 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
129
129
  }) => void;
130
130
  /**
131
131
  * Set the value of the metadata property, this is no reactive and will not trigger a re-render
132
- * @param {StateSetter<TMetadata>} setter - The setter function or the value to set
132
+ * @param {MetadataSetter<TMetadata>} setter - The setter function or the value to set
133
133
  * */
134
- protected setMetadata: StateSetter<TMetadata>;
134
+ protected setMetadata: MetadataSetter<TMetadata>;
135
+ protected getMetadata: () => TMetadata;
136
+ protected getState: () => TState;
135
137
  /**
136
138
  * get the parameters object to pass to the callback functions (onInit, onStateChanged, onSubscribed, computePreventStateChange)
137
139
  * this parameters object brings the following properties: setState, getState, setMetadata, getMetadata
@@ -202,3 +204,81 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
202
204
  }>>;
203
205
  }) => ActionCollectionResult<TState, TMetadata, TStateSetter>;
204
206
  }
207
+ /**
208
+ * Creates a global hook that can be used to access the state and actions across the application
209
+ * @param {TState} state - The initial state
210
+ * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object (optional) (default: null)
211
+ * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object
212
+ * @param {TStateSetter | null} parameters.actionsConfig - The setter configuration object (optional) (default: null)
213
+ * @returns {} [HOOK, DECOUPLED_GETTER, DECOUPLED_SETTER] this is an array with the hook, the decoupled getState function and the decoupled setter of the state
214
+ */
215
+ export declare const createGlobalStateWithDecoupledFuncs: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, { actions, metadata, onInit, onStateChanged, onSubscribed, computePreventStateChange, }?: {
216
+ /**
217
+ * @description
218
+ * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
219
+ */
220
+ actions?: TActions;
221
+ /**
222
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
223
+ * */
224
+ metadata?: TMetadata;
225
+ /**
226
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
227
+ * @returns {void} result - void
228
+ * */
229
+ onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
230
+ /**
231
+ * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
232
+ * @returns {void} result - void
233
+ */
234
+ onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => void;
235
+ /**
236
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
237
+ * @returns {void} result - void
238
+ */
239
+ onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
240
+ /**
241
+ * @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
242
+ * @returns {boolean} result - true if you want to prevent the state change, false otherwise
243
+ */
244
+ computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => boolean;
245
+ }) => [useHook: () => [TState, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata], getState: () => TState, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
246
+ /**
247
+ * Creates a global hook that can be used to access the state and actions across the application
248
+ * @param {TState} state - The initial state of the store
249
+ * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object of the store and the configuration object of the state setter (optional) (default: null)
250
+ * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object of the store
251
+ * @param {TStateSetter | null} parameters.actionsConfig - The configuration object of the state setter (optional) (default: null)
252
+ * @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
253
+ */
254
+ export declare const createGlobalState: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, config?: {
255
+ /**
256
+ * @description
257
+ * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
258
+ */
259
+ actions?: TActions;
260
+ /**
261
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
262
+ * */
263
+ metadata?: TMetadata;
264
+ /**
265
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
266
+ * @returns {void} result - void
267
+ * */
268
+ onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
269
+ /**
270
+ * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
271
+ * @returns {void} result - void
272
+ */
273
+ onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => void;
274
+ /**
275
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
276
+ * @returns {void} result - void
277
+ */
278
+ onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
279
+ /**
280
+ * @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
281
+ * @returns {boolean} result - true if you want to prevent the state change, false otherwise
282
+ */
283
+ computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => boolean;
284
+ }) => () => [TState, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata];
@@ -1,8 +1,15 @@
1
1
  /**
2
- * @param {StateSetter<TState>} setter - add a new state to an existing state
2
+ * @param {StateSetter<TState>} setter - set the state
3
3
  * @returns {void} result - void
4
4
  */
5
- export type StateSetter<TState> = (setter: TState | ((state: TState) => TState),
5
+ export type StateSetter<TState> = (
6
+ /**
7
+ * @param {StateSetter<TState>} setter - set the state
8
+ * @param {{ forceUpdate?: boolean }} options - Options to be passed to the setter
9
+ * @param {{ forceUpdate?: boolean }} options.forceUpdate - Force the re-render of the subscribers even if the state is the same
10
+ * @returns {void} result - void
11
+ * */
12
+ setter: TState | ((state: TState) => TState),
6
13
  /**
7
14
  * This parameter indicate whether we should force the re-render of the subscribers even if the state is the same,
8
15
  * Do
@@ -14,13 +21,34 @@ export type StateSetter<TState> = (setter: TState | ((state: TState) => TState),
14
21
  */
15
22
  forceUpdate?: boolean;
16
23
  }) => void;
24
+ /**
25
+ * @description
26
+ * Type that prevent ts issues with merging never with other types
27
+ */
28
+ export type AvoidNever<T> = T extends never | null | undefined ? {} : T;
29
+ /**
30
+ * @param {TMetadata} setter - set the metadata
31
+ * @returns {void} result - void
32
+ */
33
+ export type MetadataSetter<TMetadata> = (
34
+ /**
35
+ * @param {TMetadata} setter - set the metadata
36
+ * @returns {void} result - void
37
+ * */
38
+ setter: TMetadata | ((metadata: TMetadata) => TMetadata)) => void;
17
39
  /**
18
40
  * Parameters of the onStateChanged callback function
19
41
  * @param {TState} state - the new state
20
42
  * @param {TState} previousState - the previous state
21
43
  **/
22
44
  export type StateChanges<TState> = {
45
+ /**
46
+ * The new state
47
+ * */
23
48
  state: TState;
49
+ /**
50
+ * The previous state
51
+ * */
24
52
  previousState?: TState;
25
53
  };
26
54
  /**
@@ -33,22 +61,44 @@ export type StateChanges<TState> = {
33
61
  * @property {() => TMetadata} getMetadata - Get the metadata
34
62
  * @property {ActionCollectionResult<TState, TMetadata>} actions - The actions collection if any
35
63
  **/
36
- export type StoreTools<TState, TMetadata = null> = {
37
- setMetadata: StateSetter<TMetadata>;
64
+ export type StoreTools<TState = any, TMetadata = any, TActions = any> = {
65
+ /**
66
+ * Set the metadata
67
+ * @param {TMetadata} setter - The metadata or a function that will receive the metadata and return the new metadata
68
+ * @returns {void} result - void
69
+ * */
70
+ setMetadata: MetadataSetter<TMetadata>;
71
+ /**
72
+ * Set the state
73
+ * @param {TState} setter - The state or a function that will receive the state and return the new state
74
+ * @param {{ forceUpdate?: boolean }} options - Options
75
+ * @returns {void} result - void
76
+ * */
38
77
  setState: StateSetter<TState>;
78
+ /**
79
+ * Get the state
80
+ * @returns {TState} result - The state
81
+ * */
39
82
  getState: () => TState;
83
+ /**
84
+ * Get the metadata
85
+ * @returns {TMetadata} result - The metadata
86
+ * */
40
87
  getMetadata: () => TMetadata;
41
- actions: ActionCollectionResult<TState, TMetadata>;
88
+ /**
89
+ * Actions of the hook
90
+ */
91
+ actions: TActions;
42
92
  };
43
93
  /**
44
94
  * Basic contract for the storeActionsConfig configuration
45
95
  * @template {TState} TState - The state type
46
96
  * @template {TMetadata} TMetadata - The metadata type
47
97
  * @property {string} key - The action name
48
- * @property {(...parameters: unknown[]) => (storeTools: { setMetadata: StateSetter<TMetadata>; setState: StateSetter<TState>; getState: () => TState; getMetadata: () => TMetadata; }) => unknown | void} value - The action function
98
+ * @property {(...parameters: unknown[]) => (storeTools: { setMetadata: MetadataSetter<TMetadata>; setState: StateSetter<TState>; getState: () => TState; getMetadata: () => TMetadata; }) => unknown | void} value - The action function
49
99
  * @returns {ActionCollectionConfig<TState, TMetadata>} result - The action collection configuration
50
100
  */
51
- export interface ActionCollectionConfig<TState, TMetadata> {
101
+ export interface ActionCollectionConfig<TState, TMetadata = null> {
52
102
  [key: string]: (...parameters: any[]) => (storeTools: StoreTools<TState, TMetadata>) => unknown | void;
53
103
  }
54
104
  /**
@@ -84,7 +134,7 @@ export type ActionCollectionResult<TState, TMetadata, TStateSetter extends Actio
84
134
  * Common parameters of the store configuration callback functions
85
135
  * @param {StateSetter<TState>} setState - add a new value to the state
86
136
  * @param {() => TState} getState - get the current state
87
- * @param {StateSetter<TMetadata>} setMetadata - add a new value to the metadata
137
+ * @param {MetadataSetter<TMetadata>} setMetadata - add a new value to the metadata
88
138
  * @param {() => TMetadata} getMetadata - get the current metadata
89
139
  * @param {ActionCollectionResult<TState, ActionCollectionConfig<TState, TMetadata>> | null} actions - the actions object returned by the hook when you pass an storeActionsConfig configuration otherwise null
90
140
  * @template {TState} TState - The state type
@@ -113,9 +163,28 @@ export type StateChangesParam<TState, TMetadata, TStateSetter extends ActionColl
113
163
  * @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
114
164
  * */
115
165
  export type GlobalStoreConfig<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
166
+ /**
167
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
168
+ * */
116
169
  metadata?: TMetadata;
170
+ /**
171
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
172
+ * @returns {void} result - void
173
+ * */
117
174
  onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
175
+ /**
176
+ * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
177
+ * @returns {void} result - void
178
+ */
118
179
  onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
180
+ /**
181
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
182
+ * @returns {void} result - void
183
+ */
119
184
  onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
185
+ /**
186
+ * @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
187
+ * @returns {boolean} result - true if you want to prevent the state change, false otherwise
188
+ */
120
189
  computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => boolean;
121
190
  } | null;
@@ -1,4 +1,4 @@
1
- import { StateSetter, StateConfigCallbackParam, StateChangesParam, ActionCollectionConfig, GlobalStoreConfig } from 'GlobalStore.types';
1
+ import { StateSetter, StateConfigCallbackParam, StateChangesParam, ActionCollectionConfig, GlobalStoreConfig, AvoidNever, ActionCollectionResult } from 'GlobalStore.types';
2
2
  import { GlobalStore } from './GlobalStore';
3
3
  /**
4
4
  * @description
@@ -6,10 +6,80 @@ import { GlobalStore } from './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> | null = StateSetter<TState>> extends GlobalStore<TState, TMetadata, TStateSetter> {
10
- constructor(state: TState, config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>, setterConfig?: TStateSetter | null);
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
11
  protected onInit: (parameters: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => void;
12
- protected onStateChanged: (parameters: StateChangesParam<TState, TMetadata, NonNullable<TStateSetter>>) => void;
12
+ protected onStateChanged: (parameters: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
13
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, NonNullable<TStateSetter>>) => void;
14
+ protected abstract onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<TState, TMetadata, TStateSetter>) => void;
15
15
  }
16
+ export type CustomGlobalHookParams<TInheritMetadata = null, TCustomConfig = {}> = {
17
+ /**
18
+ * @description
19
+ * This function is called when the state is initialized.
20
+ */
21
+ onInitialize: ({ setState, setMetadata, getMetadata, getState, actions, }: StateConfigCallbackParam<any, TInheritMetadata>, config: TCustomConfig) => void;
22
+ /**
23
+ * @description
24
+ * This function is called when the state is changed.
25
+ */
26
+ onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<any, TInheritMetadata>, config: TCustomConfig) => void;
27
+ };
28
+ /**
29
+ * @description
30
+ * Use this function to create a custom global store.
31
+ * You can use this function to create a store with async storage.
32
+ */
33
+ export declare const createCustomGlobalStateWithDecoupledFuncs: <TInheritMetadata = null, TCustomConfig = null>({ onInitialize, onChange, }: CustomGlobalHookParams<TInheritMetadata, TCustomConfig>) => <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>> = null>(state: TState, { config: customConfig, actions, metadata, onInit, onStateChanged, onSubscribed, computePreventStateChange, }?: {
34
+ config?: TCustomConfig;
35
+ actions?: TActions;
36
+ metadata?: TMetadata;
37
+ onInit?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
38
+ onStateChanged?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
39
+ onSubscribed?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
40
+ computePreventStateChange?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => boolean;
41
+ }) => [useHook: () => [TState, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>], getState: () => TState, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>];
42
+ /**
43
+ * @description
44
+ * Use this function to create a custom global store.
45
+ * You can use this function to create a store with async storage.
46
+ * This function will return a hook that you can use to access the store.
47
+ * @param state The initial state of the store.
48
+ * @param config The configuration of the store.
49
+ * @returns {[TState, TStateSetter, TMetadata]} The state, the state setter and the metadata of the store.
50
+ */
51
+ export declare const createCustomGlobalState: <TInheritMetadata = null, TCustomConfig = {}>({ onInitialize, onChange, }: CustomGlobalHookParams<TInheritMetadata, TCustomConfig>) => <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>> = null>(state: TState, { config: customConfig, actions, metadata, onInit, onStateChanged, onSubscribed, computePreventStateChange, }?: {
52
+ /**
53
+ * Configuration of the custom global store
54
+ */
55
+ config?: TCustomConfig;
56
+ /**
57
+ * @description
58
+ * (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
59
+ */
60
+ actions?: TActions;
61
+ /**
62
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
63
+ * */
64
+ metadata?: TMetadata;
65
+ /**
66
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
67
+ * @returns {void} result - void
68
+ * */
69
+ onInit?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
70
+ /**
71
+ * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
72
+ * @returns {void} result - void
73
+ */
74
+ onStateChanged?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
75
+ /**
76
+ * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
77
+ * @returns {void} result - void
78
+ */
79
+ onSubscribed?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
80
+ /**
81
+ * @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
82
+ * @returns {boolean} result - true if you want to prevent the state change, false otherwise
83
+ */
84
+ computePreventStateChange?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => boolean;
85
+ }) => () => [TState, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, (TInheritMetadata extends null ? {} : TInheritMetadata) & (TMetadata extends null ? {} : TMetadata)];
package/lib/bundle.js CHANGED
@@ -1 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports["react-native-global-state-hooks"]=e(require("react")):t["react-native-global-state-hooks"]=e(t.react)}(this,(t=>{return e={774:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function a(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===n(e)?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStore=void 0;var u=r(156),c=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setterConfig=i,this.subscribers=new Set,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.initialize=function(){var t=r.onInit,e=r.config.onInit;if(t||e){var n=r.getConfigCallbackParam({});null==t||t(n),null==e||e(n)}},this.setState=function(t){var e=t.invokerSetState,n=t.state;r.stateWrapper={state:n},null==e||e({state:n}),r.subscribers.forEach((function(t){t!==e&&t({state:n})}))},this.setMetadata=function(t){var e,n,o="function"==typeof t?t(null!==(e=r.config.metadata)&&void 0!==e?e:null):t;r.config=Object.assign(Object.assign({},null!==(n=r.config)&&void 0!==n?n:{}),{metadata:o})},this.getConfigCallbackParam=function(t){var e=t.invokerSetState;return{setMetadata:r.setMetadata,getMetadata:function(){return r.config.metadata},getState:function(){return r.stateWrapper.state},setState:r.getSetStateWrapper({invokerSetState:e}),actions:r.getStoreActionsMap()}},this.getHook=function(){return function(){var t,e,n=(t=(0,u.useState)((function(){return r.stateWrapper})),e=2,function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,f=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){f=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(f)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=n[0],a=n[1];(0,u.useEffect)((function(){r.subscribers.add(a);var t=r.onSubscribed,e=r.config.onSubscribed;if(t||e){var n=r.getConfigCallbackParam({invokerSetState:a});null==t||t(n),null==e||e(n)}return function(){r.subscribers.delete(a)}}),[]);var c=r.getStateOrchestrator(a);return[i.state,c,r.config.metadata]}},this.getHookDecoupled=function(){return[function(){return r.stateWrapper.state},r.getStateOrchestrator(),function(){return r.config.metadata}]},this.getSetStateWrapper=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;return function(e){var n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate;r.computeSetState({invokerSetState:t,setter:e,forceUpdate:n})}},this.hasStateCallbacks=function(){var t=r.computePreventStateChange,e=r.onStateChanged,n=r.config,o=n.computePreventStateChange,i=n.onStateChanged;return!!(t||o||e||i)},this.computeSetState=function(t){var e=t.setter,n=t.invokerSetState,o=t.forceUpdate,i="function"==typeof e,a=r.stateWrapper.state,u=i?e(a):e;if(o||!Object.is(r.stateWrapper.state,u)){var c=r.hasStateCallbacks(),f=c&&r.getStoreActionsMap({}),s=c&&r.getSetStateWrapper({invokerSetState:n}),l={setMetadata:r.setMetadata,getMetadata:function(){return r.config.metadata},setState:s,getState:function(){return r.stateWrapper.state},actions:f,previousState:a,state:u},p=r.computePreventStateChange,v=r.config.computePreventStateChange;if((p||v)&&((null==p?void 0:p(l))||(null==v?void 0:v(l))))return;r.setState({invokerSetState:n,state:u});var y=r.onStateChanged,b=r.config.onStateChanged;(y||b)&&(null==y||y(l),null==b||b(l))}},this.getStoreActionsMap=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;if(!r.setterConfig)return null;var e=r.setterConfig,n=r.setMetadata,o=e,i=Object.keys(o),u=r.getSetStateWrapper({invokerSetState:t}),c=function(){return r.stateWrapper.state},f=function(){return r.config.metadata},s=i.reduce((function(t,e){return Object.assign(Object.assign({},t),(r={},l=function(){for(var t=o[e],r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];var l=t.apply(s,i);return"function"!=typeof l&&function(t){throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(t,"]: key is not a valid function, try something like this: \n{\n\n ").concat(t,": (param) => ({ setState, getState, setMetadata, getMetadata }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(e),l.call(s,{setState:u,getState:c,setMetadata:n,getMetadata:f,actions:s})},(i=a(i=e))in r?Object.defineProperty(r,i,{value:l,enumerable:!0,configurable:!0,writable:!0}):r[i]=l,r));var r,i,l}),{});return s},this.stateWrapper={state:e},this.config=Object.assign({metadata:null},null!=n?n:{}),this.constructor!==t||this.initialize()}var e,r;return e=t,(r=[{key:"state",get:function(){return this.stateWrapper.state}},{key:"getStateOrchestrator",value:function(t){return this.setterConfig?this.getStoreActionsMap({invokerSetState:t}):this.getSetStateWrapper({invokerSetState:t})}}])&&i(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=c},530:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},195:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStoreAbstract=void 0;var a=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}(c,t);var e,r,a,u=(r=c,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=i(r);if(a){var o=i(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function c(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.call(this,t,r,n)).onInit=function(t){e.onInitialize(t)},e.onStateChanged=function(t){e.onChange(t)},e}return e=c,Object.defineProperty(e,"prototype",{writable:!1}),e}(r(774).GlobalStore);e.GlobalStoreAbstract=a},991:(t,e,r)=>{"use strict";var n=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]},o=function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(684),e),o(r(530),e),o(r(774),e),o(r(195),e)},684:function(t){t.exports=(()=>{"use strict";var t={991:(t,e,r)=>{var n=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]};Object.defineProperty(e,"__esModule",{value:!0}),function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)}(r(729),e)},729:(t,e)=>{function r(t){return r="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},r(t)}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===r(e)?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.formatToStore=e.formatFromStore=e.isPrimitive=e.isFunction=e.isRegex=e.isDate=e.isString=e.isBoolean=e.isNumber=e.isNil=e.clone=void 0,e.clone=function(t){var r,a=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,e.isPrimitive)(t)||(0,e.isDate)(t))return t;if(Array.isArray(t))return a?function(t){if(Array.isArray(t))return i(t)}(r=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():t.map((function(t){return(0,e.clone)(t)}));if(t instanceof Map){var u=Array.from(t.entries());return a?new Map(u):new Map(u.map((function(t){return(0,e.clone)(t)})))}if(t instanceof Set){var c=Array.from(t.values());return a?new Set(c):new Set(c.map((function(t){return(0,e.clone)(t)})))}return t instanceof RegExp?new RegExp(t.toString()):(0,e.isFunction)(t)?a?t:Object.create(t):a?Object.assign({},t):t instanceof Error?new Error(t.message):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.clone)(i)))}),{})},e.isNil=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isBoolean=function(t){return"boolean"==typeof t},e.isString=function(t){return"string"==typeof t},e.isDate=function(t){return t instanceof Date},e.isRegex=function(t){return t instanceof RegExp},e.isFunction=function(t){return"function"==typeof t||t instanceof Function},e.isPrimitive=function(t){return(0,e.isNil)(t)||(0,e.isNumber)(t)||(0,e.isBoolean)(t)||(0,e.isString)(t)||"symbol"===r(t)},e.formatFromStore=function(t){return function(t){var r,i;if((0,e.isPrimitive)(t))return t;if("date"===(null==t?void 0:t.$t))return new Date(t.$v);if("map"===(null==t?void 0:t.$t)){var a=(null!==(r=t.$v)&&void 0!==r?r:[]).map((function(t){var r,n=(2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,f=!1;try{for(i=(r=r.call(t)).next,0;!(c=(n=i.call(r)).done)&&(u.push(n.value),2!==u.length);c=!0);}catch(t){f=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(f)throw o}}return u}}(r)||o(r,2)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=n[0],a=n[1];return[i,(0,e.formatFromStore)(a)]}));return new Map(a)}if("set"===(null==t?void 0:t.$t)){var u=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(u)}return"regex"===(null==t?void 0:t.$t)?new RegExp(t.$v):"error"===(null==t?void 0:t.$t)?new Error(t.$v):Array.isArray(t)?t.map((function(t){return(0,e.formatFromStore)(t)})):"function"===(null==t?void 0:t.$t)?Function("(".concat(t.$v,")(...arguments)")):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?JSON.parse(t):(0,e.clone)(t))},e.formatToStore=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,a=o.validator,u=o.excludeTypes,c=o.excludeKeys,f=new Set(null!=u?u:[]),s=new Set(null!=c?c:[]),l=f.size||s.size,p=null!=a?a:function(t){var e=t.key,n=t.value;if(!l)return!0;var o=s.has(e),i=f.has(r(n));return!o&&!i},v=function t(r){if((0,e.isPrimitive)(r))return r;if(Array.isArray(r))return r.map((function(e){return t(e)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(e){return t(e)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(e){return t(e)}))};if((0,e.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,e.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,e.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:Object.keys(r).reduce((function(e,o){var i=r[o],a=t(i);return p({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(v):v}}},e={};return function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}(991)})()},156:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(991);var e,r}));
1
+ /*! For license information please see bundle.js.LICENSE.txt */
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports["react-native-global-state-hooks"]=e(require("react")):t["react-native-global-state-hooks"]=e(t.react)}(this,(t=>{return e={774:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(){a=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",l=i.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 s(t,e,r,n){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),u=new k(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var v={};function h(){}function y(){}function d(){}var g={};f(g,u,(function(){return this}));var b=Object.getPrototypeOf,m=b&&b(b(E([])));m&&m!==e&&r.call(m,u)&&(g=m);var S=d.prototype=h.prototype=Object.create(g);function w(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(o,a,u,c){var l=p(t[o],t,a);if("throw"!==l.type){var f=l.arg,s=f.value;return s&&"object"==n(s)&&r.call(s,"__await")?e.resolve(s.__await).then((function(t){i("next",t,u,c)}),(function(t){i("throw",t,u,c)})):e.resolve(s).then((function(t){f.value=t,u(f)}),(function(t){return i("throw",t,u,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){i(t,r,e,n)}))}return a=a?a.then(n,n):n()}})}function j(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=p(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function x(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,v;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,v):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function P(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 C(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function E(t){if(t){var e=t[u];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:A}}function A(){return{value:void 0,done:!0}}return y.prototype=d,o(S,"constructor",{value:d,configurable:!0}),o(d,"constructor",{value:y,configurable:!0}),y.displayName=f(d,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,f(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},t.awrap=function(t){return{__await:t}},w(O.prototype),f(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(S),f(S,l,"Generator"),f(S,u,(function(){return this})),f(S,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=E,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(C),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):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),v},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),C(r),v}},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;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),v}},t}function u(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,c(n.key),n)}}function c(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===n(e)?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.createGlobalState=e.createGlobalStateWithDecoupledFuncs=e.GlobalStore=void 0;var l=r(156),f=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=i,this.subscribers=new Set,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.initialize=function(){return t=r,e=void 0,n=void 0,o=a().mark((function t(){var e,r,n;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e=this.onInit,r=this.config.onInit,e||r){t.next=4;break}return t.abrupt("return");case 4:n=this.getConfigCallbackParam({}),null==e||e(n),null==r||r(n);case 7:case"end":return t.stop()}}),t,this)})),new(n||(n=Promise))((function(r,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function u(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}c((o=o.apply(t,e||[])).next())}));var t,e,n,o},this.setState=function(t){var e=t.invokerSetState,n=t.state;r.stateWrapper={state:n},null==e||e({state:n}),r.subscribers.forEach((function(t){t!==e&&t({state:n})}))},this.setMetadata=function(t){var e,n,o="function"==typeof t?t(null!==(e=r.config.metadata)&&void 0!==e?e:null):t;r.config=Object.assign(Object.assign({},null!==(n=r.config)&&void 0!==n?n:{}),{metadata:o})},this.getMetadata=function(){var t;return null!==(t=r.config.metadata)&&void 0!==t?t:null},this.getState=function(){return r.stateWrapper.state},this.getConfigCallbackParam=function(t){var e=t.invokerSetState;return{setMetadata:r.setMetadata,getMetadata:r.getMetadata,getState:r.getState,setState:r.getSetStateWrapper({invokerSetState:e}),actions:r.getStoreActionsMap()}},this.getHook=function(){return function(){var t,e=o((0,l.useState)((function(){return r.stateWrapper})),2),n=e[0],i=e[1];(0,l.useEffect)((function(){r.subscribers.add(i);var t=r.onSubscribed,e=r.config.onSubscribed;if(t||e){var n=r.getConfigCallbackParam({invokerSetState:i});null==t||t(n),null==e||e(n)}return function(){r.subscribers.delete(i)}}),[]);var a=(0,l.useMemo)((function(){return r.getStateOrchestrator(i)}),[]);return[n.state,a,null!==(t=r.config.metadata)&&void 0!==t?t:null]}},this.getHookDecoupled=function(){return[function(){return r.stateWrapper.state},r.getStateOrchestrator(),r.getMetadata]},this.getSetStateWrapper=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;return function(e){var n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate;r.computeSetState({invokerSetState:t,setter:e,forceUpdate:n})}},this.hasStateCallbacks=function(){var t=r.computePreventStateChange,e=r.onStateChanged,n=r.config,o=n.computePreventStateChange,i=n.onStateChanged;return!!(t||o||e||i)},this.computeSetState=function(t){var e=t.setter,n=t.invokerSetState,o=t.forceUpdate,i="function"==typeof e,a=r.stateWrapper.state,u=i?e(a):e;if(o||!Object.is(r.stateWrapper.state,u)){var c=r.hasStateCallbacks(),l=c&&r.getStoreActionsMap({}),f=c&&r.getSetStateWrapper({invokerSetState:n}),s={setMetadata:r.setMetadata,getMetadata:r.getMetadata,setState:f,getState:r.getState,actions:l,previousState:a,state:u},p=r.computePreventStateChange,v=r.config.computePreventStateChange;if((p||v)&&((null==p?void 0:p(s))||(null==v?void 0:v(s))))return;r.setState({invokerSetState:n,state:u});var h=r.onStateChanged,y=r.config.onStateChanged;(h||y)&&(null==h||h(s),null==y||y(s))}},this.getStoreActionsMap=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;if(!r.actionsConfig)return null;var e=r.actionsConfig,n=r.setMetadata,o=e,i=Object.keys(o),a=r.getSetStateWrapper({invokerSetState:t}),u=function(){return r.stateWrapper.state},l=function(){return r.config.metadata},f=i.reduce((function(t,e){return Object.assign(Object.assign({},t),(r={},s=function(){for(var t=o[e],r=arguments.length,i=new Array(r),c=0;c<r;c++)i[c]=arguments[c];var s=t.apply(f,i);return"function"!=typeof s&&function(t){throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(t,"]: key is not a valid function, try something like this: \n{\n\n ").concat(t,": (param) => ({ setState, getState, setMetadata, getMetadata }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(e),s.call(f,{setState:a,getState:u,setMetadata:n,getMetadata:l,actions:f})},(i=c(i=e))in r?Object.defineProperty(r,i,{value:s,enumerable:!0,configurable:!0,writable:!0}):r[i]=s,r));var r,i,s}),{});return f},this.stateWrapper={state:e},this.config=Object.assign({metadata:null},null!=n?n:{}),this.constructor!==t||this.initialize()}var e,r;return e=t,(r=[{key:"state",get:function(){return this.stateWrapper.state}},{key:"getStateOrchestrator",value:function(t){return this.actionsConfig?this.getStoreActionsMap({invokerSetState:t}):this.getSetStateWrapper({invokerSetState:t})}}])&&u(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=f,e.createGlobalStateWithDecoupledFuncs=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.actions,n=e.metadata,i=e.onInit,a=e.onStateChanged,u=e.onSubscribed,c=e.computePreventStateChange,l=new f(t,{metadata:n,onInit:i,onStateChanged:a,onSubscribed:u,computePreventStateChange:c},r),s=o(l.getHookDecoupled(),2),p=s[0],v=s[1];return[l.getHook(),p,v]},e.createGlobalState=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return o((0,e.createGlobalStateWithDecoupledFuncs)(t,r),1)[0]}},530:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},195:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.createCustomGlobalState=e.createCustomGlobalStateWithDecoupledFuncs=e.GlobalStoreAbstract=void 0;var u=r(774),c=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(c,t);var e,r,o,u=(r=c,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=a(r);if(o){var i=a(this).constructor;t=Reflect.construct(e,arguments,i)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function c(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.call(this,t,r,n)).onInit=function(t){e.onInitialize(t)},e.onStateChanged=function(t){e.onChange(t)},e}return e=c,Object.defineProperty(e,"prototype",{writable:!1}),e}(u.GlobalStore);e.GlobalStoreAbstract=c,e.createCustomGlobalStateWithDecoupledFuncs=function(t){var e=t.onInitialize,r=t.onChange;return function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:null},o=n.config,i=n.actions,a=n.metadata,c=n.onInit,l=n.onStateChanged,f=n.onSubscribed,s=n.computePreventStateChange;return(0,u.createGlobalStateWithDecoupledFuncs)(t,{actions:i,metadata:a,onInit:function(t){e(t,o),null==c||c(t)},onStateChanged:function(t){r(t,o),null==l||l(t)},onSubscribed:f,computePreventStateChange:s})}},e.createCustomGlobalState=function(t){var r=t.onInitialize,n=t.onChange,i=(0,e.createCustomGlobalStateWithDecoupledFuncs)({onInitialize:r,onChange:n});return function(t){var e,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:{}},a=n.config,u=n.actions,c=n.metadata,l=n.onInit,f=n.onStateChanged,s=n.onSubscribed,p=n.computePreventStateChange;return(e=i(t,{config:a,actions:u,metadata:c,onInit:l,onStateChanged:f,onSubscribed:s,computePreventStateChange:p}),r=1,function(t){if(Array.isArray(t))return t}(e)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(e,r)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(e,r)||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]}}},991:(t,e,r)=>{"use strict";var n=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]},o=function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(684),e),o(r(530),e),o(r(774),e),o(r(195),e)},684:function(t){t.exports=(()=>{"use strict";var t={991:(t,e,r)=>{var n=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]};Object.defineProperty(e,"__esModule",{value:!0}),function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)}(r(729),e)},729:(t,e)=>{function r(t){return r="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},r(t)}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===r(e)?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.formatToStore=e.formatFromStore=e.isPrimitive=e.isFunction=e.isRegex=e.isDate=e.isString=e.isBoolean=e.isNumber=e.isNil=e.clone=void 0,e.clone=function(t){var r,a=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,e.isPrimitive)(t)||(0,e.isDate)(t))return t;if(Array.isArray(t))return a?function(t){if(Array.isArray(t))return i(t)}(r=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():t.map((function(t){return(0,e.clone)(t)}));if(t instanceof Map){var u=Array.from(t.entries());return a?new Map(u):new Map(u.map((function(t){return(0,e.clone)(t)})))}if(t instanceof Set){var c=Array.from(t.values());return a?new Set(c):new Set(c.map((function(t){return(0,e.clone)(t)})))}return t instanceof RegExp?new RegExp(t.toString()):(0,e.isFunction)(t)?a?t:Object.create(t):a?Object.assign({},t):t instanceof Error?new Error(t.message):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.clone)(i)))}),{})},e.isNil=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isBoolean=function(t){return"boolean"==typeof t},e.isString=function(t){return"string"==typeof t},e.isDate=function(t){return t instanceof Date},e.isRegex=function(t){return t instanceof RegExp},e.isFunction=function(t){return"function"==typeof t||t instanceof Function},e.isPrimitive=function(t){return(0,e.isNil)(t)||(0,e.isNumber)(t)||(0,e.isBoolean)(t)||(0,e.isString)(t)||"symbol"===r(t)},e.formatFromStore=function(t){return function(t){var r,i;if((0,e.isPrimitive)(t))return t;if("date"===(null==t?void 0:t.$t))return new Date(t.$v);if("map"===(null==t?void 0:t.$t)){var a=(null!==(r=t.$v)&&void 0!==r?r:[]).map((function(t){var r,n=(2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{for(i=(r=r.call(t)).next,0;!(c=(n=i.call(r)).done)&&(u.push(n.value),2!==u.length);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(r)||o(r,2)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=n[0],a=n[1];return[i,(0,e.formatFromStore)(a)]}));return new Map(a)}if("set"===(null==t?void 0:t.$t)){var u=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(u)}return"regex"===(null==t?void 0:t.$t)?new RegExp(t.$v):"error"===(null==t?void 0:t.$t)?new Error(t.$v):Array.isArray(t)?t.map((function(t){return(0,e.formatFromStore)(t)})):"function"===(null==t?void 0:t.$t)?Function("(".concat(t.$v,")(...arguments)")):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?JSON.parse(t):(0,e.clone)(t))},e.formatToStore=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,a=o.validator,u=o.excludeTypes,c=o.excludeKeys,l=new Set(null!=u?u:[]),f=new Set(null!=c?c:[]),s=l.size||f.size,p=null!=a?a:function(t){var e=t.key,n=t.value;if(!s)return!0;var o=f.has(e),i=l.has(r(n));return!o&&!i},v=function t(r){if((0,e.isPrimitive)(r))return r;if(Array.isArray(r))return r.map((function(e){return t(e)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(e){return t(e)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(e){return t(e)}))};if((0,e.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,e.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,e.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:Object.keys(r).reduce((function(e,o){var i=r[o],a=t(i);return p({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(v):v}}},e={};return function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}(991)})()},156:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(991);var e,r}));
@@ -0,0 +1 @@
1
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-global-state-hooks",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "description": "This is a package to easily handling global-state across your react-native-components No-redux",
5
5
  "main": "lib/bundle.js",
6
6
  "types": "lib/index.d.ts",