react-native-global-state-hooks 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+
2
+ ## Customize persist storage
3
+
4
+ Let suppose you don't like **async-storage** or you also want to implement some kind of encrypt-process. You could easily extend the **GlobalStore** Class, and customize your persist store implementation.
5
+
6
+ ## Creating hooks with reusable actions
7
+
8
+ Let's say you want to have a STATE with a specific set of actions that you could be reused. With this library is pretty easy to accomplish. Let's create **increase** and **decrease** actions to our COUNT-store. **useCountGlobal.ts**:
9
+
10
+ ```JSX
11
+ import * as IGlobalState from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
12
+ import GlobalStore from 'react-native-global-state-hooks';
13
+
14
+ export interface ICountActionsConfig extends IGlobalState.IActionCollectionConfig<number> {
15
+ decrease: (decrease: number) => (setter: IGlobalState.StateSetter<number>, state: number) => Promise<void>,
16
+ increase: (increase: number) => (setter: IGlobalState.StateSetter<number>, state: number) => Promise<void>,
17
+ }
18
+
19
+ export interface ICountActions extends IGlobalState.IActionCollectionResult {
20
+ decrease: (decrease: number) => Promise<void>,
21
+ increase: (increase: number) => Promise<void>,
22
+ }
23
+
24
+ const countActions: IActionCollectionConfig<number> = {
25
+ decrease: (decrease: number) => async (setter: IGlobalState.StateSetter<number>, state: number) => {
26
+ setter(state - decrease);
27
+ },
28
+ increase: (increase: number) => async (setter: IGlobalState.StateSetter<number>, state: number) => {
29
+ setter(state + increase);
30
+ },
31
+ };
32
+
33
+ const countStore = new GlobalStore(0, countActions);
34
+
35
+ export const useCountGlobal = countStore.getHook<ICountActions>();
36
+
37
+ ```
38
+
39
+ Now the result of our useCountGlobal will return our actions instead of a simple setter... Let's see:
40
+
41
+ ```JSX
42
+ import { useCountGlobal } from './useCountGlobal'
43
+
44
+ function Stage1() {
45
+ const [count, actions] = useCountGlobal();
46
+
47
+ const increaseClick = () => actions.increase(1);
48
+ const decreaseClick = () => actions.decrease(1);
49
+
50
+ return (<>
51
+ <label>{count}<label/><br/>
52
+ <button onPress={increaseClick}>increase<button/>
53
+ <button onPress={decreaseClick}>decrease<button/>
54
+ </>);
55
+ }
56
+
57
+ ```
58
+
59
+ ```JSX
60
+ import GlobalState from 'react-native-global-state-hooks';
61
+ import secureStorage from 'react-native-secure-storage';
62
+ import { IActionCollection } from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
63
+
64
+ export class SecureGlobalState<
65
+ IState,
66
+ IPersist extends string | null = null,
67
+ IsPersist extends boolean = IPersist extends null ? false : true,
68
+ IActions extends IActionCollection<IState> | null = null
69
+ > extends GlobalState<IState, IPersist, IsPersist, IActions> {
70
+
71
+ protected asyncStorageGetItem = () => secureStorage.getItem(this.persistStoreAs as string, config);
72
+
73
+ protected asyncStorageSetItem = (value: string) => secureStorage.setItem(this.persistStoreAs as string, value, config);
74
+
75
+ }
76
+
77
+ export default SecureGlobalState;
78
+ ```
package/README.md CHANGED
@@ -1,178 +1,101 @@
1
1
  # react-native-global-state-hooks
2
2
  This is a package to easily handling global-state across your react-native-components No-redux, No-context.
3
3
 
4
- This utility follows the same style as the default useState hook, this in order to be an intuitive tool to help you to quickly migrate from complex options as redux to the new react-hooks.
4
+ This utility follows the same style as the default useState hook, this in order to be an intuitive and easy to use
5
5
 
6
6
  **after version 1.0.4, we migrated to @react-native-async-storage/async-storage, because @react-native-async-storage/async-storage has been deprecated!!**
7
7
 
8
8
  ## Creating a global store, an a simple hook
9
9
 
10
- We are gonna create a global count example **count.ts**:
10
+ We are gonna create a global count example **useCountGlobal.ts**:
11
11
 
12
- ```
12
+ ```JSX
13
13
  import GlobalStore from 'react-native-global-state-hooks';
14
14
 
15
15
  const countStore = new GlobalStore(0);
16
16
 
17
- export const useCount = countStore.getHook();
17
+ export const useCountGlobal = countStore.getHook();
18
18
  ```
19
19
 
20
20
  That's it, that's a global store... Strongly typed, with a global-hook that we could reuse cross all our react-components.
21
21
 
22
22
  ## Consuming global hook
23
- Let's say we have two components stage1, stage2, in order to use our global hook they will look just like:
24
- ```
25
- import { useCount } from './count'
23
+ Let's say we have two components **Stage1**, **Stage2**, in order to use our global hook they will look just like:
24
+ ```JSX
25
+ import { useCountGlobal } from './useCountGlobal'
26
26
 
27
- function Stage1() {
28
- const [count, setter] = useCount();
29
- const onClick = useCallback(() => setter(currentState => currentState + 1), []);
30
- return (<button onPress={onClick}>count: {count}<button/>);
31
- }
27
+ const Stage1: React.FC = () => {
28
+ const [count, setter] = useCountGlobal();
29
+ const onClickAddOne = () => setter(count + 1);
32
30
 
33
- function Stage2() {
34
- const [count, setter] = useCount();
35
- const onClick = useCallback(() => setter(currentState => currentState + 1));
36
- return (<button onPress={onClick}>count: {count}<button/>);
31
+ return (<button onPress={onClickAddOne}>count: {count}<button/>);
37
32
  }
38
- ```
39
- Just like that, you are using a global state. Note that the only difference between this and the default useState hook is that you are not adding the initial value, cause you already did that when you created the store.
40
-
41
- ## Persisted store
42
-
43
- You could persist the state in the local-storage by just adding a name to the constructor of your global-store let's see.
44
- ```
45
- const countStore = new GlobalStore(0, null, 'GLOBAL_COUNT');
46
- ```
47
-
48
- ## Customize persist storage
49
-
50
- Let suppose you don't like async storage, or you also want to implement some kind of secure storage. You could easily extends the GlobalStore Class, and customize your persist store implementation.
51
-
52
- ```
53
- import GlobalState from 'react-native-global-state-hooks';
54
- import secureStorage from 'react-native-secure-storage';
55
- import { IActionCollection } from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
56
33
 
57
- export class SecureGlobalState<
58
- IState,
59
- IPersist extends string | null = null,
60
- IsPersist extends boolean = IPersist extends null ? false : true,
61
- IActions extends IActionCollection<IState> | null = null
62
- > extends GlobalState<IState, IPersist, IsPersist, IActions> {
63
-
64
- protected asyncStorageGetItem = () => secureStorage.getItem(this.persistStoreAs as string, config);
65
-
66
- protected asyncStorageSetItem = (value: string) => secureStorage.setItem(this.persistStoreAs as string, value, config);
34
+ const Stage2: React.FC = () => {
35
+ const [count, setter] = useCountGlobal();
36
+ const onClickAddTwo = () => setter(count + 2);
67
37
 
38
+ return (<button onPress={onClickAddTwo}>count: {count}<button/>);
68
39
  }
69
-
70
- export default SecureGlobalState;
71
40
  ```
72
41
 
73
- ## Consuming Persisted Store
74
- ```
75
- const [refresh, setter, state, isUpdated] = useCount();
76
-
77
- useEffect(() => {
78
- refresh();
79
- }, []);
42
+ Just like that! You now are using a global state.
80
43
 
44
+ Note that the only difference between this and the default **useState** hook is that you are not adding the initial value, cause you already did that when you created the store:
45
+ ```JSX
46
+ const countStore = new GlobalStore(0);
81
47
  ```
82
- With the persistent storage, I preferred to change a little the format of the result... To let know developers what they are doing, because **asyncStorage** is ASYNC, so if I were automatically updating the state the first time that the hook is called, it could be ending into an INEXPLICABLE re-render of components...
83
-
84
- But even with the above, you could still automatically adding that behavior if you want, just by wrapping the hook:
85
- ```
86
- export const usePersistedCount = () => {
87
- const [refresh, setter, state, isUpdated] = useCount();
88
-
89
- useEffect(() => {
90
- refresh();
91
- }, []);
92
-
93
- return [state, setter, isUpdated];
94
- }
95
- ```
96
- Don't worry about calling the refresh method every time you reuse the hook, that use case is already being handled by the GlobalState, and is not gonna perform any re-render... actually is just gonna read the asyncStorage the first time that you'll call the REFRESH method. Again this is strongly typed, so you'll don't have to guess what is happening.
97
48
 
98
- ## Creating hooks with reusable actions
99
-
100
- Let's say you want to have a STATE with a specific set of actions that you could be reused. With this library is pretty easy to accomplish. Let's create **plus** and **decrease** actions to our COUNT-store. **count.ts**:
49
+ ## Persisted store
101
50
 
51
+ You could persist the state in the **async-storage** by just adding the **key-name** to the constructor of your global-store, for example:
52
+ ```JSX
53
+ // The FIRST parameter is the initial value of the state
54
+ // The Second parameter is an API to restrict access to the state, will talk about that later.
55
+ // The Third parameter is the key that will use on the async-storage
56
+ const countStore = new GlobalStore(0, null, 'GLOBAL_COUNT');
102
57
  ```
103
- import * as IGlobalState from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
104
- import GlobalStore from 'react-native-global-state-hooks';
105
58
 
106
- const countStore = new GlobalStore(0, {
107
- plus: (increase: number) => async (setter: IGlobalStore.StateSetter<number>, currentState: number) => {
108
- // perfom whatever login you want
109
- setter(currentState + increase);
110
- },
111
- decrease: (decrease: number) => async (setter: IGlobalStore.StateSetter<number>, currentState: number) => {
112
- // perfom whatever login you want
113
- setter(currentState - decrease);
114
- },
115
- });
116
-
117
- export const useCount = countStore.getHook();
59
+ ## Consuming Persisted Store
118
60
 
61
+ ```JSX
62
+ const [count, setCount, isCountUpdated] = useCountGlobal();
119
63
  ```
120
64
 
121
- Now the result of our useCount will return our actions instead of a simple setter... Let's see:
122
-
123
- ```
124
- import { useCount } from './count'
65
+ **isCountUpdated**: With the persist storage, the first time the hooks is called the same is gonna return the default value declared in the **new GlobalStore**, at the same time will perform an **async** request to the **async-storage** in order to get the stored value, to validate if that call was already performed, youl'll get an extra boolean value.
125
66
 
126
- function Stage1() {
127
- const [count, actions] = useCount();
128
- const increaseClick = useCallback(() => actions.plus(1), []);
129
- const decreaseClick = useCallback(() => actions.decrease(1), []);
67
+ ## Decoupled hook
130
68
 
131
- return (<>
132
- <label>{count}<label/><br/>
133
- <button onPress={increaseClick}>increase<button/>
134
- <button onPress={decreaseClick}>decrease<button/>
135
- </>);
136
- }
69
+ ```JSX
70
+ import GlobalStore from 'react-native-global-state-hooks';
137
71
 
138
- ```
72
+ const countStore = new GlobalStore(0);
139
73
 
140
- You could also type the API contract, in order to take more advantage of typescript, just by passing an interface to getHook method:
74
+ export const useCountGlobal = countStore.getHook();
141
75
 
142
- ```
143
- export interface ICountActions {
144
- plus: (increase: number) => Promise<void>,
145
- decrease: (decrease: number) => Promise<void>,
146
- }
76
+ export const [getCountGlobalValue, setCountGlobalValue] = countStore.getHookDecoupled();
147
77
 
148
- export const useCount = countStore.getHook<ICountActions>();
149
78
  ```
150
- The above step is necessary to get the correct typing of the parameters of your actions, otherwise, you'll get the name of the actions but the parameters would be all TYPE-ANY
151
79
 
152
- ## Decoupled hook
80
+ If you want to access the global state outside a component or outside a hook, or without subscribing the component to the state changes...
153
81
 
154
- Finally, if you want to access the global state outside a component, or without subscribing the component to the state changes...
82
+ This is especially useful when you want when you create components that have edition access to a certain store, but they actually don't need to be reactive to the state changes, like a search component that just need to get the current state every time that is going to search the data; but actually don't need to be subscribed to the changes over the collection he is going to be filtering.
155
83
 
156
- This is especially useful when you want to reuse an action into another one, or when you wrote components that have edition access to a certain store, but they actually don't need to be reactive to the state changes, like a search component that just need to get the current state every time is gonna search the data, but actually don't need to hear all changes over the collection he is gonna be filtering.
157
- ```
158
- export const useCount = countStore.getHook<ICountActions>();
159
- export const useCountDecoupled = countStore.getHookDecoupled<ICountActions>();
160
- ```
161
84
 
162
85
  Let's see a trivial example:
163
- ```
164
- import { useCount, useCountDecoupled } from './count'
86
+ ```JSX
87
+ import { useCountGlobal, setCountGlobalValue } from './useCountGlobal'
165
88
 
166
- function Stage1() {
167
- const [count] = useCount();
89
+ const Stage1: React.FC = () => {
90
+ const [count] = useCountGlobal();
168
91
 
169
92
  return (<label>{count}<label/><br/>);
170
93
  }
171
94
 
172
- function Stage2() {
173
- const [, actions] = useCountDecoupled();
174
- const increaseClick = useCallback(() => actions.plus(1), []);
175
- const decreaseClick = useCallback(() => actions.decrease(1), []);
95
+ // Stage2 does not need to be updated once the global count changes
96
+ const Stage2: React.FC = () => {
97
+ const increaseClick = () => setCountGlobalValue(count => count + 1);
98
+ const decreaseClick = () => setCountGlobalValue(count => count - 1);
176
99
 
177
100
  return (<>
178
101
  <button onPress={increaseClick}>increase<button/>
@@ -181,17 +104,10 @@ function Stage2() {
181
104
  }
182
105
  ```
183
106
 
184
- Now our stage 1, is just listening to the changes of the state, while stage 2 is just acting as an orchestrator, but stage 2 is not actively listening to state changes, so, actually is not gonna be re-render while stage 1 does.
185
-
186
- # Important notes:
187
- Are concern about performance? this library is for you, instead of handling huge complex stores with options like redux, or by passing the setState to a context Provider (because of the limitations that the context has)... If does, You should just use this library, we are using the more atomic and 'native' way that REACT gives to handle the state, and that is the hook **useState**...
188
-
189
- This utility is just including the implementation of the use state into a subscriber pattern, to enable you to create hooks that will be subscribed to specific store changes, does how we'll be creating a global state hook.
190
-
191
107
  ## Advantages:
192
108
  1. Using REACT's simplest and default way to deal with the state.
193
- 2. Adding partial state designations (This is not on useState default functionality)
194
- 3. Added availability to create actions and decoupled access to the states, no more connects, and dispatches, just call your actions as a normal service of whatever other libraries.
195
- 4. This library is already taking care of avoiding re-renders if the new state does not have changes
196
- 5. This library also is taking care of batching multiple stores updates by using **React unstable_batchedUpdates**; this is a problem that the **useState** have when you call multiple **setStates** into async flows as setTimeout
197
- 6. This tool also take care for you to avoid localStorage data to lose the data types that you stored. For example when you are using datetimes
109
+ 2. This library also is taking care of batching multiple stores updates by using **React unstable_batchedUpdates**; this is a problem that the **useState** have when you call multiple **setStates** into async flows as setTimeout
110
+ 3. This tool also take care for you to avoid **async-storage*** data to lose the data types that you stored. For example when you are using datetimes
111
+
112
+ ## Advance Config
113
+ [README]: ./README.advance.md
@@ -1,7 +1,7 @@
1
1
  /// <reference types="lodash" />
2
2
  import * as IGlobalStore from './GlobalStoreTypes';
3
3
  export declare const isPrimitive: <T>(value: T) => boolean;
4
- export declare class GlobalStore<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IGlobalStore.IActionCollection<IState> | null = null> implements IGlobalStore.IGlobalState<IState, IPersist, IsPersist, IActions> {
4
+ export declare class GlobalStore<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IGlobalStore.IActionCollectionConfig<IState> | null = null> implements IGlobalStore.IGlobalState<IState, IPersist, IsPersist, IActions> {
5
5
  protected state: IState;
6
6
  protected actions: IActions;
7
7
  persistStoreAs: IPersist;
@@ -10,29 +10,28 @@ export declare class GlobalStore<IState, IPersist extends string | null = null,
10
10
  constructor(state: IState, actions?: IActions, persistStoreAs?: IPersist);
11
11
  private get isStoredStateItemUpdated();
12
12
  private storedStateItem;
13
- protected formatItemFromStore<T>(obj: T): any;
14
- protected formatToStore<T>(obj: T): any;
13
+ protected formatItemFromStore<T>(obj: T): unknown;
14
+ protected formatToStore<T>(obj: T): unknown;
15
15
  protected getAsyncStoreItemPromise: Promise<IState> | null;
16
16
  protected asyncStorageGetItem(): Promise<string | null>;
17
17
  protected getAsyncStoreItem(): Promise<IState>;
18
18
  protected asyncStorageSetItem(valueToStore: string): Promise<void>;
19
19
  protected setAsyncStoreItem(): Promise<void>;
20
- getPersistStoreValue: () => () => Promise<IState>;
21
20
  protected getStateCopy: () => IState;
22
- getHook: <IApi extends IGlobalStore.ActionCollectionResult<IActions> | null = IActions extends null ? null : IGlobalStore.ActionCollectionResult<IActions>>() => () => [IPersist extends string ? () => Promise<IState> : IState, IGlobalStore.IHookResult<IState, IActions, IApi>, IsPersist extends true ? IState : null, IsPersist extends true ? boolean : null];
23
- getHookDecoupled: <IApi extends IGlobalStore.ActionCollectionResult<IActions> | null = IActions extends null ? null : IGlobalStore.ActionCollectionResult<IActions>>() => () => [() => IPersist extends string ? Promise<IState> : IState, IGlobalStore.IHookResult<IState, IActions, IApi>, IsPersist extends true ? IState : null, IsPersist extends true ? boolean : null];
21
+ getHook: <IApi extends IGlobalStore.ActionCollectionResult<IState, IActions> | null = IActions extends null ? null : IGlobalStore.ActionCollectionResult<IState, IActions>>() => () => [IState, IGlobalStore.IHookResult<IState, IActions, IApi>, IsPersist extends true ? boolean : null];
22
+ getHookDecoupled: <IApi extends IGlobalStore.ActionCollectionResult<IState, IActions> | null = IActions extends null ? null : IGlobalStore.ActionCollectionResult<IState, IActions>>() => [() => IPersist extends string ? Promise<IState> : IState, IGlobalStore.IHookResult<IState, IActions, IApi>];
24
23
  private _stateOrchestrator;
25
- protected get stateOrchestrator(): IGlobalStore.StateSetter<IState> | IGlobalStore.ActionCollectionResult<IActions>;
24
+ protected get stateOrchestrator(): IGlobalStore.StateSetter<IState> | IGlobalStore.ActionCollectionResult<IState, IActions>;
26
25
  /**
27
- ** [subscriber-update-callback, hook, newState]
26
+ ** [subscriber-update-callback, hook]
28
27
  */
29
- protected static batchedUpdates: [() => void, object, object][];
30
- protected globalSetter: (setter: Partial<IState> | ((state: IState) => Partial<IState>), callback: () => void) => void;
31
- protected globalSetterAsync: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
32
- protected globalSetterToPersistStoreAsync: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
28
+ protected static batchedUpdates: [() => void, object][];
29
+ protected globalSetter: (setter: IState | ((state: IState) => IState), callback: () => void) => void;
30
+ protected globalSetterAsync: (setter: IState | ((state: IState) => IState)) => Promise<void>;
31
+ protected globalSetterToPersistStoreAsync: (setter: IState | ((state: IState) => IState)) => Promise<void>;
33
32
  static ExecutePendingBatchesCallbacks: (() => void)[];
34
33
  static ExecutePendingBatches: import("lodash").DebouncedFunc<() => void>;
35
- protected getActions: <IApi extends IGlobalStore.ActionCollectionResult<IGlobalStore.IActionCollection<IState>>>() => IApi;
34
+ protected getActions: <IApi extends IGlobalStore.ActionCollectionResult<IState, IGlobalStore.IActionCollectionConfig<IState>>>() => IApi;
36
35
  }
37
36
  export default GlobalStore;
38
37
  //# sourceMappingURL=GlobalStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GlobalStore.d.ts","sourceRoot":"","sources":["../src/GlobalStore.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAEnD,eAAO,MAAM,WAAW,0BAAuH,CAAC;AAEhJ,qBAAa,WAAW,CACtB,MAAM,EACN,QAAQ,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EACrC,SAAS,SAAS,OAAO,GAAG,QAAQ,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,EAChE,QAAQ,SAAS,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CACrE,YAAW,YAAY,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAA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B,6BAAoC,MAAM,KAAK,MAAM,MAAI,QAAQ,IAAI,CAAC,CAG7G;IAEF,MAAM,CAAC,8BAA8B,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAM;IAI3D,MAAM,CAAC,qBAAqB,6CAWtB;IAEN,SAAS,CAAC,UAAU,qHAyBlB;CAEH;AAED,eAAe,WAAW,CAAC"}
@@ -4,9 +4,9 @@ exports.GlobalStore = exports.isPrimitive = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = require("react");
6
6
  const lodash_1 = require("lodash");
7
- const async_storage_1 = tslib_1.__importDefault(require("@react-native-async-storage/async-storage"));
8
- const react_dom_1 = tslib_1.__importDefault(require("react-dom"));
9
- const isPrimitive = (value) => lodash_1.isNil(value) || lodash_1.isNumber(value) || lodash_1.isBoolean(value) || lodash_1.isString(value) || typeof value === 'symbol';
7
+ const async_storage_1 = (0, tslib_1.__importDefault)(require("@react-native-async-storage/async-storage"));
8
+ const react_dom_1 = (0, tslib_1.__importDefault)(require("react-dom"));
9
+ const isPrimitive = (value) => (0, lodash_1.isNil)(value) || (0, lodash_1.isNumber)(value) || (0, lodash_1.isBoolean)(value) || (0, lodash_1.isString)(value) || typeof value === 'symbol';
10
10
  exports.isPrimitive = isPrimitive;
11
11
  class GlobalStore {
12
12
  constructor(state, actions = null, persistStoreAs = null) {
@@ -16,55 +16,51 @@ class GlobalStore {
16
16
  this.subscribers = [];
17
17
  this.storedStateItem = undefined;
18
18
  this.getAsyncStoreItemPromise = null;
19
- this.getPersistStoreValue = () => () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getAsyncStoreItem(); });
20
- this.getStateCopy = () => Object.freeze(lodash_1.cloneDeep(this.state));
19
+ this.getStateCopy = () => Object.freeze((0, lodash_1.cloneDeep)(this.state));
21
20
  this.getHook = () => () => {
22
- const [value, setter] = react_1.useState(this.state);
23
- const valueWrapper = this.isPersistStore ? this.getPersistStoreValue() : value;
24
- react_1.useEffect(() => {
21
+ const [value, setter] = (0, react_1.useState)(() => this.state);
22
+ (0, react_1.useEffect)(() => {
25
23
  this.subscribers.push(setter);
24
+ if (this.isPersistStore) {
25
+ this.getAsyncStoreItem();
26
+ }
26
27
  return () => {
27
28
  this.subscribers = this.subscribers.filter((hook) => setter !== hook);
28
29
  };
29
30
  }, []);
30
31
  return [
31
- valueWrapper,
32
+ value,
32
33
  this.stateOrchestrator,
33
- this.state,
34
34
  this.isStoredStateItemUpdated,
35
35
  ];
36
36
  };
37
- this.getHookDecoupled = () => () => {
38
- const valueWrapper = this.isPersistStore ? this.getPersistStoreValue() : () => this.state;
37
+ this.getHookDecoupled = () => {
38
+ const valueWrapper = this.isPersistStore ? this.getAsyncStoreItem() : () => this.state;
39
39
  return [
40
40
  valueWrapper,
41
41
  this.stateOrchestrator,
42
- this.state,
43
- this.isStoredStateItemUpdated,
44
42
  ];
45
43
  };
46
44
  this._stateOrchestrator = null;
47
45
  this.globalSetter = (setter, callback) => {
48
- const partialState = typeof setter === 'function' ? setter(this.getStateCopy()) : setter;
49
- let newState = exports.isPrimitive(partialState) ? partialState : Object.assign(Object.assign({}, this.state), partialState);
50
- // avoid perform multiple update batches by accumulating state changes of the same hook
51
- GlobalStore.batchedUpdates = GlobalStore.batchedUpdates.filter(([, hook, previousState]) => {
46
+ // avoid perform multiple updates over the same state
47
+ GlobalStore.batchedUpdates = GlobalStore.batchedUpdates.filter(([, hook]) => {
52
48
  const isSameHook = hook === this;
53
49
  if (isSameHook) {
54
50
  // eslint-disable-next-line no-console
55
51
  console.warn('You should try avoid call the same state-setter multiple times at one execution line');
56
- newState = exports.isPrimitive(newState) ? newState : Object.assign(Object.assign({}, previousState), newState);
57
52
  }
58
53
  return !isSameHook;
59
54
  });
55
+ const newState = typeof setter === 'function' ? setter(this.getStateCopy()) : setter;
60
56
  this.state = newState;
61
57
  // batch store updates
62
- GlobalStore.batchedUpdates.push([() => this.subscribers.forEach((updateChild) => updateChild(newState)), this, newState]);
58
+ GlobalStore.batchedUpdates.push([() => this.subscribers.forEach((updateChild) => updateChild(newState)), this]);
63
59
  GlobalStore.ExecutePendingBatchesCallbacks.push(callback);
64
60
  GlobalStore.ExecutePendingBatches();
65
61
  };
66
- this.globalSetterAsync = (setter) => tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve) => this.globalSetter(setter, () => resolve())); });
67
- this.globalSetterToPersistStoreAsync = (setter) => tslib_1.__awaiter(this, void 0, void 0, function* () {
62
+ this.globalSetterAsync = (setter) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return new Promise((resolve) => this.globalSetter(setter, () => resolve())); });
63
+ this.globalSetterToPersistStoreAsync = (setter) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
68
64
  yield this.globalSetterAsync(setter);
69
65
  yield this.setAsyncStoreItem();
70
66
  });
@@ -73,7 +69,7 @@ class GlobalStore {
73
69
  // Setter is allways async because of the render batch
74
70
  // but we are typing the setter as synchronous to avoid the developer has extra complexity that useState do not handle
75
71
  const setter = this.isPersistStore ? this.globalSetterToPersistStoreAsync : this.globalSetterAsync;
76
- return Object.keys(actions).reduce((accumulator, key) => (Object.assign(Object.assign({}, accumulator), { [key]: (...parameres) => tslib_1.__awaiter(this, void 0, void 0, function* () {
72
+ return Object.keys(actions).reduce((accumulator, key) => (Object.assign(Object.assign({}, accumulator), { [key]: (...parameres) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
77
73
  let promise;
78
74
  const setterWrapper = (value) => {
79
75
  promise = setter(value);
@@ -93,6 +89,10 @@ class GlobalStore {
93
89
  return this.storedStateItem !== undefined;
94
90
  }
95
91
  formatItemFromStore(obj) {
92
+ const isArray = Array.isArray(obj);
93
+ if (isArray) {
94
+ return obj.map((item) => this.formatItemFromStore(item));
95
+ }
96
96
  return Object.keys(obj).filter((key) => !key.includes('_type')).reduce((acumulator, key) => {
97
97
  const type = obj[`${key}_type`];
98
98
  const unformatedValue = obj[key];
@@ -100,32 +100,36 @@ class GlobalStore {
100
100
  if (isDateType) {
101
101
  return Object.assign(Object.assign({}, acumulator), { [key]: new Date(unformatedValue) });
102
102
  }
103
- return Object.assign(Object.assign({}, acumulator), { [key]: exports.isPrimitive(unformatedValue) ? unformatedValue : this.formatItemFromStore(unformatedValue) });
103
+ return Object.assign(Object.assign({}, acumulator), { [key]: (0, exports.isPrimitive)(unformatedValue) ? unformatedValue : this.formatItemFromStore(unformatedValue) });
104
104
  }, {});
105
105
  }
106
106
  formatToStore(obj) {
107
+ const isArray = Array.isArray(obj);
108
+ if (isArray) {
109
+ return obj.map((item) => this.formatToStore(item));
110
+ }
107
111
  return Object.keys(obj).reduce((acumulator, key) => {
108
112
  const value = obj[key];
109
113
  const isDatetime = value instanceof Date;
110
- return (Object.assign(Object.assign({}, acumulator), { [key]: exports.isPrimitive(value) || isDatetime ? value : this.formatToStore(value), [`${key}_type`]: isDatetime ? 'date' : typeof value }));
114
+ return (Object.assign(Object.assign({}, acumulator), { [key]: (0, exports.isPrimitive)(value) || isDatetime ? value : this.formatToStore(value), [`${key}_type`]: isDatetime ? 'date' : typeof value }));
111
115
  }, {});
112
116
  }
113
117
  asyncStorageGetItem() {
114
118
  return async_storage_1.default.getItem(this.persistStoreAs);
115
119
  }
116
120
  getAsyncStoreItem() {
117
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
121
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
118
122
  if (this.isStoredStateItemUpdated)
119
123
  return this.storedStateItem;
120
124
  if (this.getAsyncStoreItemPromise)
121
125
  return this.getAsyncStoreItemPromise;
122
126
  this.getAsyncStoreItemPromise = new Promise((resolve) => {
123
- (() => tslib_1.__awaiter(this, void 0, void 0, function* () {
127
+ (() => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
124
128
  const item = yield this.asyncStorageGetItem();
125
129
  if (item) {
126
130
  const value = JSON.parse(item);
127
- const primitive = exports.isPrimitive(value);
128
- const newState = primitive ? value : this.formatItemFromStore(value);
131
+ const primitive = (0, exports.isPrimitive)(value);
132
+ const newState = primitive || Array.isArray(value) ? value : this.formatItemFromStore(value);
129
133
  yield this.globalSetterAsync(newState);
130
134
  }
131
135
  resolve(this.state);
@@ -135,16 +139,16 @@ class GlobalStore {
135
139
  });
136
140
  }
137
141
  asyncStorageSetItem(valueToStore) {
138
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
142
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
139
143
  yield async_storage_1.default.setItem(this.persistStoreAs, valueToStore);
140
144
  });
141
145
  }
142
146
  setAsyncStoreItem() {
143
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
147
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
144
148
  if (this.storedStateItem === this.state)
145
149
  return;
146
150
  this.storedStateItem = this.state;
147
- const valueToStore = exports.isPrimitive(this.state) ? this.state : this.formatToStore(lodash_1.cloneDeep(this.state));
151
+ const valueToStore = (0, exports.isPrimitive)(this.state) ? this.state : this.formatToStore((0, lodash_1.cloneDeep)(this.state));
148
152
  yield this.asyncStorageSetItem(JSON.stringify(valueToStore));
149
153
  });
150
154
  }
@@ -165,13 +169,13 @@ class GlobalStore {
165
169
  }
166
170
  exports.GlobalStore = GlobalStore;
167
171
  /**
168
- ** [subscriber-update-callback, hook, newState]
172
+ ** [subscriber-update-callback, hook]
169
173
  */
170
174
  GlobalStore.batchedUpdates = [];
171
175
  GlobalStore.ExecutePendingBatchesCallbacks = [];
172
176
  // avoid multiples calls to batchedUpdates
173
177
  // eslint-disable-next-line @typescript-eslint/no-empty-function
174
- GlobalStore.ExecutePendingBatches = lodash_1.debounce(() => {
178
+ GlobalStore.ExecutePendingBatches = (0, lodash_1.debounce)(() => {
175
179
  const reactBatchedUpdates = react_dom_1.default.unstable_batchedUpdates || ((mock) => mock());
176
180
  reactBatchedUpdates(() => {
177
181
  GlobalStore.batchedUpdates.forEach(([execute]) => {
@@ -1,28 +1,34 @@
1
1
  /**
2
2
  * @param {StateSetter<IState>} setter - add a new value to the state
3
- * @returns {Promise<void>} result - resolves when update_batches finished
3
+ * @returns {void} result - void
4
4
  */
5
- export declare type StateSetter<IState> = (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
5
+ export declare type StateSetter<IState> = (setter: IState | ((state: IState) => IState)) => void;
6
6
  /**
7
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
8
  */
9
- export declare type IAction<IState> = <IResult>(...params: any[]) => (setter: StateSetter<IState>, currentState: IState) => Promise<unknown> | IResult;
9
+ export declare type IActionConfig<IState> = (...params: any[]) => (setter: StateSetter<IState>, currentState: IState) => Promise<unknown>;
10
10
  /**
11
11
  * Configuration of you API
12
12
  */
13
- export interface IActionCollection<IState> {
14
- [key: string]: IAction<IState>;
13
+ export interface IActionCollectionConfig<IState> {
14
+ [key: string]: IActionConfig<IState>;
15
+ }
16
+ /**
17
+ * This should be the API format of the hook (if you passed an API as a parameter)
18
+ */
19
+ export interface IActionCollectionResult {
20
+ [key: string]: (...params: any[]) => Promise<unknown>;
15
21
  }
16
22
  /**
17
23
  * This is the API result of the hook (if you passed an API as a parameter)
18
24
  */
19
- export declare type ActionCollectionResult<IActions> = {
20
- [key in keyof IActions]: <IResult>(...params: any[]) => any | IResult;
25
+ export declare type ActionCollectionResult<IState, IActions extends IActionCollectionConfig<IState> | null> = {
26
+ [key in keyof IActions]: (...params: any[]) => unknown;
21
27
  };
22
28
  /**
23
29
  * Hook result, if you passed an API as a parameter it will be returned in the second position of the hook invoke.
24
30
  */
25
- export declare type IHookResult<IState, IActions extends IActionCollection<IState> | null = null, IApi extends ActionCollectionResult<IActions> | null = IActions extends null ? null : ActionCollectionResult<IActions>> = IApi extends null ? StateSetter<IState> : IActions extends IActionCollection<IState> ? IApi extends ActionCollectionResult<IActions> ? IApi : StateSetter<IState> : StateSetter<IState>;
31
+ export declare type IHookResult<IState, IActions extends IActionCollectionConfig<IState> | null = null, IApi extends ActionCollectionResult<IState, IActions> | null = IActions extends null ? null : ActionCollectionResult<IState, IActions>> = IApi extends null ? StateSetter<IState> : IActions extends IActionCollectionConfig<IState> ? IApi extends ActionCollectionResult<IState, IActions> ? IApi : StateSetter<IState> : StateSetter<IState>;
26
32
  /**
27
33
  * This is a class to create global-store objects
28
34
  * @template IState
@@ -36,34 +42,31 @@ export declare type IHookResult<IState, IActions extends IActionCollection<IStat
36
42
  * this will disable the default return of the state-setter of the hook, and instead will return the API
37
43
  * @param {string} persistStoreAs - A name if you want to persist the state of the store in localstorage
38
44
  * */
39
- export interface IGlobalState<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IActionCollection<IState> | null = null> {
45
+ export interface IGlobalState<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IActionCollectionConfig<IState> | null = null> {
40
46
  persistStoreAs: IPersist;
41
47
  isPersistStore: boolean;
42
48
  /**
43
49
  * Returns a global hook that will share information across components by subscribing them to a specific store.
44
50
  * @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>, initialStatePersistStorage | null, isUpdatedPersistStorage | null]
45
51
  */
46
- getHook: <IApi extends IActions extends ActionCollectionResult<IActions> ? ActionCollectionResult<IActions> : null>() => () => [
47
- IPersist extends string ? () => Promise<IState> : IState,
52
+ getHook: <IApi extends IActions extends ActionCollectionResult<IState, IActions> ? ActionCollectionResult<IState, IActions> : null>() => () => [
53
+ IState,
48
54
  IHookResult<IState, IActions, IApi>,
49
- IsPersist extends true ? IState : null,
50
55
  IsPersist extends true ? boolean : null
51
56
  ];
52
57
  /**
53
58
  * This is an access to the subscribers queue and to the current state of a specific store...
54
59
  * THIS IS NOT A REACT-HOOK, so you could use it everywhere example other hooks, and services.
55
- * @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>, initialStatePersistStorage | null, isUpdatedPersistStorage | null]
60
+ * @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>]
56
61
  */
57
- getHookDecoupled: <IApi extends IActions extends ActionCollectionResult<IActions> ? ActionCollectionResult<IActions> : null>() => () => [
62
+ getHookDecoupled: <IApi extends IActions extends ActionCollectionResult<IState, IActions> ? ActionCollectionResult<IState, IActions> : null>() => [
58
63
  () => IPersist extends string ? Promise<IState> : IState,
59
- IHookResult<IState, IActions, IApi>,
60
- IsPersist extends true ? IState : null,
61
- IsPersist extends true ? boolean : null
64
+ IHookResult<IState, IActions, IApi>
62
65
  ];
63
66
  }
64
67
  /**
65
68
  * @deprecated This interface name is deprecated, use instead IGlobalState
66
69
  */
67
- export interface IGlobalStateFactory<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IActionCollection<IState> | null = null> extends IGlobalState<IState, IPersist, IsPersist, IActions> {
70
+ export interface IGlobalStateFactory<IState, IPersist extends string | null = null, IsPersist extends boolean = IPersist extends null ? false : true, IActions extends IActionCollectionConfig<IState> | null = null> extends IGlobalState<IState, IPersist, IsPersist, IActions> {
68
71
  }
69
72
  //# sourceMappingURL=GlobalStoreTypes.d.ts.map
@@ -1 +1 @@
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,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,KAC3D,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB;;EAEE;AACF,oBAAY,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,EAEpC,GAAG,MAAM,EAAE,GAAG,EAAE,KACb,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAEvF;;EAEE;AACF,MAAM,WAAW,iBAAiB,CAAC,MAAM;IACvC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,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,SAAS,uBAAuB,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI;IAG9D,cAAc,EAAE,QAAQ,CAAC;IAEzB,cAAc,EAAE,OAAO,CAAC;IAExB;;;MAGE;IACF,OAAO,EAAE,CAAC,IAAI,SAAS,QAAQ,SAAS,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,IAAI,OAAO,MAAM;QAC7I,MAAM;QACN,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC;QACnC,SAAS,SAAS,IAAI,GAAG,OAAO,GAAG,IAAI;KACxC,CAAC;IAEF;;;;MAIE;IACF,gBAAgB,EAAE,CAAC,IAAI,SAAS,QAAQ,SAAS,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,IAAI,OAAO;QAChJ,MAAM,QAAQ,SAAS,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM;QACxD,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC;KACpC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAClC,MAAM,EACN,QAAQ,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EACrC,SAAS,SAAS,OAAO,GAAG,QAAQ,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,EAChE,QAAQ,SAAS,uBAAuB,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAC9D,SAAQ,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC;CAE5D"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-global-state-hooks",
3
- "version": "1.1.3",
4
- "description": "This is a package to easily handling global-state across your react-native-components No-redux, No-context.",
3
+ "version": "2.0.0",
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": [
7
7
  "lib"
@@ -63,5 +63,11 @@
63
63
  "lodash": "workspace:*",
64
64
  "react": "workspace:*",
65
65
  "react-dom": "workspace:*"
66
+ },
67
+ "dependencies": {
68
+ "@react-native-async-storage/async-storage": "^1.15.14",
69
+ "lodash": "^4.17.21",
70
+ "react": "^17.0.2",
71
+ "react-dom": "^17.0.2"
66
72
  }
67
73
  }