beestate 0.1.9 → 0.1.11
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/dist/@types/InternalStore.d.ts +17 -10
- package/dist/@types/StoreProvider.d.ts +3 -8
- package/dist/@types/constants.d.ts +3 -0
- package/dist/@types/createStore.d.ts +5 -2
- package/dist/@types/createStoreRegistry.d.ts +3 -2
- package/dist/@types/createUseStore.d.ts +2 -4
- package/dist/@types/ensureInternalStore.d.ts +6 -0
- package/dist/@types/index.d.ts +3 -4
- package/dist/@types/types/DeferredAction.d.ts +7 -0
- package/dist/@types/types/InitInstance.d.ts +3 -3
- package/dist/@types/types/InitializedStateLink.d.ts +11 -0
- package/dist/@types/types/InitializedStoreInstance.d.ts +5 -0
- package/dist/@types/types/InstanceKeyStateLink.d.ts +11 -0
- package/dist/@types/types/InternalStore/ApplyState.d.ts +5 -0
- package/dist/@types/types/InternalStore/Dispatch.d.ts +1 -1
- package/dist/@types/types/InternalStore/EnsureInstance.d.ts +4 -0
- package/dist/@types/types/InternalStore/GetInitializedInstance.d.ts +6 -0
- package/dist/@types/types/InternalStore/GetInstance.d.ts +6 -0
- package/dist/@types/types/InternalStore/GetUninitializedInstance.d.ts +6 -0
- package/dist/@types/types/InternalStore/InitInstance.d.ts +2 -4
- package/dist/@types/types/InternalStore/IsInitialized.d.ts +4 -0
- package/dist/@types/types/InternalStore/Listener.d.ts +1 -1
- package/dist/@types/types/InternalStore/ListenerAll.d.ts +1 -1
- package/dist/@types/types/InternalStore/PruneInstance.d.ts +4 -0
- package/dist/@types/types/InternalStore/ResetInstance.d.ts +3 -3
- package/dist/@types/types/InternalStoreProps.d.ts +2 -2
- package/dist/@types/types/ReducerMap.d.ts +2 -2
- package/dist/@types/types/RegisterDefaultInstance.d.ts +3 -3
- package/dist/@types/types/RegisterInstance.d.ts +3 -3
- package/dist/@types/types/ResetInstance.d.ts +2 -3
- package/dist/@types/types/Store.d.ts +4 -0
- package/dist/@types/types/StoreContextValue.d.ts +6 -0
- package/dist/@types/types/StoreInstance.d.ts +8 -0
- package/dist/@types/types/StoreProviderProps.d.ts +10 -0
- package/dist/@types/types/StoreRegistry.d.ts +2 -2
- package/dist/@types/types/UninitializedStoreInstance.d.ts +5 -0
- package/dist/@types/types/UseProp.d.ts +4 -0
- package/dist/cjs/index.cjs.js +286 -199
- package/dist/esm/index.esm.js +287 -200
- package/package.json +1 -1
- package/dist/@types/createStoreController.d.ts +0 -6
- package/dist/@types/types/InitPayload.d.ts +0 -3
- package/dist/@types/types/ResetPayload.d.ts +0 -3
- package/dist/@types/types/StoreController.d.ts +0 -10
- package/dist/@types/types/StoreInstanceController.d.ts +0 -7
|
@@ -2,22 +2,29 @@ import type { Dispatch } from './types/InternalStore/Dispatch.tsx';
|
|
|
2
2
|
import type { GetState } from './types/InternalStore/GetState.tsx';
|
|
3
3
|
import type { GetStateAll } from './types/InternalStore/GetStateAll.tsx';
|
|
4
4
|
import type { InitInstance } from './types/InternalStore/InitInstance.tsx';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { ResetPayload } from './types/ResetPayload.tsx';
|
|
5
|
+
import type { IsInitialized } from './types/InternalStore/IsInitialized.tsx';
|
|
6
|
+
import type { ResetInstance } from './types/InternalStore/ResetInstance.tsx';
|
|
8
7
|
import type { StoreState } from './types/StoreState.tsx';
|
|
9
8
|
import type { Subscribe } from './types/InternalStore/Subscribe.tsx';
|
|
10
9
|
import type { SubscribeAll } from './types/InternalStore/SubscribeAll.tsx';
|
|
11
|
-
export declare class InternalStore<TStoreState extends StoreState = StoreState
|
|
12
|
-
private
|
|
13
|
-
private listenersAll;
|
|
14
|
-
name: string;
|
|
15
|
-
private
|
|
10
|
+
export declare class InternalStore<TStoreState extends StoreState = StoreState> {
|
|
11
|
+
private readonly instances;
|
|
12
|
+
private readonly listenersAll;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
private stateAll;
|
|
16
15
|
constructor(name: string);
|
|
16
|
+
private applyState;
|
|
17
|
+
dispatch: Dispatch<TStoreState>;
|
|
18
|
+
private ensureInstance;
|
|
19
|
+
private getInstance;
|
|
20
|
+
private getInitializedInstance;
|
|
17
21
|
getState: GetState<TStoreState>;
|
|
18
22
|
getStateAll: GetStateAll<TStoreState>;
|
|
19
|
-
|
|
23
|
+
private getUninitializedInstance;
|
|
24
|
+
initInstance: InitInstance<TStoreState>;
|
|
25
|
+
isInitialized: IsInitialized;
|
|
26
|
+
private pruneInstance;
|
|
27
|
+
resetInstance: ResetInstance<TStoreState>;
|
|
20
28
|
subscribe: Subscribe<TStoreState>;
|
|
21
29
|
subscribeAll: SubscribeAll<TStoreState>;
|
|
22
|
-
dispatch: Dispatch<TStoreState>;
|
|
23
30
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { InstanceKey } from './types/InstanceKey.tsx';
|
|
1
|
+
import type { createUseStore } from './createUseStore.tsx';
|
|
3
2
|
import type { ReducerMap } from './types/ReducerMap.tsx';
|
|
4
|
-
import type {
|
|
3
|
+
import type { StoreProviderProps } from './types/StoreProviderProps.tsx';
|
|
5
4
|
import type { StoreState } from './types/StoreState.tsx';
|
|
6
|
-
export
|
|
7
|
-
instanceKey: InstanceKey;
|
|
8
|
-
store: Store<TStoreName, TStoreState, TReducerMap>;
|
|
9
|
-
}>;
|
|
10
|
-
export declare function StoreProvider<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>({ children, instanceKey, store, }: StoreProviderProps<TStoreName, TStoreState, TReducerMap>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function createStoreProvider(useStore: ReturnType<typeof createUseStore>): <TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(props: StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const DEFAULT_INSTANCE_KEY: unique symbol;
|
|
2
2
|
export declare const DESTROY: unique symbol;
|
|
3
|
+
export declare const INITIALIZED_STATE_NAME: "$$initialized";
|
|
4
|
+
export declare const INSTANCE_KEY_STATE_NAME: "$$instanceKey";
|
|
5
|
+
export declare const INTERNAL_BUG_MESSAGE = "This must never happen and may mean a bug inside the library itself. Please report it to the library developers.";
|
|
3
6
|
export declare const INTERNAL_STORE_PROPS_ACCESSOR: unique symbol;
|
|
4
7
|
export declare const REDUCER_LINK: unique symbol;
|
|
5
8
|
export declare const STATE_LINK: unique symbol;
|
|
@@ -2,8 +2,11 @@ import type { Payload } from './types/Payload.tsx';
|
|
|
2
2
|
import type { ReducerMap } from './types/ReducerMap.tsx';
|
|
3
3
|
import type { Store } from './types/Store.tsx';
|
|
4
4
|
import type { StoreState } from './types/StoreState.tsx';
|
|
5
|
+
type CheckInitialState<TStoreState extends StoreState = StoreState> = {
|
|
6
|
+
[TKey in keyof TStoreState]: TKey extends `$$initialized` | `$$instanceKey` ? void : TStoreState[TKey];
|
|
7
|
+
};
|
|
5
8
|
type CheckReducerMap<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
|
|
6
|
-
[TKey in keyof TReducerMap]: TKey extends keyof TStoreState ? void : TReducerMap[TKey] extends (state: any, payload: void) => any ? TReducerMap[TKey] : TReducerMap[TKey] extends (state: any, payload: infer TPayload) => any ? TPayload extends Payload ? TReducerMap[TKey] : void : void;
|
|
9
|
+
[TKey in keyof TReducerMap]: TKey extends `$$initialized` | `$$instanceKey` ? void : TKey extends keyof TStoreState ? void : TReducerMap[TKey] extends (state: any, payload: void) => any ? TReducerMap[TKey] : TReducerMap[TKey] extends (state: any, payload: infer TPayload) => any ? TPayload extends Payload ? TReducerMap[TKey] : void : void;
|
|
7
10
|
};
|
|
8
|
-
export declare function createStore<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(name: TStoreName, initialState: TStoreState
|
|
11
|
+
export declare function createStore<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(name: TStoreName, initialState: TStoreState & CheckInitialState<TStoreState>, reducerMap: TReducerMap & CheckReducerMap<TStoreState, TReducerMap>): Store<TStoreName, TStoreState, TReducerMap>;
|
|
9
12
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StoreRegistry } from './types/StoreRegistry.tsx';
|
|
2
2
|
export declare function createStoreRegistry(): {
|
|
3
3
|
storeRegistry: StoreRegistry;
|
|
4
|
+
StoreProvider: <TStoreName extends string = string, TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(props: import("./types/StoreProviderProps.tsx").StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element;
|
|
4
5
|
useStore: {
|
|
5
|
-
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState
|
|
6
|
-
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState
|
|
6
|
+
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TStoreState>): void;
|
|
7
|
+
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TStoreState>): void;
|
|
7
8
|
};
|
|
8
9
|
useProp: import("./types/UseProp.tsx").UseProp;
|
|
9
10
|
usePropAll: import("./types/UsePropAll.tsx").UsePropAll;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { InitPayload } from './types/InitPayload.tsx';
|
|
2
1
|
import type { InstanceKey } from './types/InstanceKey.tsx';
|
|
3
2
|
import type { ReducerMap } from './types/ReducerMap.tsx';
|
|
4
3
|
import type { RegisterDefaultInstance } from './types/RegisterDefaultInstance.tsx';
|
|
5
4
|
import type { RegisterInstance } from './types/RegisterInstance.tsx';
|
|
6
|
-
import type { ResetPayload } from './types/ResetPayload.tsx';
|
|
7
5
|
import type { Store } from './types/Store.tsx';
|
|
8
6
|
import type { StoreRegistry } from './types/StoreRegistry.tsx';
|
|
9
7
|
import type { StoreState } from './types/StoreState.tsx';
|
|
10
8
|
export declare function createUseStore(storeRegistry: StoreRegistry): {
|
|
11
|
-
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState
|
|
12
|
-
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState
|
|
9
|
+
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(store: Store<string, TStoreState, TReducerMap>, registerInstance: RegisterDefaultInstance<TStoreState>): void;
|
|
10
|
+
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(store: Store<string, TStoreState, TReducerMap>, instanceKeys: InstanceKey[], registerInstance: RegisterInstance<TStoreState>): void;
|
|
13
11
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InternalStoreProps } from './types/InternalStoreProps.tsx';
|
|
2
|
+
import type { ReducerMap } from './types/ReducerMap.tsx';
|
|
3
|
+
import type { StoreRegistry } from './types/StoreRegistry.tsx';
|
|
4
|
+
import type { StoreState } from './types/StoreState.tsx';
|
|
5
|
+
import { InternalStore } from './InternalStore.tsx';
|
|
6
|
+
export declare function ensureInternalStore<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(storeRegistry: StoreRegistry, internalStoreProps: InternalStoreProps<string, TStoreState, TReducerMap>): InternalStore<TStoreState>;
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -11,8 +11,7 @@ export { createStoreRegistry } from './createStoreRegistry.tsx';
|
|
|
11
11
|
export { InternalStore } from './InternalStore.tsx';
|
|
12
12
|
export { requestState } from './requestState.tsx';
|
|
13
13
|
export { requestStatus } from './requestStatus.tsx';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState
|
|
17
|
-
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TInitPayload extends import("./types/InitPayload.tsx").InitPayload<TReducerMap> = import("./types/InitPayload.tsx").InitPayload<TReducerMap>, TResetPayload extends import("./types/ResetPayload.tsx").ResetPayload<TReducerMap> = import("./types/ResetPayload.tsx").ResetPayload<TReducerMap>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TInitPayload, TResetPayload>): void;
|
|
14
|
+
export declare const StoreProvider: <TStoreName extends string = string, TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(props: import("./types/StoreProviderProps.tsx").StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element, useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TPayload extends import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]> = import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>) => import("./types/Dispatcher.tsx").Dispatcher<TPayload>, useProp: import("./types/UseProp.tsx").UseProp, usePropAll: import("./types/UsePropAll.tsx").UsePropAll, useStore: {
|
|
15
|
+
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TStoreState>): void;
|
|
16
|
+
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TStoreState>): void;
|
|
18
17
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Payload } from './Payload.tsx';
|
|
2
|
+
import type { Reducer } from './Reducer.tsx';
|
|
3
|
+
import type { StoreState } from './StoreState.tsx';
|
|
4
|
+
export type DeferredAction<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
payload: void | Payload;
|
|
6
|
+
reducer: Reducer<TStoreState, any>;
|
|
7
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Payload } from './Payload.tsx';
|
|
2
1
|
import type { ResetInstance } from './ResetInstance.tsx';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { StoreState } from './StoreState.tsx';
|
|
3
|
+
export type InitInstance<TStoreState extends StoreState = StoreState> = {
|
|
4
|
+
(prefill?: Partial<TStoreState>): ResetInstance;
|
|
5
5
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INITIALIZED_STATE_NAME } from '../constants.tsx';
|
|
2
|
+
import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
|
|
3
|
+
import { STATE_LINK } from '../constants.tsx';
|
|
4
|
+
import type { InternalStoreProps } from './InternalStoreProps.tsx';
|
|
5
|
+
import type { ReducerMap } from './ReducerMap.tsx';
|
|
6
|
+
import type { StoreState } from './StoreState.tsx';
|
|
7
|
+
export type InitializedStateLink<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
|
|
8
|
+
[INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
|
|
9
|
+
stateName: typeof INITIALIZED_STATE_NAME;
|
|
10
|
+
type: typeof STATE_LINK;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INSTANCE_KEY_STATE_NAME } from '../constants.tsx';
|
|
2
|
+
import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
|
|
3
|
+
import { STATE_LINK } from '../constants.tsx';
|
|
4
|
+
import type { InternalStoreProps } from './InternalStoreProps.tsx';
|
|
5
|
+
import type { ReducerMap } from './ReducerMap.tsx';
|
|
6
|
+
import type { StoreState } from './StoreState.tsx';
|
|
7
|
+
export type InstanceKeyStateLink<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
|
|
8
|
+
[INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
|
|
9
|
+
stateName: typeof INSTANCE_KEY_STATE_NAME;
|
|
10
|
+
type: typeof STATE_LINK;
|
|
11
|
+
};
|
|
@@ -3,5 +3,5 @@ import type { Payload } from '../Payload.tsx';
|
|
|
3
3
|
import type { Reducer } from '../Reducer.tsx';
|
|
4
4
|
import type { StoreState } from '../StoreState.tsx';
|
|
5
5
|
export type Dispatch<TStoreState extends StoreState = StoreState> = {
|
|
6
|
-
<TPayload extends void | Payload = void | Payload>(instanceKey: InstanceKey,
|
|
6
|
+
<TPayload extends void | Payload = void | Payload>(instanceKey: InstanceKey, reducer: Reducer<TStoreState, TPayload>, payload: TPayload): void;
|
|
7
7
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InitializedStoreInstance } from '../InitializedStoreInstance.tsx';
|
|
2
|
+
import type { InstanceKey } from '../InstanceKey.tsx';
|
|
3
|
+
import type { StoreState } from '../StoreState.tsx';
|
|
4
|
+
export type GetInitializedInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(instanceKey: InstanceKey): InitializedStoreInstance<TStoreState>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InstanceKey } from '../InstanceKey.tsx';
|
|
2
|
+
import type { StoreInstance } from '../StoreInstance.tsx';
|
|
3
|
+
import type { StoreState } from '../StoreState.tsx';
|
|
4
|
+
export type GetInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(instanceKey: InstanceKey): StoreInstance<TStoreState>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InstanceKey } from '../InstanceKey.tsx';
|
|
2
|
+
import type { StoreState } from '../StoreState.tsx';
|
|
3
|
+
import type { UninitializedStoreInstance } from '../UninitializedStoreInstance.tsx';
|
|
4
|
+
export type GetUninitializedInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(instanceKey: InstanceKey): UninitializedStoreInstance<TStoreState>;
|
|
6
|
+
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { InstanceKey } from '../InstanceKey.tsx';
|
|
2
|
-
import type { Payload } from '../Payload.tsx';
|
|
3
2
|
import type { Reducer } from '../Reducer.tsx';
|
|
4
|
-
import type { ResetInstance } from './ResetInstance.tsx';
|
|
5
3
|
import type { StoreState } from '../StoreState.tsx';
|
|
6
|
-
export type InitInstance<TStoreState extends StoreState = StoreState
|
|
7
|
-
(instanceKey: InstanceKey,
|
|
4
|
+
export type InitInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Partial<TStoreState>>, initialState: TStoreState, prefill?: Partial<TStoreState>): void;
|
|
8
6
|
};
|
|
@@ -3,5 +3,5 @@ import type { Payload } from '../Payload.tsx';
|
|
|
3
3
|
import type { Reducer } from '../Reducer.tsx';
|
|
4
4
|
import type { StoreState } from '../StoreState.tsx';
|
|
5
5
|
export type Listener<TStoreState extends StoreState = StoreState> = {
|
|
6
|
-
<TPayload extends void | Payload = void | Payload, TReducer extends Reducer<TStoreState, TPayload> = Reducer<TStoreState, TPayload>>(instanceKey: InstanceKey,
|
|
6
|
+
<TPayload extends void | Payload = void | Payload, TReducer extends Reducer<TStoreState, TPayload> = Reducer<TStoreState, TPayload>>(instanceKey: InstanceKey, reducer: TReducer, payload: TPayload): void;
|
|
7
7
|
};
|
|
@@ -3,5 +3,5 @@ import type { Payload } from '../Payload.tsx';
|
|
|
3
3
|
import type { Reducer } from '../Reducer.tsx';
|
|
4
4
|
import type { StoreState } from '../StoreState.tsx';
|
|
5
5
|
export type ListenerAll<TStoreState extends StoreState = StoreState> = {
|
|
6
|
-
<TPayload extends void | Payload = void | Payload, TReducer extends Reducer<TStoreState, TPayload> = Reducer<TStoreState, TPayload>>(instanceKey: InstanceKey,
|
|
6
|
+
<TPayload extends void | Payload = void | Payload, TReducer extends Reducer<TStoreState, TPayload> = Reducer<TStoreState, TPayload>>(instanceKey: InstanceKey, reducer: TReducer, payload: TPayload): void;
|
|
7
7
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InstanceKey } from '../InstanceKey.tsx';
|
|
2
2
|
import type { Reducer } from '../Reducer.tsx';
|
|
3
3
|
import type { StoreState } from '../StoreState.tsx';
|
|
4
|
-
export type ResetInstance<TStoreState extends StoreState = StoreState
|
|
5
|
-
(
|
|
4
|
+
export type ResetInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(instanceKey: InstanceKey, resetReducer: Reducer<TStoreState, void>): void;
|
|
6
6
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { InstanceKey } from './InstanceKey.tsx';
|
|
3
2
|
import type { ReducerMap } from './ReducerMap.tsx';
|
|
3
|
+
import type { StoreContextValue } from './StoreContextValue.tsx';
|
|
4
4
|
import type { StoreState } from './StoreState.tsx';
|
|
5
5
|
export type InternalStoreProps<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
|
|
6
6
|
$$init: TReducerMap[`$$init`];
|
|
7
7
|
$$reset: TReducerMap[`$$reset`];
|
|
8
|
-
context: React.Context<null |
|
|
8
|
+
context: React.Context<null | StoreContextValue<TStoreState>>;
|
|
9
9
|
initialState: TStoreState;
|
|
10
10
|
name: TStoreName;
|
|
11
11
|
uniqKey: symbol;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Reducer } from './Reducer.tsx';
|
|
2
2
|
import type { StoreState } from './StoreState.tsx';
|
|
3
3
|
export type ReducerMap<TStoreState extends StoreState = StoreState> = Record<string, Reducer<TStoreState, void | any>> & {
|
|
4
|
-
$$init: Reducer<TStoreState,
|
|
5
|
-
$$reset: Reducer<TStoreState, void
|
|
4
|
+
$$init: Reducer<TStoreState, Partial<TStoreState>>;
|
|
5
|
+
$$reset: Reducer<TStoreState, void>;
|
|
6
6
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { STORE_INSTANCE_UNREGISTERED } from '../constants.tsx';
|
|
2
2
|
import type { InitInstance } from './InitInstance.tsx';
|
|
3
|
-
import type {
|
|
4
|
-
export type RegisterDefaultInstance<
|
|
5
|
-
(initInstance: InitInstance<
|
|
3
|
+
import type { StoreState } from './StoreState.tsx';
|
|
4
|
+
export type RegisterDefaultInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
(initInstance: InitInstance<TStoreState>, instanceKey: void): () => typeof STORE_INSTANCE_UNREGISTERED;
|
|
6
6
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { STORE_INSTANCE_UNREGISTERED } from '../constants.tsx';
|
|
2
2
|
import type { InitInstance } from './InitInstance.tsx';
|
|
3
3
|
import type { InstanceKey } from './InstanceKey.tsx';
|
|
4
|
-
import type {
|
|
5
|
-
export type RegisterInstance<
|
|
6
|
-
(initInstance: InitInstance<
|
|
4
|
+
import type { StoreState } from './StoreState.tsx';
|
|
5
|
+
export type RegisterInstance<TStoreState extends StoreState = StoreState> = {
|
|
6
|
+
(initInstance: InitInstance<TStoreState>, instanceKey: InstanceKey): () => typeof STORE_INSTANCE_UNREGISTERED;
|
|
7
7
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { STORE_INSTANCE_UNREGISTERED } from '../constants.tsx';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
(payload: TPayload): typeof STORE_INSTANCE_UNREGISTERED;
|
|
2
|
+
export type ResetInstance = {
|
|
3
|
+
(): typeof STORE_INSTANCE_UNREGISTERED;
|
|
5
4
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
|
|
2
|
+
import type { InitializedStateLink } from './InitializedStateLink.tsx';
|
|
3
|
+
import type { InstanceKeyStateLink } from './InstanceKeyStateLink.tsx';
|
|
2
4
|
import type { InternalStoreProps } from './InternalStoreProps.tsx';
|
|
3
5
|
import type { ReducerMap } from './ReducerMap.tsx';
|
|
4
6
|
import type { ReducerLink } from './ReducerLink.tsx';
|
|
@@ -7,6 +9,8 @@ import type { StoreState } from './StoreState.tsx';
|
|
|
7
9
|
export type Store<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
|
|
8
10
|
[INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
|
|
9
11
|
$$init: void;
|
|
12
|
+
$$initialized: InitializedStateLink<TStoreName, TStoreState, TReducerMap>;
|
|
13
|
+
$$instanceKey: InstanceKeyStateLink<TStoreName, TStoreState, TReducerMap>;
|
|
10
14
|
$$reset: void;
|
|
11
15
|
} & {
|
|
12
16
|
[TKey in keyof TStoreState]: TKey extends string ? StateLink<TStoreName, TStoreState, TReducerMap, TKey> : never;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DeferredAction } from './DeferredAction.tsx';
|
|
2
|
+
import type { Listener } from './InternalStore/Listener.tsx';
|
|
3
|
+
import type { StoreState } from './StoreState.tsx';
|
|
4
|
+
export type StoreInstance<TStoreState extends StoreState = StoreState> = {
|
|
5
|
+
deferredActions: DeferredAction<TStoreState>[];
|
|
6
|
+
listeners: Set<Listener<TStoreState>>;
|
|
7
|
+
state: undefined | TStoreState;
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { InstanceKey } from './InstanceKey.tsx';
|
|
3
|
+
import type { ReducerMap } from './ReducerMap.tsx';
|
|
4
|
+
import type { Store } from './Store.tsx';
|
|
5
|
+
import type { StoreState } from './StoreState.tsx';
|
|
6
|
+
export type StoreProviderProps<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = React.PropsWithChildren<{
|
|
7
|
+
instanceKey?: InstanceKey;
|
|
8
|
+
prefill?: Partial<TStoreState>;
|
|
9
|
+
store: Store<TStoreName, TStoreState, TReducerMap>;
|
|
10
|
+
}>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type StoreRegistry = Record<symbol,
|
|
1
|
+
import type { InternalStore } from '../InternalStore.tsx';
|
|
2
|
+
export type StoreRegistry = Record<symbol, InternalStore>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { InitializedStateLink } from './InitializedStateLink.tsx';
|
|
1
2
|
import type { InstanceKey } from './InstanceKey.tsx';
|
|
3
|
+
import type { InstanceKeyStateLink } from './InstanceKeyStateLink.tsx';
|
|
2
4
|
import type { ReducerMap } from './ReducerMap.tsx';
|
|
3
5
|
import type { StateLink } from './StateLink.tsx';
|
|
4
6
|
import type { StoreState } from './StoreState.tsx';
|
|
5
7
|
export type UseProp = {
|
|
8
|
+
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: InitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): boolean;
|
|
9
|
+
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: InstanceKeyStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): InstanceKey;
|
|
6
10
|
<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): TStoreState[TStateName];
|
|
7
11
|
};
|