react-native-global-state-hooks 2.0.6 → 2.1.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.
- package/README.md +304 -58
- package/lib/GlobalStore.d.ts +162 -45
- package/lib/GlobalStore.d.ts.map +1 -1
- package/lib/GlobalStore.js +283 -150
- package/lib/GlobalStore.types.d.ts +108 -0
- package/lib/GlobalStore.types.d.ts.map +1 -0
- package/lib/{GlobalStoreTypes.js → GlobalStore.types.js} +0 -0
- package/lib/GlobalStore.utils.d.ts +10 -0
- package/lib/GlobalStore.utils.d.ts.map +1 -0
- package/lib/GlobalStore.utils.js +23 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/package.json +4 -4
- package/lib/GlobalStoreTypes.d.ts +0 -66
- package/lib/GlobalStoreTypes.d.ts.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debounce = exports.clone = exports.formatFromStore = exports.formatToStore = void 0;
|
|
4
|
+
const json_storage_formatter_1 = require("json-storage-formatter");
|
|
5
|
+
Object.defineProperty(exports, "formatToStore", { enumerable: true, get: function () { return json_storage_formatter_1.formatToStore; } });
|
|
6
|
+
Object.defineProperty(exports, "formatFromStore", { enumerable: true, get: function () { return json_storage_formatter_1.formatFromStore; } });
|
|
7
|
+
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return json_storage_formatter_1.clone; } });
|
|
8
|
+
/**
|
|
9
|
+
* Debounce function to prevent multiple calls to the same function in a short period of time
|
|
10
|
+
* @param callback Function to be called
|
|
11
|
+
* @param wait Time to wait before calling the function
|
|
12
|
+
* @returns Function to be called
|
|
13
|
+
*/
|
|
14
|
+
const debounce = (callback, wait = 300) => {
|
|
15
|
+
let timer;
|
|
16
|
+
return ((...args) => {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
timer = setTimeout(() => {
|
|
19
|
+
callback(...args);
|
|
20
|
+
}, wait);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.debounce = debounce;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./GlobalStore.types"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./GlobalStore.utils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./GlobalStore"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-global-state-hooks",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
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": [
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/johnny-quesada-developer/react-native-global-state-hooks#readme",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@react-native-async-storage/async-storage": "workspace:*",
|
|
44
43
|
"@types/jest": "^26.0.17",
|
|
45
44
|
"@types/lodash": "^4.14.165",
|
|
46
45
|
"@types/react": "^17.0.0",
|
|
@@ -48,6 +47,7 @@
|
|
|
48
47
|
"@types/react-test-renderer": "^17.0.0",
|
|
49
48
|
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
|
50
49
|
"@typescript-eslint/parser": "^4.9.1",
|
|
50
|
+
"cancelable-promise-jq": "^1.0.4",
|
|
51
51
|
"eslint": "^7.15.0",
|
|
52
52
|
"eslint-config-airbnb": "^18.2.1",
|
|
53
53
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"react": "workspace:*",
|
|
59
59
|
"react-test-renderer": "^17.0.1",
|
|
60
60
|
"ts-jest": "^26.4.4",
|
|
61
|
-
"
|
|
61
|
+
"tslib": "^2.5.0",
|
|
62
|
+
"typescript": "^4.9.5"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
|
-
"@react-native-async-storage/async-storage": "workspace:*",
|
|
65
65
|
"react": "workspace:*"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {StateSetter<IState>} setter - add a new value to the state
|
|
3
|
-
* @returns {void} result - void
|
|
4
|
-
*/
|
|
5
|
-
export declare type StateSetter<IState> = (setter: IState | ((state: IState) => IState)) => void;
|
|
6
|
-
/**
|
|
7
|
-
* This is the structure required by the API actions in order to be able to capture action parameters and inject state setter into actions.
|
|
8
|
-
*/
|
|
9
|
-
export declare type IActionConfig<IState> = (...params: any[]) => (setter: StateSetter<IState>, currentState: IState) => Promise<unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Configuration of you API
|
|
12
|
-
*/
|
|
13
|
-
export interface IActionCollectionConfig<IState> {
|
|
14
|
-
[key: string]: IActionConfig<IState>;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* This is the API result of the hook (if you passed an API as a parameter)
|
|
18
|
-
*/
|
|
19
|
-
export declare type IActionCollectionResult<IState, IActions extends IActionCollectionConfig<IState> | null> = {
|
|
20
|
-
[key in keyof IActions]: (...params: any[]) => unknown;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Hook result, if you passed an API as a parameter it will be returned in the second position of the hook invoke.
|
|
24
|
-
*/
|
|
25
|
-
export declare type IHookResult<IState, IActions extends IActionCollectionConfig<IState> | null = null, IApi extends IActionCollectionResult<IState, IActions> | null = IActions extends null ? null : IActionCollectionResult<IState, IActions>> = IApi extends null ? StateSetter<IState> : IActions extends IActionCollectionConfig<IState> ? IApi extends IActionCollectionResult<IState, IActions> ? IApi : StateSetter<IState> : StateSetter<IState>;
|
|
26
|
-
/**
|
|
27
|
-
* This is a class to create global-store objects
|
|
28
|
-
* @template IState
|
|
29
|
-
* @param {IState} state - Initial state,
|
|
30
|
-
* @template IPersist
|
|
31
|
-
* @param {IPersist} persistStoreAs - A name that indicates if the store should be persisted at the asyncStorage
|
|
32
|
-
* @template IsPersist
|
|
33
|
-
* @param {IsPersist} isPersist - Calculated flag that indicates if the store is persisted
|
|
34
|
-
* @template IActions
|
|
35
|
-
* @param {IActions} actions - An specific api to restrict the use of the state,
|
|
36
|
-
* this will disable the default return of the state-setter of the hook, and instead will return the API
|
|
37
|
-
* @param {string} persistStoreAs - A name if you want to persist the state of the store in localstorage
|
|
38
|
-
* */
|
|
39
|
-
export interface IGlobalState<IState, IPersist extends string | null = null, IActions extends IActionCollectionConfig<IState> | null = null> {
|
|
40
|
-
persistStoreAs: IPersist;
|
|
41
|
-
isPersistStore: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* This function can be used to format the data after it is loaded from the asyncStorage
|
|
44
|
-
*/
|
|
45
|
-
onPersistStorageLoad: (obj: unknown) => (IState | null);
|
|
46
|
-
/**
|
|
47
|
-
* Returns a global hook that will share information across components by subscribing them to a specific store.
|
|
48
|
-
* @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>, initialStatePersistStorage | null, isUpdatedPersistStorage | null]
|
|
49
|
-
*/
|
|
50
|
-
getHook: <IApi extends IActions extends IActionCollectionResult<IState, IActions> ? IActionCollectionResult<IState, IActions> : null>() => () => [
|
|
51
|
-
IState,
|
|
52
|
-
IHookResult<IState, IActions, IApi>,
|
|
53
|
-
IPersist extends null ? false : true extends true ? boolean : null
|
|
54
|
-
];
|
|
55
|
-
/**
|
|
56
|
-
* This is an access to the subscribers queue and to the current state of a specific store...
|
|
57
|
-
* THIS IS NOT A REACT-HOOK, so you could use it everywhere example other hooks, and services.
|
|
58
|
-
* @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>]
|
|
59
|
-
*/
|
|
60
|
-
getHookDecoupled: <IApi extends IActions extends IActionCollectionResult<IState, IActions> ? IActionCollectionResult<IState, IActions> : null>() => [
|
|
61
|
-
() => IPersist extends string ? Promise<IState> : IState,
|
|
62
|
-
IHookResult<IState, IActions, IApi>
|
|
63
|
-
];
|
|
64
|
-
deleteAsyncStoreItem: () => Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=GlobalStoreTypes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStoreTypes.d.ts","sourceRoot":"","sources":["../src/GlobalStoreTypes.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,oBAAY,WAAW,CAAC,MAAM,IAAI,CAChC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,KACzC,IAAI,CAAC;AAEV;;EAEE;AACF,oBAAY,aAAa,CAAC,MAAM,IAAI,CAElC,GAAG,MAAM,EAAE,GAAG,EAAE,KACb,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE7E;;EAEE;AACF,MAAM,WAAW,uBAAuB,CAAC,MAAM;IAC7C,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;EAEE;AACF,oBAAY,uBAAuB,CAAC,MAAM,EAAE,QAAQ,SAAS,uBAAuB,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI;KAEpG,GAAG,IAAI,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,OAAO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