react-native-global-state-hooks 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/lib/GlobalStore.d.ts +5 -0
- package/lib/GlobalStore.d.ts.map +1 -1
- package/lib/GlobalStore.js +9 -4
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/package.json +1 -1
- package/lib/GlobalStore.utils.d.ts +0 -3
- package/lib/GlobalStore.utils.d.ts.map +0 -1
- package/lib/GlobalStore.utils.js +0 -5
package/README.md
CHANGED
|
@@ -223,6 +223,14 @@ The methods **formatToStore** and **formatFromStore** are part of another librar
|
|
|
223
223
|
|
|
224
224
|
this super small library will help you to transform objects into json string and get them back without losing any of the original data types... no more problems when **stringify** Dates, Maps, Sets, etc...
|
|
225
225
|
|
|
226
|
+
## How to use the **GlobalStoreAsync**
|
|
227
|
+
|
|
228
|
+
It will work exactly the same as the **GlobalStore**, the main difference is that by default the metadata object will include the {**isAsyncStorageReady** } which will allow you to know if the async data was already retrieved.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
const [count, setCount, { isAsyncStorageReady }] = useCountGlobal();
|
|
232
|
+
```
|
|
233
|
+
|
|
226
234
|
...
|
|
227
235
|
|
|
228
236
|
Originally the library was implementing persistent storage by using the package **@react-native-async-storage**, but not all people want to use it or need to use it... so it has been removed. Feel free to use the above example to get back that functionality if you were using the previous versions of the package.
|
package/lib/GlobalStore.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
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;
|
|
3
8
|
/**
|
|
4
9
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
5
10
|
* @template {TState} TState - The type of the state object
|
package/lib/GlobalStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStore.d.ts","sourceRoot":"","sources":["../src/GlobalStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GlobalStore.d.ts","sourceRoot":"","sources":["../src/GlobalStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAuB,MAAM,OAAO,CAAC;AAEtE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EAEzB,MAAM,qBAAqB,CAAC;AAU7B,eAAO,MAAM,KAAK,kBAA6B,CAAC;AAChD,eAAO,MAAM,eAAe,oCAAuC,CAAC;AACpE,eAAO,MAAM,aAAa;;gDAAqC,CAAC;AAEhE;;;;;KAKK;AACL,qBAAa,WAAW,CACtB,MAAM,EACN,SAAS,GAAG,IAAI,EAChB,YAAY,SACR,sBAAsB,CAAC,MAAM,EAAE,SAAS,CAAC,GACzC,WAAW,CAAC,MAAM,CAAC,GACnB,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC;IAuI5B,SAAS,CAAC,KAAK,EAAE,MAAM;IACvB,SAAS,CAAC,QAAQ,EAAE,SAAS;IAC7B,SAAS,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAC3C,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC;IAxItE;;;SAGK;IACE,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAa;IAEzD;;;;;;;;;;SAUK;IACL,SAAS,CAAC,MAAM,CA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AsB;0BAGZ,cAAc,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;UAC5D,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"}
|
package/lib/GlobalStore.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GlobalStore = void 0;
|
|
3
|
+
exports.GlobalStore = exports.formatToStore = exports.formatFromStore = exports.clone = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// jsonStorageFormatter
|
|
6
|
+
const jsonStorageFormatter = tslib_1.__importStar(require("json-storage-formatter"));
|
|
4
7
|
const react_1 = require("react");
|
|
5
|
-
const GlobalStore_utils_1 = require("./GlobalStore.utils");
|
|
6
8
|
const throwWrongKeyOnActionCollectionConfig = (action_key) => {
|
|
7
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
|
|
8
10
|
${action_key}: (param) => ({ setState, getState, setMetadata, getMetadata }) => {\n
|
|
@@ -10,6 +12,9 @@ const throwWrongKeyOnActionCollectionConfig = (action_key) => {
|
|
|
10
12
|
}\n
|
|
11
13
|
}\n`);
|
|
12
14
|
};
|
|
15
|
+
exports.clone = jsonStorageFormatter.clone;
|
|
16
|
+
exports.formatFromStore = jsonStorageFormatter.formatFromStore;
|
|
17
|
+
exports.formatToStore = jsonStorageFormatter.formatToStore;
|
|
13
18
|
/**
|
|
14
19
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
15
20
|
* @template {TState} TState - The type of the state object
|
|
@@ -100,12 +105,12 @@ class GlobalStore {
|
|
|
100
105
|
* gets a clone of the state
|
|
101
106
|
* @returns {TState} - The state clone
|
|
102
107
|
* */
|
|
103
|
-
this.getStateClone = () =>
|
|
108
|
+
this.getStateClone = () => jsonStorageFormatter.clone(this.state);
|
|
104
109
|
/**
|
|
105
110
|
* gets a clone of the metadata
|
|
106
111
|
* @returns {TMetadata} - The metadata clone
|
|
107
112
|
* */
|
|
108
|
-
this.getMetadataClone = () =>
|
|
113
|
+
this.getMetadataClone = () => jsonStorageFormatter.clone(this.metadata);
|
|
109
114
|
/**
|
|
110
115
|
* set the state and update all the subscribers
|
|
111
116
|
* @param {StateSetter<TState>} setter - The setter function or the value to set
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,5 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./GlobalStore.types"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./GlobalStore.utils"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./GlobalStore"), exports);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStore.utils.d.ts","sourceRoot":"","sources":["../src/GlobalStore.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAG/C,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/lib/GlobalStore.utils.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.clone = void 0;
|
|
4
|
-
const json_storage_formatter_1 = require("json-storage-formatter");
|
|
5
|
-
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return json_storage_formatter_1.clone; } });
|