react-native-global-state-hooks 2.1.6 → 2.1.7

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,10 +1,6 @@
1
+ export * from 'json-storage-formatter';
1
2
  import { Dispatch, SetStateAction } from 'react';
2
3
  import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam } from './GlobalStore.types';
3
- export declare const clone: <T>(obj: T) => T;
4
- export declare const formatFromStore: <T = unknown>(value: unknown) => T;
5
- export declare const formatToStore: <TValue, TStringify extends boolean = false>(value: TValue, { stringify }?: {
6
- stringify: TStringify;
7
- }) => TStringify extends true ? string : unknown;
8
4
  /**
9
5
  * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
10
6
  * @template {TState} TState - The type of the state object
@@ -24,6 +20,11 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
24
20
  * @template {TState} TState - The type of the state object
25
21
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
26
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
23
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
24
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
25
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
26
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onSubscribed - The callback to execute when a component is subscribed to the store (optional) (default: null)
27
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
27
28
  */
28
29
  protected config: GlobalStoreConfig<TState, TMetadata, TStateSetter>;
29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,yBAAyB,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAsB3D;IAEF;;;SAGK;IACE,OAAO,4JA8BZ;IAEF;;;SAGK;IACE,gBAAgB,eAMb,MAAM,kIAIN,SAAS,EAEjB;IAEF;;;;SAIK;IACL,SAAS,CAAC,kBAAkB;0BAGR,cAAc,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;UACvD,YAAY,MAAM,CAAC,CAM1B;IAEF;;;;SAIK;IACL,SAAS,CAAC,oBAAoB,CAC5B,eAAe,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAWhE;;;SAGK;IACL,SAAS,CAAC,iBAAiB,QAAO,OAAO,CAgBvC;IAEF;;;;;;OAMG;IACH,SAAS,CAAC,eAAe;gBAIf,YAAY,MAAM,CAAC;0BACT,cAAc,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;eAwD9D;IAEF;;;;SAIK;IACL,SAAS,CAAC,kBAAkB;0BAGR,cAAc,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;UAC5D,uBAAuB,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAgDzD;CACH;AAED,eAAe,WAAW,CAAC"}
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalStore = exports.formatToStore = exports.formatFromStore = exports.clone = void 0;
3
+ exports.GlobalStore = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const jsonStorageFormatter = tslib_1.__importStar(require("json-storage-formatter"));
5
+ tslib_1.__exportStar(require("json-storage-formatter"), exports);
6
+ const json_storage_formatter_1 = require("json-storage-formatter");
6
7
  const react_1 = require("react");
7
8
  const throwWrongKeyOnActionCollectionConfig = (action_key) => {
8
9
  throw new Error(`[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[${action_key}]: key is not a valid function, try something like this: \n{\n
@@ -11,9 +12,6 @@ const throwWrongKeyOnActionCollectionConfig = (action_key) => {
11
12
  }\n
12
13
  }\n`);
13
14
  };
14
- exports.clone = jsonStorageFormatter.clone;
15
- exports.formatFromStore = jsonStorageFormatter.formatFromStore;
16
- exports.formatToStore = jsonStorageFormatter.formatToStore;
17
15
  /**
18
16
  * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
19
17
  * @template {TState} TState - The type of the state object
@@ -44,6 +42,11 @@ class GlobalStore {
44
42
  * @template {TState} TState - The type of the state object
45
43
  * @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
46
44
  * @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
45
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
46
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
47
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
48
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onSubscribed - The callback to execute when a component is subscribed to the store (optional) (default: null)
49
+ * @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
47
50
  */
48
51
  this.config = {
49
52
  metadata: null,
@@ -110,12 +113,12 @@ class GlobalStore {
110
113
  * gets a clone of the state
111
114
  * @returns {TState} - The state clone
112
115
  * */
113
- this.getStateClone = () => jsonStorageFormatter.clone(this.state);
116
+ this.getStateClone = () => (0, json_storage_formatter_1.clone)(this.state);
114
117
  /**
115
118
  * gets a clone of the metadata
116
119
  * @returns {TMetadata} - The metadata clone
117
120
  * */
118
- this.getMetadataClone = () => { var _a, _b; return jsonStorageFormatter.clone((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.metadata) !== null && _b !== void 0 ? _b : null); };
121
+ this.getMetadataClone = () => { var _a, _b; return (0, json_storage_formatter_1.clone)((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.metadata) !== null && _b !== void 0 ? _b : null); };
119
122
  /**
120
123
  * set the state and update all the subscribers
121
124
  * @param {StateSetter<TState>} setter - The setter function or the value to set
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-global-state-hooks",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "This is a package to easily handling global-state across your react-native-components No-redux",
5
5
  "main": "lib/GlobalStore.js",
6
6
  "files": [