react-hooks-global-states 15.0.4 → 15.0.6
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/createContext.d.ts +4 -3
- package/createGlobalState.d.ts +26 -2
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/createContext.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { type PropsWithChildren, Context as ReactContext } from 'react';
|
|
2
2
|
import { GlobalStore } from './GlobalStore';
|
|
3
3
|
import type { BaseMetadata, GlobalStoreCallbacks as GlobalStoreCallbacksBase, UseHookOptions, AnyFunction, StoreTools, ReadonlyStateApi, SelectHook, ObservableFragment, StateApi, UnsubscribeCallback } from './types';
|
|
4
|
+
import { AnyActions } from 'createGlobalState';
|
|
4
5
|
type GlobalStoreContextCallbacks<State, StateMutator, Metadata extends BaseMetadata> = {
|
|
5
6
|
/**
|
|
6
7
|
* @description Optional callback invoked after the context is created,
|
|
@@ -405,7 +406,7 @@ interface CreateContext {
|
|
|
405
406
|
args: {
|
|
406
407
|
name?: string;
|
|
407
408
|
metadata?: Metadata | (() => Metadata);
|
|
408
|
-
callbacks?: GlobalStoreCallbacks<State,
|
|
409
|
+
callbacks?: GlobalStoreCallbacks<State, AnyActions, Metadata>;
|
|
409
410
|
actions?: ActionsConfig;
|
|
410
411
|
}): {
|
|
411
412
|
/**
|
|
@@ -469,7 +470,7 @@ interface CreateContext {
|
|
|
469
470
|
* - **`Context`** — The raw React `Context` object for advanced usage, such as integration with
|
|
470
471
|
* external tools or non-React consumers.
|
|
471
472
|
*/
|
|
472
|
-
<State, Metadata extends BaseMetadata, ActionsConfig extends ContextActionCollectionConfig<State, Metadata
|
|
473
|
+
<State, Metadata extends BaseMetadata, ActionsConfig extends ContextActionCollectionConfig<State, Metadata>>(
|
|
473
474
|
/**
|
|
474
475
|
* @description Initial state value or initializer function.
|
|
475
476
|
*/
|
|
@@ -484,7 +485,7 @@ interface CreateContext {
|
|
|
484
485
|
args: {
|
|
485
486
|
name?: string;
|
|
486
487
|
metadata?: Metadata | (() => Metadata);
|
|
487
|
-
callbacks?: GlobalStoreCallbacks<State,
|
|
488
|
+
callbacks?: GlobalStoreCallbacks<State, AnyActions, Metadata>;
|
|
488
489
|
actions: ActionsConfig;
|
|
489
490
|
}): {
|
|
490
491
|
/**
|
package/createGlobalState.d.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import type { ActionCollectionConfig, ActionCollectionResult, StateHook, BaseMetadata, GlobalStoreCallbacks, StoreTools } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Typescript is unable to infer the actions type correctly for the lifecycle callbacks
|
|
4
|
+
* so we use a generic AnyActions type here to bypass that limitation.
|
|
5
|
+
*
|
|
6
|
+
* The parameter could still be typed before using it with
|
|
7
|
+
* ```ts
|
|
8
|
+
* type StoreTools = InferStateApi<typeof <hook>>;
|
|
9
|
+
*
|
|
10
|
+
* onInit: (tools) => {
|
|
11
|
+
* const storeTools = tools as StoreTools;
|
|
12
|
+
* // ...
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* or when dealing with context:
|
|
16
|
+
*
|
|
17
|
+
* type ContextApi = InferContextApi<typeof <context>>;
|
|
18
|
+
*
|
|
19
|
+
* onInit: (tools) => {
|
|
20
|
+
* const storeTools = tools as ContextApi;
|
|
21
|
+
* // ...
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type AnyActions = Record<string, (...args: any[]) => any>;
|
|
2
26
|
interface CreateGlobalState {
|
|
3
27
|
/**
|
|
4
28
|
* Creates a global state hook.
|
|
@@ -89,7 +113,7 @@ interface CreateGlobalState {
|
|
|
89
113
|
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
90
114
|
name?: string;
|
|
91
115
|
metadata?: Metadata;
|
|
92
|
-
callbacks?: GlobalStoreCallbacks<State,
|
|
116
|
+
callbacks?: GlobalStoreCallbacks<State, AnyActions, Metadata>;
|
|
93
117
|
actions?: ActionsConfig;
|
|
94
118
|
}): StateHook<State, PublicStateMutator, Metadata>;
|
|
95
119
|
/**
|
|
@@ -144,7 +168,7 @@ interface CreateGlobalState {
|
|
|
144
168
|
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>, PublicStateMutator = ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
145
169
|
name?: string;
|
|
146
170
|
metadata?: Metadata;
|
|
147
|
-
callbacks?: GlobalStoreCallbacks<State,
|
|
171
|
+
callbacks?: GlobalStoreCallbacks<State, AnyActions, Metadata>;
|
|
148
172
|
actions: ActionsConfig;
|
|
149
173
|
}): StateHook<State, PublicStateMutator, Metadata>;
|
|
150
174
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { StateApi, ObservableFragment, MetadataSetter, StateChanges, StoreTools, ActionCollectionResult, GlobalStoreCallbacks, UseHookOptions, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, BaseMetadata, MetadataGetter, SelectorCallback, SubscriberParameters, SubscriptionCallback, StateHook, ActionCollectionConfig, } from './types';
|
|
2
2
|
export { GlobalStore } from './GlobalStore';
|
|
3
|
-
export { createGlobalState, type InferActionsType, type InferStateApi } from './createGlobalState';
|
|
3
|
+
export { createGlobalState, type InferActionsType, type InferStateApi, AnyActions, } from './createGlobalState';
|
|
4
4
|
export { shallowCompare } from './shallowCompare';
|
|
5
5
|
export { uniqueId, type BrandedId } from './uniqueId';
|
|
6
6
|
export { throwWrongKeyOnActionCollectionConfig } from './throwWrongKeyOnActionCollectionConfig';
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ export type StateChanges<State> = {
|
|
|
180
180
|
**/
|
|
181
181
|
export type StoreTools<State, StateMutator = React.Dispatch<React.SetStateAction<State>>, Metadata extends BaseMetadata = BaseMetadata> = {
|
|
182
182
|
/**
|
|
183
|
-
* The actions available for the global state
|
|
183
|
+
* The actions available for the global state if provided
|
|
184
184
|
*/
|
|
185
185
|
actions: StateMutator extends AnyFunction ? null : StateMutator;
|
|
186
186
|
/**
|