react-global-state-hooks 1.1.2 → 2.0.1
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 +574 -499
- package/lib/bundle.js +1 -2
- package/lib/src/GlobalStore.d.ts +18 -0
- package/lib/src/GlobalStore.functionHooks.d.ts +18 -0
- package/lib/src/GlobalStore.types.d.ts +43 -0
- package/lib/src/GlobalStore.utils.d.ts +18 -0
- package/lib/src/GlobalStoreAbstract.d.ts +16 -0
- package/lib/src/index.d.ts +12 -0
- package/package.json +7 -6
- package/lib/GlobalStore.d.ts +0 -66
- package/lib/GlobalStore.types.d.ts +0 -24
- package/lib/bundle.js.LICENSE.txt +0 -1
- package/lib/index.d.ts +0 -2
package/lib/GlobalStore.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { GlobalStore as GlobalStoreBase } from 'react-native-global-state-hooks';
|
|
2
|
-
import { ActionCollectionConfig, ActionCollectionResult, GlobalStoreConfig, StateConfigCallbackParam, StateSetter } from './GlobalStore.types';
|
|
3
|
-
export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> | null = StateSetter<TState>> extends GlobalStoreBase<TState, TMetadata, TStateSetter> {
|
|
4
|
-
/**
|
|
5
|
-
* Returns a custom hook that allows to handle a global state
|
|
6
|
-
* @returns {[TState, TStateSetter, TMetadata]} - The state, the state setter or the actions map, the metadata
|
|
7
|
-
* */
|
|
8
|
-
getHook: () => () => [
|
|
9
|
-
TState,
|
|
10
|
-
TStateSetter extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>,
|
|
11
|
-
TMetadata
|
|
12
|
-
];
|
|
13
|
-
/**
|
|
14
|
-
* Returns an array with the a function to get the state, the state setter or the actions map, and a function to get the metadata
|
|
15
|
-
* @returns {[() => TState, TStateSetter, () => TMetadata]} - The state getter, the state setter or the actions map, the metadata getter
|
|
16
|
-
* */
|
|
17
|
-
getHookDecoupled: () => [
|
|
18
|
-
() => TState,
|
|
19
|
-
TStateSetter extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>,
|
|
20
|
-
() => TMetadata
|
|
21
|
-
];
|
|
22
|
-
/**
|
|
23
|
-
* additional configuration for the store
|
|
24
|
-
* @template {TState} TState - The type of the state object
|
|
25
|
-
* @template {TMetadata} TMetadata - The type of the metadata object (optional) (default: null) no reactive information set to share with the subscribers
|
|
26
|
-
* @template {TStateSetter} TStateSetter - The type of the setterConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
|
|
27
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
|
|
28
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
|
|
29
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
|
|
30
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.onSubscribed - The callback to execute when a component is subscribed to the store (optional) (default: null)
|
|
31
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
|
|
32
|
-
* @property {GlobalStoreConfig<TState, TMetadata, TStateSetter>} config.localStorageKey - The key to use to store the state in the localStorage (optional) (default: null) if not null the state will be stored in the localStorage
|
|
33
|
-
*/
|
|
34
|
-
protected config: GlobalStoreConfig<TState, TMetadata, TStateSetter>;
|
|
35
|
-
/**
|
|
36
|
-
* Create a new instance of the GlobalStore
|
|
37
|
-
* @param {TState} state - The initial state
|
|
38
|
-
* @param {TStateSetter} setterConfig - The actions configuration object (optional) (default: null) if not null the store manipulation will be done through the actions
|
|
39
|
-
* @param {GlobalStoreConfig<TState, TMetadata>} config - The configuration object (optional) (default: { metadata: null })
|
|
40
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.metadata - The metadata to pass to the callbacks (optional) (default: null)
|
|
41
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.onInit - The callback to execute when the store is initialized (optional) (default: null)
|
|
42
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.onStateChanged - The callback to execute when the state is changed (optional) (default: null)
|
|
43
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.onSubscribed - The callback to execute when a subscriber is added (optional) (default: null)
|
|
44
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.computePreventStateChange - The callback to execute when the state is changed to compute if the state change should be prevented (optional) (default: null)
|
|
45
|
-
* @param {StateConfigCallbackParam<TState, TMetadata>} config.localStorageKey - The key to use to store the state in the localStorage (optional) (default: null) if not null the state will be stored in the localStorage
|
|
46
|
-
* */
|
|
47
|
-
constructor(state: TState, config: GlobalStoreConfig<TState, TMetadata, TStateSetter>, setterConfig?: TStateSetter | null);
|
|
48
|
-
protected setLocalStorageValue: () => void;
|
|
49
|
-
protected getLocalStorageValue: () => string;
|
|
50
|
-
/**
|
|
51
|
-
* This method will be called once the store is created after the constructor,
|
|
52
|
-
* this method is different from the onInit of the confg property and it won't be overriden
|
|
53
|
-
*/
|
|
54
|
-
protected onInit: ({ setState, }: StateConfigCallbackParam<TState, TMetadata, TStateSetter>) => Promise<void>;
|
|
55
|
-
protected onStateChanged: () => void;
|
|
56
|
-
/**
|
|
57
|
-
* set the state and update all the subscribers,
|
|
58
|
-
* In react web ReacDom allows to batch the state updates, this method will use the unstable_batchedUpdates method if it exists
|
|
59
|
-
* @param {StateSetter<TState>} setter - The setter function or the value to set
|
|
60
|
-
* @param {React.Dispatch<React.SetStateAction<TState>>} invokerSetState - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
|
|
61
|
-
* */
|
|
62
|
-
protected setState: ({ invokerSetState, state, }: {
|
|
63
|
-
state: TState;
|
|
64
|
-
invokerSetState?: React.Dispatch<React.SetStateAction<TState>>;
|
|
65
|
-
}) => void;
|
|
66
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as TGlobalStoreBase from 'react-native-global-state-hooks/lib/GlobalStore.types';
|
|
2
|
-
export type StateSetter<TState> = TGlobalStoreBase.StateSetter<TState>;
|
|
3
|
-
export type StateChanges<TState> = TGlobalStoreBase.StateChanges<TState>;
|
|
4
|
-
export type StoreTools<TState, TMetadata = null> = TGlobalStoreBase.StoreTools<TState, TMetadata>;
|
|
5
|
-
export interface ActionCollectionConfig<TState, TMetadata> extends TGlobalStoreBase.ActionCollectionConfig<TState, TMetadata> {
|
|
6
|
-
}
|
|
7
|
-
export type ActionCollectionResult<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = TGlobalStoreBase.ActionCollectionResult<TState, TMetadata, TStateSetter>;
|
|
8
|
-
export type StateConfigCallbackParam<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = TGlobalStoreBase.StateConfigCallbackParam<TState, TMetadata, TStateSetter>;
|
|
9
|
-
export type StateChangesParam<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = TGlobalStoreBase.StateChangesParam<TState, TMetadata, TStateSetter>;
|
|
10
|
-
/**
|
|
11
|
-
* Configuration of the store (optional) - if you don't need to use the store configuration you don't need to pass this parameter
|
|
12
|
-
* @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
|
|
13
|
-
* @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
|
|
14
|
-
* @param {StateChangesParam<TState, TMetadata> => boolean} computePreventStateChange - callback function called every time the state is changed and it allows you to prevent the state change
|
|
15
|
-
* @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
|
|
16
|
-
* @template TState - the type of the state
|
|
17
|
-
* @template TMetadata - the type of the metadata (optional) - if you don't pass an metadata as a parameter, you can pass null
|
|
18
|
-
* @template {ActionCollectionConfig<TState,TMetadata> | null} TStateSetter - the configuration of the API (optional) - if you don't pass an API as a parameter, you can pass null
|
|
19
|
-
* */
|
|
20
|
-
export type GlobalStoreConfig<TState, TMetadata, TStateSetter extends TGlobalStoreBase.ActionCollectionConfig<TState, TMetadata> | TGlobalStoreBase.StateSetter<TState> = TGlobalStoreBase.StateSetter<TState>> = TGlobalStoreBase.GlobalStoreConfig<TState, TMetadata, TStateSetter> & {
|
|
21
|
-
localStorageKey?: string;
|
|
22
|
-
encrypt?: boolean | ((value: string) => string);
|
|
23
|
-
decrypt?: boolean | ((value: string) => string);
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
package/lib/index.d.ts
DELETED