react-native-global-state-hooks 1.1.6 → 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,163 +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
- ## Consuming Persisted Store
49
- ```
50
- const [state, setter, isUpdated] = useCount();
51
- ```
52
33
 
53
- with the persist storage, the first time the hooks is called the same is gonna return the initial value, at the same time will perform an async request to the persist storage in order to get the stored value, to validate if that call was already performed, youl'll get an extra boolean item in the resulted array.
54
-
55
-
56
- ## Customize persist storage
57
-
58
- 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.
59
-
60
- ```
61
- import GlobalState from 'react-native-global-state-hooks';
62
- import secureStorage from 'react-native-secure-storage';
63
- import { IActionCollection } from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
64
-
65
- export class SecureGlobalState<
66
- IState,
67
- IPersist extends string | null = null,
68
- IsPersist extends boolean = IPersist extends null ? false : true,
69
- IActions extends IActionCollection<IState> | null = null
70
- > extends GlobalState<IState, IPersist, IsPersist, IActions> {
71
-
72
- protected asyncStorageGetItem = () => secureStorage.getItem(this.persistStoreAs as string, config);
73
-
74
- 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);
75
37
 
38
+ return (<button onPress={onClickAddTwo}>count: {count}<button/>);
76
39
  }
77
-
78
- export default SecureGlobalState;
79
40
  ```
80
41
 
81
- ## Creating hooks with reusable actions
82
-
83
- 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**:
84
-
85
- ```
86
- import * as IGlobalState from 'react-native-global-state-hooks/lib/GlobalStoreTypes';
87
- import GlobalStore from 'react-native-global-state-hooks';
88
-
89
- const countStore = new GlobalStore(0, {
90
- plus: (increase: number) => async (setter: IGlobalStore.StateSetter<number>, currentState: number) => {
91
- // perfom whatever login you want
92
- setter(currentState + increase);
93
- },
94
- decrease: (decrease: number) => async (setter: IGlobalStore.StateSetter<number>, currentState: number) => {
95
- // perfom whatever login you want
96
- setter(currentState - decrease);
97
- },
98
- });
99
-
100
- export const useCount = countStore.getHook();
42
+ Just like that! You now are using a global state.
101
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);
102
47
  ```
103
48
 
104
- Now the result of our useCount will return our actions instead of a simple setter... Let's see:
49
+ ## Persisted store
105
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');
106
57
  ```
107
- import { useCount } from './count'
108
-
109
- function Stage1() {
110
- const [count, actions] = useCount();
111
- const increaseClick = useCallback(() => actions.plus(1), []);
112
- const decreaseClick = useCallback(() => actions.decrease(1), []);
113
58
 
114
- return (<>
115
- <label>{count}<label/><br/>
116
- <button onPress={increaseClick}>increase<button/>
117
- <button onPress={decreaseClick}>decrease<button/>
118
- </>);
119
- }
59
+ ## Consuming Persisted Store
120
60
 
61
+ ```JSX
62
+ const [count, setCount, isCountUpdated] = useCountGlobal();
121
63
  ```
122
64
 
123
- You could also type the API contract, in order to take more advantage of typescript, just by passing an interface to getHook method:
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.
124
66
 
125
- ```
126
- export interface ICountActions {
127
- plus: (increase: number) => Promise<void>,
128
- decrease: (decrease: number) => Promise<void>,
129
- }
67
+ ## Decoupled hook
130
68
 
131
- export const useCount = countStore.getHook<ICountActions>();
132
- ```
133
- 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
69
+ ```JSX
70
+ import GlobalStore from 'react-native-global-state-hooks';
134
71
 
135
- ## Decoupled hook
72
+ const countStore = new GlobalStore(0);
136
73
 
137
- Finally, if you want to access the global state outside a component, or without subscribing the component to the state changes...
74
+ export const useCountGlobal = countStore.getHook();
138
75
 
139
- 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.
76
+ export const [getCountGlobalValue, setCountGlobalValue] = countStore.getHookDecoupled();
140
77
 
141
78
  ```
142
- export const useCount = countStore.getHook<ICountActions>();
143
79
 
144
- export const [getCountValue, countActions] = countStore.getHookDecoupled<ICountActions>()();
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...
81
+
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.
145
83
 
146
- ```
147
84
 
148
85
  Let's see a trivial example:
149
- ```
150
- import { useCount, countActions } from './count'
86
+ ```JSX
87
+ import { useCountGlobal, setCountGlobalValue } from './useCountGlobal'
151
88
 
152
- function Stage1() {
153
- const [count] = useCount();
89
+ const Stage1: React.FC = () => {
90
+ const [count] = useCountGlobal();
154
91
 
155
92
  return (<label>{count}<label/><br/>);
156
93
  }
157
94
 
158
- function Stage2() {
159
- const increaseClick = useCallback(() => countActions.plus(1), []);
160
- const decreaseClick = useCallback(() => countActions.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);
161
99
 
162
100
  return (<>
163
101
  <button onPress={increaseClick}>increase<button/>
@@ -166,17 +104,10 @@ function Stage2() {
166
104
  }
167
105
  ```
168
106
 
169
- 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.
170
-
171
- # Important notes:
172
- 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**...
173
-
174
- 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.
175
-
176
107
  ## Advantages:
177
108
  1. Using REACT's simplest and default way to deal with the state.
178
- 2. Adding partial state designations (This is not on useState default functionality)
179
- 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.
180
- 4. This library is already taking care of avoiding re-renders if the new state does not have changes
181
- 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
182
- 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,28 +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
20
  protected getStateCopy: () => IState;
21
- getHook: <IApi extends IGlobalStore.ActionCollectionResult<IActions> | null = IActions extends null ? null : IGlobalStore.ActionCollectionResult<IActions>>() => () => [IState, IGlobalStore.IHookResult<IState, IActions, IApi>, IsPersist extends true ? boolean : null];
22
- 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>];
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>];
23
23
  private _stateOrchestrator;
24
- protected get stateOrchestrator(): IGlobalStore.StateSetter<IState> | IGlobalStore.ActionCollectionResult<IActions>;
24
+ protected get stateOrchestrator(): IGlobalStore.StateSetter<IState> | IGlobalStore.ActionCollectionResult<IState, IActions>;
25
25
  /**
26
- ** [subscriber-update-callback, hook, newState]
26
+ ** [subscriber-update-callback, hook]
27
27
  */
28
- protected static batchedUpdates: [() => void, object, object][];
29
- protected globalSetter: (setter: Partial<IState> | ((state: IState) => Partial<IState>), callback: () => void) => void;
30
- protected globalSetterAsync: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
31
- 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>;
32
32
  static ExecutePendingBatchesCallbacks: (() => void)[];
33
33
  static ExecutePendingBatches: import("lodash").DebouncedFunc<() => void>;
34
- protected getActions: <IApi extends IGlobalStore.ActionCollectionResult<IGlobalStore.IActionCollection<IState>>>() => IApi;
34
+ protected getActions: <IApi extends IGlobalStore.ActionCollectionResult<IState, IGlobalStore.IActionCollectionConfig<IState>>>() => IApi;
35
35
  }
36
36
  export default GlobalStore;
37
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,EAAE,SAAS,EAAE,QAAQ,CAAC;IAQ/D,SAAS,CAAC,KAAK,EAAE,MAAM;IAAE,SAAS,CAAC,OAAO,EAAE,QAAQ;IAA4B,cAAc,EAAE,QAAQ;IAN7G,WAAW,EAAE,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAM;IAE5D,IAAW,cAAc,IAAI,OAAO,CAEnC;gBAEqB,KAAK,EAAE,MAAM,EAAY,OAAO,GAAE,QAA2B,EAAS,cAAc,GAAE,QAA2B;IAEvI,OAAO,KAAK,wBAAwB,GAEnC;IAED,OAAO,CAAC,eAAe,CAAiC;IAExD,SAAS,CAAC,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG;IA0B7C,SAAS,CAAC,aAAa,CAAC,C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C,IAAI,CAAC;cAIxD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUlD,SAAS,CAAC,YAAY,QAAO,MAAM,CAAyC;IAErE,OAAO,oRA2BZ;IAEK,gBAAgB,iLAGV,QAAQ,SAAS,MAAM,GAAG,QAAQ,MAAM,CAAC,GAAG,MAAM,oDAO7D;IAEF,OAAO,CAAC,kBAAkB,CAAyG;IAEnI,SAAS,KAAK,iBAAiB,IAAI,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAY1H;IAED;;MAEE;IACF,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,MAAM,IAAI,EAAE,MAAM,CAAC,EAAE,CAAM;IAE7D,SAAS,CAAC,YAAY,6BAA8B,MAAM,KAAK,MAAM,aAAa,MAAM,IAAI,UAqB1F;IAEF,SAAS,CAAC,iBAAiB,6BAAoC,MAAM,KAAK,MAAM,MAC9E,QAAQ,IAAI,CAAC,CAAyE;IAExF,SAAS,CAAC,+BAA+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,10 +16,10 @@ class GlobalStore {
16
16
  this.subscribers = [];
17
17
  this.storedStateItem = undefined;
18
18
  this.getAsyncStoreItemPromise = null;
19
- this.getStateCopy = () => Object.freeze(lodash_1.cloneDeep(this.state));
19
+ this.getStateCopy = () => Object.freeze((0, lodash_1.cloneDeep)(this.state));
20
20
  this.getHook = () => () => {
21
- const [value, setter] = react_1.useState(this.state);
22
- react_1.useEffect(() => {
21
+ const [value, setter] = (0, react_1.useState)(() => this.state);
22
+ (0, react_1.useEffect)(() => {
23
23
  this.subscribers.push(setter);
24
24
  if (this.isPersistStore) {
25
25
  this.getAsyncStoreItem();
@@ -43,26 +43,24 @@ class GlobalStore {
43
43
  };
44
44
  this._stateOrchestrator = null;
45
45
  this.globalSetter = (setter, callback) => {
46
- const partialState = typeof setter === 'function' ? setter(this.getStateCopy()) : setter;
47
- let newState = exports.isPrimitive(partialState) || Array.isArray(partialState) ? partialState : Object.assign(Object.assign({}, this.state), partialState);
48
- // avoid perform multiple update batches by accumulating state changes of the same hook
49
- GlobalStore.batchedUpdates = GlobalStore.batchedUpdates.filter(([, hook, previousState]) => {
46
+ // avoid perform multiple updates over the same state
47
+ GlobalStore.batchedUpdates = GlobalStore.batchedUpdates.filter(([, hook]) => {
50
48
  const isSameHook = hook === this;
51
49
  if (isSameHook) {
52
50
  // eslint-disable-next-line no-console
53
51
  console.warn('You should try avoid call the same state-setter multiple times at one execution line');
54
- newState = exports.isPrimitive(newState) || Array.isArray(partialState) ? newState : Object.assign(Object.assign({}, previousState), newState);
55
52
  }
56
53
  return !isSameHook;
57
54
  });
55
+ const newState = typeof setter === 'function' ? setter(this.getStateCopy()) : setter;
58
56
  this.state = newState;
59
57
  // batch store updates
60
- GlobalStore.batchedUpdates.push([() => this.subscribers.forEach((updateChild) => updateChild(newState)), this, newState]);
58
+ GlobalStore.batchedUpdates.push([() => this.subscribers.forEach((updateChild) => updateChild(newState)), this]);
61
59
  GlobalStore.ExecutePendingBatchesCallbacks.push(callback);
62
60
  GlobalStore.ExecutePendingBatches();
63
61
  };
64
- this.globalSetterAsync = (setter) => tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve) => this.globalSetter(setter, () => resolve())); });
65
- 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* () {
66
64
  yield this.globalSetterAsync(setter);
67
65
  yield this.setAsyncStoreItem();
68
66
  });
@@ -71,7 +69,7 @@ class GlobalStore {
71
69
  // Setter is allways async because of the render batch
72
70
  // but we are typing the setter as synchronous to avoid the developer has extra complexity that useState do not handle
73
71
  const setter = this.isPersistStore ? this.globalSetterToPersistStoreAsync : this.globalSetterAsync;
74
- 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* () {
75
73
  let promise;
76
74
  const setterWrapper = (value) => {
77
75
  promise = setter(value);
@@ -102,7 +100,7 @@ class GlobalStore {
102
100
  if (isDateType) {
103
101
  return Object.assign(Object.assign({}, acumulator), { [key]: new Date(unformatedValue) });
104
102
  }
105
- 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) });
106
104
  }, {});
107
105
  }
108
106
  formatToStore(obj) {
@@ -113,24 +111,24 @@ class GlobalStore {
113
111
  return Object.keys(obj).reduce((acumulator, key) => {
114
112
  const value = obj[key];
115
113
  const isDatetime = value instanceof Date;
116
- 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 }));
117
115
  }, {});
118
116
  }
119
117
  asyncStorageGetItem() {
120
118
  return async_storage_1.default.getItem(this.persistStoreAs);
121
119
  }
122
120
  getAsyncStoreItem() {
123
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
121
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
124
122
  if (this.isStoredStateItemUpdated)
125
123
  return this.storedStateItem;
126
124
  if (this.getAsyncStoreItemPromise)
127
125
  return this.getAsyncStoreItemPromise;
128
126
  this.getAsyncStoreItemPromise = new Promise((resolve) => {
129
- (() => tslib_1.__awaiter(this, void 0, void 0, function* () {
127
+ (() => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
130
128
  const item = yield this.asyncStorageGetItem();
131
129
  if (item) {
132
130
  const value = JSON.parse(item);
133
- const primitive = exports.isPrimitive(value);
131
+ const primitive = (0, exports.isPrimitive)(value);
134
132
  const newState = primitive || Array.isArray(value) ? value : this.formatItemFromStore(value);
135
133
  yield this.globalSetterAsync(newState);
136
134
  }
@@ -141,16 +139,16 @@ class GlobalStore {
141
139
  });
142
140
  }
143
141
  asyncStorageSetItem(valueToStore) {
144
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
142
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
145
143
  yield async_storage_1.default.setItem(this.persistStoreAs, valueToStore);
146
144
  });
147
145
  }
148
146
  setAsyncStoreItem() {
149
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
147
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
150
148
  if (this.storedStateItem === this.state)
151
149
  return;
152
150
  this.storedStateItem = this.state;
153
- 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));
154
152
  yield this.asyncStorageSetItem(JSON.stringify(valueToStore));
155
153
  });
156
154
  }
@@ -171,13 +169,13 @@ class GlobalStore {
171
169
  }
172
170
  exports.GlobalStore = GlobalStore;
173
171
  /**
174
- ** [subscriber-update-callback, hook, newState]
172
+ ** [subscriber-update-callback, hook]
175
173
  */
176
174
  GlobalStore.batchedUpdates = [];
177
175
  GlobalStore.ExecutePendingBatchesCallbacks = [];
178
176
  // avoid multiples calls to batchedUpdates
179
177
  // eslint-disable-next-line @typescript-eslint/no-empty-function
180
- GlobalStore.ExecutePendingBatches = lodash_1.debounce(() => {
178
+ GlobalStore.ExecutePendingBatches = (0, lodash_1.debounce)(() => {
181
179
  const reactBatchedUpdates = react_dom_1.default.unstable_batchedUpdates || ((mock) => mock());
182
180
  reactBatchedUpdates(() => {
183
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,14 +42,14 @@ 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>() => () => [
52
+ getHook: <IApi extends IActions extends ActionCollectionResult<IState, IActions> ? ActionCollectionResult<IState, IActions> : null>() => () => [
47
53
  IState,
48
54
  IHookResult<IState, IActions, IApi>,
49
55
  IsPersist extends true ? boolean : null
@@ -53,7 +59,7 @@ export interface IGlobalState<IState, IPersist extends string | null = null, IsP
53
59
  * THIS IS NOT A REACT-HOOK, so you could use it everywhere example other hooks, and services.
54
60
  * @return [currentState, GlobalState.IHookResult<IState, IActions, IApi>]
55
61
  */
56
- getHookDecoupled: <IApi extends IActions extends ActionCollectionResult<IActions> ? ActionCollectionResult<IActions> : null>() => [
62
+ getHookDecoupled: <IApi extends IActions extends ActionCollectionResult<IState, IActions> ? ActionCollectionResult<IState, IActions> : null>() => [
57
63
  () => IPersist extends string ? Promise<IState> : IState,
58
64
  IHookResult<IState, IActions, IApi>
59
65
  ];
@@ -61,6 +67,6 @@ export interface IGlobalState<IState, IPersist extends string | null = null, IsP
61
67
  /**
62
68
  * @deprecated This interface name is deprecated, use instead IGlobalState
63
69
  */
64
- 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> {
65
71
  }
66
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,MAAM,CAAC,CAAC;CAChC;AAED;;EAEE;AACF,oBAAY,sBAAsB,CAAC,QAAQ,IAAI;KAE5C,GAAG,IAAI,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO;CACtE,CAAC;AAEF;;EAEE;AACF,oBAAY,WAAW,CACrB,MAAM,EACN,QAAQ,SAAS,iBAAiB,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,EACxD,IAAI,SA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AsB,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.6",
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
  }
package/lib/.DS_Store DELETED
Binary file