react-native-global-state-hooks 4.0.6 → 4.0.7
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 +1 -1
- package/lib/GlobalStore.functions.d.ts +51 -3
- package/lib/GlobalStore.types.d.ts +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ Additionally, to subscribe to state changes, you can pass a callback function as
|
|
|
143
143
|
* This not only allows you to retrieve the current value of the state...
|
|
144
144
|
* but also enables you to subscribe to any changes in the state or a portion of it
|
|
145
145
|
*/
|
|
146
|
-
const removeSubscriptionGroup = contactsGetter(
|
|
146
|
+
const removeSubscriptionGroup = contactsGetter<Subscribe>(
|
|
147
147
|
({ subscribe, subscribeSelector }) => {
|
|
148
148
|
subscribe((state) => {
|
|
149
149
|
console.log("state changed: ", state);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionCollectionConfig, StateConfigCallbackParam, StateChangesParam, StateSetter, ActionCollectionResult, UseHookConfig, AvoidNever, GlobalStoreConfig,
|
|
1
|
+
import { ActionCollectionConfig, StateConfigCallbackParam, StateChangesParam, StateSetter, ActionCollectionResult, UseHookConfig, AvoidNever, GlobalStoreConfig, UnsubscribeCallback } from "GlobalStore.types";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a global hook that can be used to access the state and actions across the application
|
|
4
4
|
* @param {TState} state - The initial state
|
|
@@ -37,7 +37,31 @@ export declare const createGlobalStateWithDecoupledFuncs: <TState, TMetadata = n
|
|
|
37
37
|
* @returns {boolean} result - true if you want to prevent the state change, false otherwise
|
|
38
38
|
*/
|
|
39
39
|
computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => boolean;
|
|
40
|
-
}) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata], getter: <
|
|
40
|
+
}) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata], getter: <Subscription extends boolean = false>(callback?: Subscription extends true ? ({ state, subscribe, subscribeSelector, }: {
|
|
41
|
+
state: TState;
|
|
42
|
+
subscribe: (callback: (state: TState) => void, config?: {
|
|
43
|
+
/**
|
|
44
|
+
* The callback to execute when the state is changed to check if the same really changed
|
|
45
|
+
* If the function is not provided the derived state will perform a shallow comparison
|
|
46
|
+
*/
|
|
47
|
+
isEqual?: (current: TState, next: TState) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* By default the callback is executed immediately after the subscription
|
|
50
|
+
*/
|
|
51
|
+
skipFirst?: boolean;
|
|
52
|
+
}) => void;
|
|
53
|
+
subscribeSelector: <TDerivate>(selector: (state: TState) => TDerivate, callback: (state: TDerivate) => void, config?: {
|
|
54
|
+
/**
|
|
55
|
+
* The callback to execute when the state is changed to check if the same really changed
|
|
56
|
+
* If the function is not provided the derived state will perform a shallow comparison
|
|
57
|
+
*/
|
|
58
|
+
isEqual?: (current: TDerivate, next: TDerivate) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* By default the callback is executed immediately after the subscription
|
|
61
|
+
*/
|
|
62
|
+
skipFirst?: boolean;
|
|
63
|
+
}) => void;
|
|
64
|
+
}) => void : null) => Subscription extends false ? TState : UnsubscribeCallback, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
|
|
41
65
|
/**
|
|
42
66
|
* Creates a global hook that can be used to access the state and actions across the application
|
|
43
67
|
* @param {TState} state - The initial state of the store
|
|
@@ -102,7 +126,31 @@ export declare const createCustomGlobalStateWithDecoupledFuncs: <TInheritMetadat
|
|
|
102
126
|
onStateChanged?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
|
|
103
127
|
onSubscribed?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
|
|
104
128
|
computePreventStateChange?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => boolean;
|
|
105
|
-
}) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>], getter: <
|
|
129
|
+
}) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>], getter: <Subscription extends boolean = false>(callback?: Subscription extends true ? ({ state, subscribe, subscribeSelector, }: {
|
|
130
|
+
state: TState;
|
|
131
|
+
subscribe: (callback: (state: TState) => void, config?: {
|
|
132
|
+
/**
|
|
133
|
+
* The callback to execute when the state is changed to check if the same really changed
|
|
134
|
+
* If the function is not provided the derived state will perform a shallow comparison
|
|
135
|
+
*/
|
|
136
|
+
isEqual?: (current: TState, next: TState) => boolean;
|
|
137
|
+
/**
|
|
138
|
+
* By default the callback is executed immediately after the subscription
|
|
139
|
+
*/
|
|
140
|
+
skipFirst?: boolean;
|
|
141
|
+
}) => void;
|
|
142
|
+
subscribeSelector: <TDerivate>(selector: (state: TState) => TDerivate, callback: (state: TDerivate) => void, config?: {
|
|
143
|
+
/**
|
|
144
|
+
* The callback to execute when the state is changed to check if the same really changed
|
|
145
|
+
* If the function is not provided the derived state will perform a shallow comparison
|
|
146
|
+
*/
|
|
147
|
+
isEqual?: (current: TDerivate, next: TDerivate) => boolean;
|
|
148
|
+
/**
|
|
149
|
+
* By default the callback is executed immediately after the subscription
|
|
150
|
+
*/
|
|
151
|
+
skipFirst?: boolean;
|
|
152
|
+
}) => void;
|
|
153
|
+
}) => void : null) => Subscription extends false ? TState : UnsubscribeCallback, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>];
|
|
106
154
|
/**
|
|
107
155
|
* @description
|
|
108
156
|
* Use this function to create a custom global store.
|
|
@@ -288,9 +288,13 @@ export type SubscriberCallback<TState> = ({ subscribe, }: {
|
|
|
288
288
|
* if you don't pass a callback function the hook will return the current state of the store
|
|
289
289
|
* @returns {UnsubscribeCallback | TState} result - the state or the unsubscribe callback if you pass a callback function
|
|
290
290
|
*/
|
|
291
|
-
export type StateGetter<TState> = <
|
|
291
|
+
export type StateGetter<TState> = <Subscription extends Subscribe | false = false>(
|
|
292
292
|
/**
|
|
293
293
|
* @param {SubscriberCallback<TState> | null} callback - the callback function to subscribe to the store changes (optional)
|
|
294
294
|
* use the methods subscribe and subscribeSelect to subscribe to the store changes
|
|
295
295
|
*/
|
|
296
|
-
callback?:
|
|
296
|
+
callback?: Subscription extends Subscribe ? SubscriberCallback<TState> : null) => Subscription extends Subscribe ? UnsubscribeCallback : TState;
|
|
297
|
+
/**
|
|
298
|
+
* Constant value type to indicate that the getter is a subscription
|
|
299
|
+
*/
|
|
300
|
+
export type Subscribe = true;
|
package/package.json
CHANGED