beestate 0.1.11 → 0.1.13

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.
Files changed (49) hide show
  1. package/dist/@types/InternalStore.d.ts +3 -3
  2. package/dist/@types/LOCKED.d.ts +2 -0
  3. package/dist/@types/OVERRIDE_LOCKED.d.ts +2 -0
  4. package/dist/@types/constants.d.ts +4 -2
  5. package/dist/@types/createStore.d.ts +4 -2
  6. package/dist/@types/createStoreRegistry.d.ts +7 -5
  7. package/dist/@types/createUsePropSelector.d.ts +3 -0
  8. package/dist/@types/createUsePropSelectorAll.d.ts +3 -0
  9. package/dist/@types/index.d.ts +5 -1
  10. package/dist/@types/isLocked.d.ts +2 -0
  11. package/dist/@types/isLockedOverride.d.ts +2 -0
  12. package/dist/@types/mergePrefill.d.ts +4 -0
  13. package/dist/@types/pickPropAll.d.ts +5 -0
  14. package/dist/@types/types/InitInstance.d.ts +2 -1
  15. package/dist/@types/types/InternalStore/ApplyState.d.ts +2 -1
  16. package/dist/@types/types/InternalStore/GetState.d.ts +2 -1
  17. package/dist/@types/types/InternalStore/GetStateAll.d.ts +2 -1
  18. package/dist/@types/types/InternalStore/InitInstance.d.ts +3 -1
  19. package/dist/@types/types/InternalStore/PatchState.d.ts +8 -0
  20. package/dist/@types/types/InternalStoreProps.d.ts +3 -0
  21. package/dist/@types/types/Locked.d.ts +5 -0
  22. package/dist/@types/types/LockedOverride.d.ts +5 -0
  23. package/dist/@types/types/Patch.d.ts +6 -0
  24. package/dist/@types/types/Prefill.d.ts +5 -0
  25. package/dist/@types/types/Reducer.d.ts +3 -1
  26. package/dist/@types/types/ReducerLink.d.ts +2 -2
  27. package/dist/@types/types/ReducerMap.d.ts +2 -1
  28. package/dist/@types/types/{InitializedStateLink.d.ts → SpecialInitializedStateLink.d.ts} +3 -3
  29. package/dist/@types/types/{InstanceKeyStateLink.d.ts → SpecialInstanceKeyStateLink.d.ts} +3 -3
  30. package/dist/@types/types/StateLink.d.ts +2 -2
  31. package/dist/@types/types/Store.d.ts +5 -5
  32. package/dist/@types/types/StoreContextValue.d.ts +2 -1
  33. package/dist/@types/types/StoreInstance.d.ts +3 -1
  34. package/dist/@types/types/StoreProviderProps.d.ts +2 -1
  35. package/dist/@types/types/Unlocked.d.ts +2 -0
  36. package/dist/@types/types/UnlockedState.d.ts +5 -0
  37. package/dist/@types/types/UseProp.d.ts +6 -5
  38. package/dist/@types/types/UsePropAll.d.ts +3 -1
  39. package/dist/@types/types/UsePropSelector.d.ts +12 -0
  40. package/dist/@types/types/UsePropSelectorAll.d.ts +9 -0
  41. package/dist/@types/unlock.d.ts +1 -0
  42. package/dist/cjs/index.cjs.js +215 -63
  43. package/dist/esm/index.esm.js +212 -64
  44. package/package.json +1 -1
  45. package/dist/@types/createUseSelector.d.ts +0 -1
  46. package/dist/@types/types/InitializedStoreInstance.d.ts +0 -5
  47. package/dist/@types/types/InternalStore/GetInitializedInstance.d.ts +0 -6
  48. package/dist/@types/types/InternalStore/GetUninitializedInstance.d.ts +0 -6
  49. package/dist/@types/types/UninitializedStoreInstance.d.ts +0 -5
@@ -10,19 +10,19 @@ import type { SubscribeAll } from './types/InternalStore/SubscribeAll.tsx';
10
10
  export declare class InternalStore<TStoreState extends StoreState = StoreState> {
11
11
  private readonly instances;
12
12
  private readonly listenersAll;
13
+ private readonly lockedStateNames;
13
14
  readonly name: string;
14
15
  private stateAll;
15
- constructor(name: string);
16
+ constructor(name: string, lockedStateNames?: string[]);
16
17
  private applyState;
17
18
  dispatch: Dispatch<TStoreState>;
18
19
  private ensureInstance;
19
20
  private getInstance;
20
- private getInitializedInstance;
21
21
  getState: GetState<TStoreState>;
22
22
  getStateAll: GetStateAll<TStoreState>;
23
- private getUninitializedInstance;
24
23
  initInstance: InitInstance<TStoreState>;
25
24
  isInitialized: IsInitialized;
25
+ private patchState;
26
26
  private pruneInstance;
27
27
  resetInstance: ResetInstance<TStoreState>;
28
28
  subscribe: Subscribe<TStoreState>;
@@ -0,0 +1,2 @@
1
+ import type { Locked } from './types/Locked.tsx';
2
+ export declare function LOCKED<TValue>(value: TValue): Locked<TValue>;
@@ -0,0 +1,2 @@
1
+ import type { LockedOverride } from './types/LockedOverride.tsx';
2
+ export declare function OVERRIDE_LOCKED<TValue extends null | NonNullable<unknown>>(value: TValue): LockedOverride<TValue>;
@@ -4,6 +4,8 @@ export declare const INITIALIZED_STATE_NAME: "$$initialized";
4
4
  export declare const INSTANCE_KEY_STATE_NAME: "$$instanceKey";
5
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.";
6
6
  export declare const INTERNAL_STORE_PROPS_ACCESSOR: unique symbol;
7
- export declare const REDUCER_LINK: unique symbol;
8
- export declare const STATE_LINK: unique symbol;
7
+ export declare const LOCKED_FLAG: unique symbol;
8
+ export declare const LOCKED_OVERRIDE_FLAG: unique symbol;
9
+ export declare const REDUCER_LINK_FLAG: unique symbol;
10
+ export declare const STATE_LINK_FLAG: unique symbol;
9
11
  export declare const STORE_INSTANCE_UNREGISTERED: unique symbol;
@@ -1,12 +1,14 @@
1
+ import type { LockedOverride } from './types/LockedOverride.tsx';
1
2
  import type { Payload } from './types/Payload.tsx';
2
3
  import type { ReducerMap } from './types/ReducerMap.tsx';
3
4
  import type { Store } from './types/Store.tsx';
4
5
  import type { StoreState } from './types/StoreState.tsx';
6
+ import type { Unlocked } from './types/Unlocked.tsx';
5
7
  type CheckInitialState<TStoreState extends StoreState = StoreState> = {
6
- [TKey in keyof TStoreState]: TKey extends `$$initialized` | `$$instanceKey` ? void : TStoreState[TKey];
8
+ [TKey in keyof TStoreState]: TKey extends `$$initialized` | `$$instanceKey` ? void : unknown extends Unlocked<TStoreState[TKey]> ? TStoreState[TKey] : undefined extends Unlocked<TStoreState[TKey]> ? never : TStoreState[TKey] extends LockedOverride ? never : TStoreState[TKey];
7
9
  };
8
10
  type CheckReducerMap<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
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;
11
+ [TKey in keyof TReducerMap]: TKey extends `$$initialized` | `$$instanceKey` ? void : TKey extends keyof TStoreState ? void : TReducerMap[TKey] extends (...args: any) => any ? [Parameters<TReducerMap[TKey]>[1]] extends [void] ? TReducerMap[TKey] : [Parameters<TReducerMap[TKey]>[1]] extends [Payload] ? Parameters<TReducerMap[TKey]>[1] extends readonly unknown[] ? void : TReducerMap[TKey] : void : void;
10
12
  };
11
13
  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>;
12
14
  export {};
@@ -1,13 +1,15 @@
1
1
  import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
2
  export declare function createStoreRegistry(): {
3
- storeRegistry: StoreRegistry;
4
3
  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
+ storeRegistry: StoreRegistry;
5
+ 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>;
6
+ useLatest: <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, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(saga: (actionName: TReducerName, payload: any, ctx: any) => void, reducerLinks: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>[], instanceKey?: import("./index.tsx").InstanceKey) => any;
7
+ useProp: import("./types/UseProp.tsx").UseProp;
8
+ usePropAll: import("./types/UsePropAll.tsx").UsePropAll;
9
+ usePropSelector: import("./types/UsePropSelector.tsx").UsePropSelector;
10
+ usePropSelectorAll: import("./types/UsePropSelectorAll.tsx").UsePropSelectorAll;
5
11
  useStore: {
6
12
  <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
13
  <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;
8
14
  };
9
- useProp: import("./types/UseProp.tsx").UseProp;
10
- usePropAll: import("./types/UsePropAll.tsx").UsePropAll;
11
- 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>;
12
- useLatest: <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, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(saga: (actionName: TReducerName, payload: any, ctx: any) => void, reducerLinks: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>[], instanceKey?: import("./index.tsx").InstanceKey) => any;
13
15
  };
@@ -0,0 +1,3 @@
1
+ import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
+ import type { UsePropSelector } from './types/UsePropSelector.tsx';
3
+ export declare function createUsePropSelector(storeRegistry: StoreRegistry): UsePropSelector;
@@ -0,0 +1,3 @@
1
+ import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
+ import type { UsePropSelectorAll } from './types/UsePropSelectorAll.tsx';
3
+ export declare function createUsePropSelectorAll(storeRegistry: StoreRegistry): UsePropSelectorAll;
@@ -1,4 +1,6 @@
1
1
  export { type InstanceKey } from './types/InstanceKey.tsx';
2
+ export { type Locked } from './types/Locked.tsx';
3
+ export { type Patch } from './types/Patch.tsx';
2
4
  export { type RequestState } from './types/RequestState.tsx';
3
5
  export { type RequestAbortedState } from './types/RequestState/RequestAbortedState.tsx';
4
6
  export { type RequestFulfilledState } from './types/RequestState/RequestFulfilledState.tsx';
@@ -9,9 +11,11 @@ export { DESTROY } from './constants.tsx';
9
11
  export { createStore } from './createStore.tsx';
10
12
  export { createStoreRegistry } from './createStoreRegistry.tsx';
11
13
  export { InternalStore } from './InternalStore.tsx';
14
+ export { LOCKED } from './LOCKED.tsx';
15
+ export { OVERRIDE_LOCKED } from './OVERRIDE_LOCKED.tsx';
12
16
  export { requestState } from './requestState.tsx';
13
17
  export { requestStatus } from './requestStatus.tsx';
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: {
18
+ 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, usePropSelector: import("./types/UsePropSelector.tsx").UsePropSelector, usePropSelectorAll: import("./types/UsePropSelectorAll.tsx").UsePropSelectorAll, useStore: {
15
19
  <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
20
  <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;
17
21
  };
@@ -0,0 +1,2 @@
1
+ import type { Locked } from './types/Locked.tsx';
2
+ export declare function isLocked(value: unknown): value is Locked;
@@ -0,0 +1,2 @@
1
+ import type { LockedOverride } from './types/LockedOverride.tsx';
2
+ export declare function isLockedOverride(value: unknown): value is LockedOverride;
@@ -0,0 +1,4 @@
1
+ import type { Prefill } from './types/Prefill.tsx';
2
+ import type { StoreState } from './types/StoreState.tsx';
3
+ import type { UnlockedState } from './types/UnlockedState.tsx';
4
+ export declare function mergePrefill<TStoreState extends StoreState = StoreState>(unlockedInitialState: UnlockedState<TStoreState>, prefill?: Prefill<TStoreState>): UnlockedState<TStoreState>;
@@ -0,0 +1,5 @@
1
+ import type { InstanceKey } from './types/InstanceKey.tsx';
2
+ import type { StoreState } from './types/StoreState.tsx';
3
+ import type { Unlocked } from './types/Unlocked.tsx';
4
+ import type { UnlockedState } from './types/UnlockedState.tsx';
5
+ export declare function pickPropAll<TStoreState extends StoreState = StoreState, TStateName extends keyof TStoreState = keyof TStoreState>(stateAll: Record<InstanceKey, UnlockedState<TStoreState>>, stateName: TStateName, instanceKeys?: InstanceKey[] | ((state: UnlockedState<TStoreState>) => boolean)): [instanceKey: InstanceKey, state: Unlocked<TStoreState[TStateName]>][];
@@ -1,5 +1,6 @@
1
+ import type { Prefill } from './Prefill.tsx';
1
2
  import type { ResetInstance } from './ResetInstance.tsx';
2
3
  import type { StoreState } from './StoreState.tsx';
3
4
  export type InitInstance<TStoreState extends StoreState = StoreState> = {
4
- (prefill?: Partial<TStoreState>): ResetInstance;
5
+ (prefill?: Prefill<TStoreState>): ResetInstance;
5
6
  };
@@ -1,5 +1,6 @@
1
1
  import type { InstanceKey } from '../InstanceKey.tsx';
2
2
  import type { StoreState } from '../StoreState.tsx';
3
+ import type { UnlockedState } from '../UnlockedState.tsx';
3
4
  export type ApplyState<TStoreState extends StoreState = StoreState> = {
4
- (instanceKey: InstanceKey, state: undefined | TStoreState): void;
5
+ (instanceKey: InstanceKey, state: undefined | UnlockedState<TStoreState>): void;
5
6
  };
@@ -1,5 +1,6 @@
1
1
  import type { InstanceKey } from '../InstanceKey.tsx';
2
2
  import type { StoreState } from '../StoreState.tsx';
3
+ import type { UnlockedState } from '../UnlockedState.tsx';
3
4
  export type GetState<TStoreState extends StoreState = StoreState> = {
4
- (instanceKey: InstanceKey): TStoreState;
5
+ (instanceKey: InstanceKey): UnlockedState<TStoreState>;
5
6
  };
@@ -1,5 +1,6 @@
1
1
  import type { InstanceKey } from '../InstanceKey.tsx';
2
2
  import type { StoreState } from '../StoreState.tsx';
3
+ import type { UnlockedState } from '../UnlockedState.tsx';
3
4
  export type GetStateAll<TStoreState extends StoreState = StoreState> = {
4
- (): Record<InstanceKey, TStoreState>;
5
+ (): Record<InstanceKey, UnlockedState<TStoreState>>;
5
6
  };
@@ -1,6 +1,8 @@
1
1
  import type { InstanceKey } from '../InstanceKey.tsx';
2
+ import type { Prefill } from '../Prefill.tsx';
2
3
  import type { Reducer } from '../Reducer.tsx';
3
4
  import type { StoreState } from '../StoreState.tsx';
5
+ import type { UnlockedState } from '../UnlockedState.tsx';
4
6
  export type InitInstance<TStoreState extends StoreState = StoreState> = {
5
- (instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Partial<TStoreState>>, initialState: TStoreState, prefill?: Partial<TStoreState>): void;
7
+ (instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Prefill<TStoreState>>, unlockedInitialState: UnlockedState<TStoreState>, prefill?: Prefill<TStoreState>): void;
6
8
  };
@@ -0,0 +1,8 @@
1
+ import type { InstanceKey } from '../InstanceKey.tsx';
2
+ import type { Payload } from '../Payload.tsx';
3
+ import type { Reducer } from '../Reducer.tsx';
4
+ import type { StoreState } from '../StoreState.tsx';
5
+ import type { UnlockedState } from '../UnlockedState.tsx';
6
+ export type PatchState<TStoreState extends StoreState = StoreState> = {
7
+ <TPayload extends void | Payload = void | Payload>(instanceKey: InstanceKey, reducer: Reducer<TStoreState, TPayload>, payload: TPayload, prevState: UnlockedState<TStoreState>): UnlockedState<TStoreState>;
8
+ };
@@ -2,11 +2,14 @@ import React from 'react';
2
2
  import type { ReducerMap } from './ReducerMap.tsx';
3
3
  import type { StoreContextValue } from './StoreContextValue.tsx';
4
4
  import type { StoreState } from './StoreState.tsx';
5
+ import type { UnlockedState } from './UnlockedState.tsx';
5
6
  export type InternalStoreProps<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
6
7
  $$init: TReducerMap[`$$init`];
7
8
  $$reset: TReducerMap[`$$reset`];
8
9
  context: React.Context<null | StoreContextValue<TStoreState>>;
9
10
  initialState: TStoreState;
11
+ lockedStateNames: string[];
10
12
  name: TStoreName;
11
13
  uniqKey: symbol;
14
+ unlockedInitialState: UnlockedState<TStoreState>;
12
15
  };
@@ -0,0 +1,5 @@
1
+ import { LOCKED_FLAG } from '../constants.tsx';
2
+ export type Locked<TValue = unknown> = {
3
+ readonly kind: typeof LOCKED_FLAG;
4
+ readonly value: TValue;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { LOCKED_OVERRIDE_FLAG } from '../constants.tsx';
2
+ export type LockedOverride<TValue = unknown> = {
3
+ readonly kind: typeof LOCKED_OVERRIDE_FLAG;
4
+ readonly value: TValue;
5
+ };
@@ -0,0 +1,6 @@
1
+ import type { Locked } from './Locked.tsx';
2
+ import type { LockedOverride } from './LockedOverride.tsx';
3
+ import type { StoreState } from './StoreState.tsx';
4
+ export type Patch<TStoreState extends StoreState = StoreState> = {
5
+ [TKey in keyof TStoreState]?: undefined | (TStoreState[TKey] extends Locked<infer TValue> ? LockedOverride<TValue> : TStoreState[TKey]);
6
+ };
@@ -0,0 +1,5 @@
1
+ import type { StoreState } from './StoreState.tsx';
2
+ import type { Unlocked } from './Unlocked.tsx';
3
+ export type Prefill<TStoreState extends StoreState = StoreState> = {
4
+ [TKey in keyof TStoreState]?: undefined | Unlocked<TStoreState[TKey]>;
5
+ };
@@ -1,5 +1,7 @@
1
+ import type { Patch } from './Patch.tsx';
1
2
  import type { Payload } from './Payload.tsx';
2
3
  import type { StoreState } from './StoreState.tsx';
4
+ import type { UnlockedState } from './UnlockedState.tsx';
3
5
  export type Reducer<TStoreState extends StoreState = StoreState, TPayload extends void | Payload = void | Payload> = {
4
- (state: TStoreState, payload: TPayload): TStoreState;
6
+ (state: UnlockedState<TStoreState>, payload: TPayload): Patch<TStoreState>;
5
7
  };
@@ -1,5 +1,5 @@
1
1
  import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
2
- import { REDUCER_LINK } from '../constants.tsx';
2
+ import { REDUCER_LINK_FLAG } from '../constants.tsx';
3
3
  import type { InternalStoreProps } from './InternalStoreProps.tsx';
4
4
  import type { Reducer } from './Reducer.tsx';
5
5
  import type { ReducerMap } from './ReducerMap.tsx';
@@ -9,5 +9,5 @@ export type ReducerLink<TStoreName extends string = string, TStoreState extends
9
9
  [INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
10
10
  reducer: Reducer<TStoreState, ReducerPayload<TReducerMap[TReducerName]>>;
11
11
  reducerName: TReducerName;
12
- type: typeof REDUCER_LINK;
12
+ type: typeof REDUCER_LINK_FLAG;
13
13
  };
@@ -1,6 +1,7 @@
1
+ import type { Prefill } from './Prefill.tsx';
1
2
  import type { Reducer } from './Reducer.tsx';
2
3
  import type { StoreState } from './StoreState.tsx';
3
4
  export type ReducerMap<TStoreState extends StoreState = StoreState> = Record<string, Reducer<TStoreState, void | any>> & {
4
- $$init: Reducer<TStoreState, Partial<TStoreState>>;
5
+ $$init: Reducer<TStoreState, Prefill<TStoreState>>;
5
6
  $$reset: Reducer<TStoreState, void>;
6
7
  };
@@ -1,11 +1,11 @@
1
1
  import { INITIALIZED_STATE_NAME } from '../constants.tsx';
2
2
  import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
3
- import { STATE_LINK } from '../constants.tsx';
3
+ import { STATE_LINK_FLAG } from '../constants.tsx';
4
4
  import type { InternalStoreProps } from './InternalStoreProps.tsx';
5
5
  import type { ReducerMap } from './ReducerMap.tsx';
6
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>> = {
7
+ export type SpecialInitializedStateLink<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
8
8
  [INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
9
9
  stateName: typeof INITIALIZED_STATE_NAME;
10
- type: typeof STATE_LINK;
10
+ type: typeof STATE_LINK_FLAG;
11
11
  };
@@ -1,11 +1,11 @@
1
1
  import { INSTANCE_KEY_STATE_NAME } from '../constants.tsx';
2
2
  import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
3
- import { STATE_LINK } from '../constants.tsx';
3
+ import { STATE_LINK_FLAG } from '../constants.tsx';
4
4
  import type { InternalStoreProps } from './InternalStoreProps.tsx';
5
5
  import type { ReducerMap } from './ReducerMap.tsx';
6
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>> = {
7
+ export type SpecialInstanceKeyStateLink<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
8
8
  [INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
9
9
  stateName: typeof INSTANCE_KEY_STATE_NAME;
10
- type: typeof STATE_LINK;
10
+ type: typeof STATE_LINK_FLAG;
11
11
  };
@@ -1,10 +1,10 @@
1
1
  import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
2
- import { STATE_LINK } from '../constants.tsx';
2
+ import { STATE_LINK_FLAG } from '../constants.tsx';
3
3
  import type { InternalStoreProps } from './InternalStoreProps.tsx';
4
4
  import type { ReducerMap } from './ReducerMap.tsx';
5
5
  import type { StoreState } from './StoreState.tsx';
6
6
  export type StateLink<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState> = {
7
7
  [INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
8
8
  stateName: TStateName;
9
- type: typeof STATE_LINK;
9
+ type: typeof STATE_LINK_FLAG;
10
10
  };
@@ -1,16 +1,16 @@
1
1
  import { INTERNAL_STORE_PROPS_ACCESSOR } from '../constants.tsx';
2
- import type { InitializedStateLink } from './InitializedStateLink.tsx';
3
- import type { InstanceKeyStateLink } from './InstanceKeyStateLink.tsx';
4
2
  import type { InternalStoreProps } from './InternalStoreProps.tsx';
5
- import type { ReducerMap } from './ReducerMap.tsx';
6
3
  import type { ReducerLink } from './ReducerLink.tsx';
4
+ import type { ReducerMap } from './ReducerMap.tsx';
5
+ import type { SpecialInitializedStateLink } from './SpecialInitializedStateLink.tsx';
6
+ import type { SpecialInstanceKeyStateLink } from './SpecialInstanceKeyStateLink.tsx';
7
7
  import type { StateLink } from './StateLink.tsx';
8
8
  import type { StoreState } from './StoreState.tsx';
9
9
  export type Store<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
10
10
  [INTERNAL_STORE_PROPS_ACCESSOR]: InternalStoreProps<TStoreName, TStoreState, TReducerMap>;
11
11
  $$init: void;
12
- $$initialized: InitializedStateLink<TStoreName, TStoreState, TReducerMap>;
13
- $$instanceKey: InstanceKeyStateLink<TStoreName, TStoreState, TReducerMap>;
12
+ $$initialized: SpecialInitializedStateLink<TStoreName, TStoreState, TReducerMap>;
13
+ $$instanceKey: SpecialInstanceKeyStateLink<TStoreName, TStoreState, TReducerMap>;
14
14
  $$reset: void;
15
15
  } & {
16
16
  [TKey in keyof TStoreState]: TKey extends string ? StateLink<TStoreName, TStoreState, TReducerMap, TKey> : never;
@@ -1,6 +1,7 @@
1
1
  import type { InstanceKey } from './InstanceKey.tsx';
2
2
  import type { StoreState } from './StoreState.tsx';
3
+ import type { UnlockedState } from './UnlockedState.tsx';
3
4
  export type StoreContextValue<TStoreState extends StoreState = StoreState> = {
4
5
  instanceKey: InstanceKey;
5
- uninitializedState: TStoreState;
6
+ uninitializedState: UnlockedState<TStoreState>;
6
7
  };
@@ -1,8 +1,10 @@
1
1
  import type { DeferredAction } from './DeferredAction.tsx';
2
2
  import type { Listener } from './InternalStore/Listener.tsx';
3
+ import type { Reducer } from './Reducer.tsx';
3
4
  import type { StoreState } from './StoreState.tsx';
4
5
  export type StoreInstance<TStoreState extends StoreState = StoreState> = {
5
6
  deferredActions: DeferredAction<TStoreState>[];
6
7
  listeners: Set<Listener<TStoreState>>;
7
- state: undefined | TStoreState;
8
+ updatedLockedWarnedReducers: Set<Reducer<TStoreState, any>>;
9
+ wrappedUnlockedWarnedReducers: Set<Reducer<TStoreState, any>>;
8
10
  };
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { InstanceKey } from './InstanceKey.tsx';
3
+ import type { Prefill } from './Prefill.tsx';
3
4
  import type { ReducerMap } from './ReducerMap.tsx';
4
5
  import type { Store } from './Store.tsx';
5
6
  import type { StoreState } from './StoreState.tsx';
6
7
  export type StoreProviderProps<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = React.PropsWithChildren<{
7
8
  instanceKey?: InstanceKey;
8
- prefill?: Partial<TStoreState>;
9
+ prefill?: Prefill<TStoreState>;
9
10
  store: Store<TStoreName, TStoreState, TReducerMap>;
10
11
  }>;
@@ -0,0 +1,2 @@
1
+ import type { Locked } from './Locked.tsx';
2
+ export type Unlocked<TValue = unknown> = TValue extends Locked<infer TInnerValue> ? TInnerValue : TValue;
@@ -0,0 +1,5 @@
1
+ import type { StoreState } from './StoreState.tsx';
2
+ import type { Unlocked } from './Unlocked.tsx';
3
+ export type UnlockedState<TStoreState extends StoreState = StoreState> = {
4
+ [TKey in keyof TStoreState]: Unlocked<TStoreState[TKey]>;
5
+ };
@@ -1,11 +1,12 @@
1
- import type { InitializedStateLink } from './InitializedStateLink.tsx';
2
1
  import type { InstanceKey } from './InstanceKey.tsx';
3
- import type { InstanceKeyStateLink } from './InstanceKeyStateLink.tsx';
4
2
  import type { ReducerMap } from './ReducerMap.tsx';
3
+ import type { SpecialInitializedStateLink } from './SpecialInitializedStateLink.tsx';
4
+ import type { SpecialInstanceKeyStateLink } from './SpecialInstanceKeyStateLink.tsx';
5
5
  import type { StateLink } from './StateLink.tsx';
6
6
  import type { StoreState } from './StoreState.tsx';
7
+ import type { Unlocked } from './Unlocked.tsx';
7
8
  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;
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];
9
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): boolean;
10
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInstanceKeyStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): InstanceKey;
11
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): Unlocked<TStoreState[TStateName]>;
11
12
  };
@@ -2,6 +2,8 @@ import type { InstanceKey } from './InstanceKey.tsx';
2
2
  import type { ReducerMap } from './ReducerMap.tsx';
3
3
  import type { StateLink } from './StateLink.tsx';
4
4
  import type { StoreState } from './StoreState.tsx';
5
+ import type { Unlocked } from './Unlocked.tsx';
6
+ import type { UnlockedState } from './UnlockedState.tsx';
5
7
  export type UsePropAll = {
6
- <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKeys?: InstanceKey[] | ((state: TStoreState) => boolean)): [instanceKey: InstanceKey, state: TStoreState[TStateName]][];
8
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKeys?: InstanceKey[] | ((state: UnlockedState<TStoreState>) => boolean)): [instanceKey: InstanceKey, state: Unlocked<TStoreState[TStateName]>][];
7
9
  };
@@ -0,0 +1,12 @@
1
+ import type { InstanceKey } from './InstanceKey.tsx';
2
+ import type { ReducerMap } from './ReducerMap.tsx';
3
+ import type { SpecialInitializedStateLink } from './SpecialInitializedStateLink.tsx';
4
+ import type { SpecialInstanceKeyStateLink } from './SpecialInstanceKeyStateLink.tsx';
5
+ import type { StateLink } from './StateLink.tsx';
6
+ import type { StoreState } from './StoreState.tsx';
7
+ import type { Unlocked } from './Unlocked.tsx';
8
+ export type UsePropSelector = {
9
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): () => boolean;
10
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInstanceKeyStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): () => InstanceKey;
11
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): () => Unlocked<TStoreState[TStateName]>;
12
+ };
@@ -0,0 +1,9 @@
1
+ import type { InstanceKey } from './InstanceKey.tsx';
2
+ import type { ReducerMap } from './ReducerMap.tsx';
3
+ import type { StateLink } from './StateLink.tsx';
4
+ import type { StoreState } from './StoreState.tsx';
5
+ import type { Unlocked } from './Unlocked.tsx';
6
+ import type { UnlockedState } from './UnlockedState.tsx';
7
+ export type UsePropSelectorAll = {
8
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKeys?: InstanceKey[] | ((state: UnlockedState<TStoreState>) => boolean)): () => [instanceKey: InstanceKey, state: Unlocked<TStoreState[TStateName]>][];
9
+ };
@@ -0,0 +1 @@
1
+ export declare function unlock(value: unknown): unknown;