beestate 0.1.13 → 0.1.15

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 (35) hide show
  1. package/dist/@types/OVERRIDE_LOCKED.d.ts +2 -2
  2. package/dist/@types/constants.d.ts +1 -1
  3. package/dist/@types/createStore.d.ts +3 -3
  4. package/dist/@types/index.d.ts +5 -0
  5. package/dist/@types/isOverrideLocked.d.ts +2 -0
  6. package/dist/@types/mergePrefill.d.ts +2 -2
  7. package/dist/@types/pickPropAll.d.ts +3 -3
  8. package/dist/@types/types/InternalStore/ApplyState.d.ts +2 -2
  9. package/dist/@types/types/InternalStore/GetState.d.ts +2 -2
  10. package/dist/@types/types/InternalStore/GetStateAll.d.ts +2 -2
  11. package/dist/@types/types/InternalStore/InitInstance.d.ts +2 -2
  12. package/dist/@types/types/InternalStore/PatchState.d.ts +2 -2
  13. package/dist/@types/types/InternalStoreProps.d.ts +2 -2
  14. package/dist/@types/types/OverrideLocked.d.ts +5 -0
  15. package/dist/@types/types/Patch.d.ts +3 -3
  16. package/dist/@types/types/Prefill.d.ts +2 -2
  17. package/dist/@types/types/Reducer.d.ts +2 -2
  18. package/dist/@types/types/StoreContextValue.d.ts +2 -2
  19. package/dist/@types/types/StoreInstance.d.ts +1 -1
  20. package/dist/@types/types/Unwrapped.d.ts +3 -0
  21. package/dist/@types/types/UnwrappedState.d.ts +5 -0
  22. package/dist/@types/types/UseProp.d.ts +2 -2
  23. package/dist/@types/types/UsePropAll.d.ts +3 -3
  24. package/dist/@types/types/UsePropSelector.d.ts +2 -2
  25. package/dist/@types/types/UsePropSelectorAll.d.ts +3 -3
  26. package/dist/@types/types/WithLocked.d.ts +5 -0
  27. package/dist/@types/unwrap.d.ts +1 -0
  28. package/dist/cjs/index.cjs.js +33 -33
  29. package/dist/esm/index.esm.js +33 -33
  30. package/package.json +1 -1
  31. package/dist/@types/isLockedOverride.d.ts +0 -2
  32. package/dist/@types/types/LockedOverride.d.ts +0 -5
  33. package/dist/@types/types/Unlocked.d.ts +0 -2
  34. package/dist/@types/types/UnlockedState.d.ts +0 -5
  35. package/dist/@types/unlock.d.ts +0 -1
@@ -1,2 +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>;
1
+ import type { OverrideLocked } from './types/OverrideLocked.tsx';
2
+ export declare function OVERRIDE_LOCKED<TValue extends null | NonNullable<unknown>>(value: TValue): OverrideLocked<TValue>;
@@ -5,7 +5,7 @@ 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
7
  export declare const LOCKED_FLAG: unique symbol;
8
- export declare const LOCKED_OVERRIDE_FLAG: unique symbol;
8
+ export declare const OVERRIDE_LOCKED_FLAG: unique symbol;
9
9
  export declare const REDUCER_LINK_FLAG: unique symbol;
10
10
  export declare const STATE_LINK_FLAG: unique symbol;
11
11
  export declare const STORE_INSTANCE_UNREGISTERED: unique symbol;
@@ -1,11 +1,11 @@
1
- import type { LockedOverride } from './types/LockedOverride.tsx';
1
+ import type { OverrideLocked } from './types/OverrideLocked.tsx';
2
2
  import type { Payload } from './types/Payload.tsx';
3
3
  import type { ReducerMap } from './types/ReducerMap.tsx';
4
4
  import type { Store } from './types/Store.tsx';
5
5
  import type { StoreState } from './types/StoreState.tsx';
6
- import type { Unlocked } from './types/Unlocked.tsx';
6
+ import type { Unwrapped } from './types/Unwrapped.tsx';
7
7
  type CheckInitialState<TStoreState extends StoreState = StoreState> = {
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];
8
+ [TKey in keyof TStoreState]: TKey extends `$$initialized` | `$$instanceKey` ? void : unknown extends Unwrapped<TStoreState[TKey]> ? TStoreState[TKey] : undefined extends Unwrapped<TStoreState[TKey]> ? never : TStoreState[TKey] extends OverrideLocked ? never : TStoreState[TKey];
9
9
  };
10
10
  type CheckReducerMap<TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
11
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;
@@ -1,12 +1,17 @@
1
1
  export { type InstanceKey } from './types/InstanceKey.tsx';
2
2
  export { type Locked } from './types/Locked.tsx';
3
+ export { type OverrideLocked } from './types/OverrideLocked.tsx';
3
4
  export { type Patch } from './types/Patch.tsx';
5
+ export { type Prefill } from './types/Prefill.tsx';
4
6
  export { type RequestState } from './types/RequestState.tsx';
5
7
  export { type RequestAbortedState } from './types/RequestState/RequestAbortedState.tsx';
6
8
  export { type RequestFulfilledState } from './types/RequestState/RequestFulfilledState.tsx';
7
9
  export { type RequestIdleState } from './types/RequestState/RequestIdleState.tsx';
8
10
  export { type RequestPendingState } from './types/RequestState/RequestPendingState.tsx';
9
11
  export { type RequestRejectedState } from './types/RequestState/RequestRejectedState.tsx';
12
+ export { type Unwrapped } from './types/Unwrapped.tsx';
13
+ export { type UnwrappedState } from './types/UnwrappedState.tsx';
14
+ export { type WithLocked } from './types/WithLocked.tsx';
10
15
  export { DESTROY } from './constants.tsx';
11
16
  export { createStore } from './createStore.tsx';
12
17
  export { createStoreRegistry } from './createStoreRegistry.tsx';
@@ -0,0 +1,2 @@
1
+ import type { OverrideLocked } from './types/OverrideLocked.tsx';
2
+ export declare function isOverrideLocked(value: unknown): value is OverrideLocked;
@@ -1,4 +1,4 @@
1
1
  import type { Prefill } from './types/Prefill.tsx';
2
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>;
3
+ import type { UnwrappedState } from './types/UnwrappedState.tsx';
4
+ export declare function mergePrefill<TStoreState extends StoreState = StoreState>(unwrappedInitialState: UnwrappedState<TStoreState>, prefill?: Prefill<TStoreState>): UnwrappedState<TStoreState>;
@@ -1,5 +1,5 @@
1
1
  import type { InstanceKey } from './types/InstanceKey.tsx';
2
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]>][];
3
+ import type { Unwrapped } from './types/Unwrapped.tsx';
4
+ import type { UnwrappedState } from './types/UnwrappedState.tsx';
5
+ export declare function pickPropAll<TStoreState extends StoreState = StoreState, TStateName extends keyof TStoreState = keyof TStoreState>(stateAll: Record<InstanceKey, UnwrappedState<TStoreState>>, stateName: TStateName, instanceKeys?: InstanceKey[] | ((state: UnwrappedState<TStoreState>) => boolean)): [instanceKey: InstanceKey, state: Unwrapped<TStoreState[TStateName]>][];
@@ -1,6 +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
+ import type { UnwrappedState } from '../UnwrappedState.tsx';
4
4
  export type ApplyState<TStoreState extends StoreState = StoreState> = {
5
- (instanceKey: InstanceKey, state: undefined | UnlockedState<TStoreState>): void;
5
+ (instanceKey: InstanceKey, state: undefined | UnwrappedState<TStoreState>): void;
6
6
  };
@@ -1,6 +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
+ import type { UnwrappedState } from '../UnwrappedState.tsx';
4
4
  export type GetState<TStoreState extends StoreState = StoreState> = {
5
- (instanceKey: InstanceKey): UnlockedState<TStoreState>;
5
+ (instanceKey: InstanceKey): UnwrappedState<TStoreState>;
6
6
  };
@@ -1,6 +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
+ import type { UnwrappedState } from '../UnwrappedState.tsx';
4
4
  export type GetStateAll<TStoreState extends StoreState = StoreState> = {
5
- (): Record<InstanceKey, UnlockedState<TStoreState>>;
5
+ (): Record<InstanceKey, UnwrappedState<TStoreState>>;
6
6
  };
@@ -2,7 +2,7 @@ import type { InstanceKey } from '../InstanceKey.tsx';
2
2
  import type { Prefill } from '../Prefill.tsx';
3
3
  import type { Reducer } from '../Reducer.tsx';
4
4
  import type { StoreState } from '../StoreState.tsx';
5
- import type { UnlockedState } from '../UnlockedState.tsx';
5
+ import type { UnwrappedState } from '../UnwrappedState.tsx';
6
6
  export type InitInstance<TStoreState extends StoreState = StoreState> = {
7
- (instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Prefill<TStoreState>>, unlockedInitialState: UnlockedState<TStoreState>, prefill?: Prefill<TStoreState>): void;
7
+ (instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Prefill<TStoreState>>, unwrappedInitialState: UnwrappedState<TStoreState>, prefill?: Prefill<TStoreState>): void;
8
8
  };
@@ -2,7 +2,7 @@ import type { InstanceKey } from '../InstanceKey.tsx';
2
2
  import type { Payload } from '../Payload.tsx';
3
3
  import type { Reducer } from '../Reducer.tsx';
4
4
  import type { StoreState } from '../StoreState.tsx';
5
- import type { UnlockedState } from '../UnlockedState.tsx';
5
+ import type { UnwrappedState } from '../UnwrappedState.tsx';
6
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>;
7
+ <TPayload extends void | Payload = void | Payload>(instanceKey: InstanceKey, reducer: Reducer<TStoreState, TPayload>, payload: TPayload, prevState: UnwrappedState<TStoreState>): UnwrappedState<TStoreState>;
8
8
  };
@@ -2,7 +2,7 @@ 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
+ import type { UnwrappedState } from './UnwrappedState.tsx';
6
6
  export type InternalStoreProps<TStoreName extends string = string, TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>> = {
7
7
  $$init: TReducerMap[`$$init`];
8
8
  $$reset: TReducerMap[`$$reset`];
@@ -11,5 +11,5 @@ export type InternalStoreProps<TStoreName extends string = string, TStoreState e
11
11
  lockedStateNames: string[];
12
12
  name: TStoreName;
13
13
  uniqKey: symbol;
14
- unlockedInitialState: UnlockedState<TStoreState>;
14
+ unwrappedInitialState: UnwrappedState<TStoreState>;
15
15
  };
@@ -0,0 +1,5 @@
1
+ import { OVERRIDE_LOCKED_FLAG } from '../constants.tsx';
2
+ export type OverrideLocked<TValue = unknown> = {
3
+ readonly kind: typeof OVERRIDE_LOCKED_FLAG;
4
+ readonly value: TValue;
5
+ };
@@ -1,6 +1,6 @@
1
1
  import type { Locked } from './Locked.tsx';
2
- import type { LockedOverride } from './LockedOverride.tsx';
2
+ import type { OverrideLocked } from './OverrideLocked.tsx';
3
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]);
4
+ export type Patch<TStoreState extends StoreState = StoreState> = null | {
5
+ [TKey in keyof TStoreState]?: undefined | (TStoreState[TKey] extends Locked<infer TValue> ? OverrideLocked<TValue> : TStoreState[TKey]);
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import type { StoreState } from './StoreState.tsx';
2
- import type { Unlocked } from './Unlocked.tsx';
2
+ import type { Unwrapped } from './Unwrapped.tsx';
3
3
  export type Prefill<TStoreState extends StoreState = StoreState> = {
4
- [TKey in keyof TStoreState]?: undefined | Unlocked<TStoreState[TKey]>;
4
+ [TKey in keyof TStoreState]?: undefined | Unwrapped<TStoreState[TKey]>;
5
5
  };
@@ -1,7 +1,7 @@
1
1
  import type { Patch } from './Patch.tsx';
2
2
  import type { Payload } from './Payload.tsx';
3
3
  import type { StoreState } from './StoreState.tsx';
4
- import type { UnlockedState } from './UnlockedState.tsx';
4
+ import type { UnwrappedState } from './UnwrappedState.tsx';
5
5
  export type Reducer<TStoreState extends StoreState = StoreState, TPayload extends void | Payload = void | Payload> = {
6
- (state: UnlockedState<TStoreState>, payload: TPayload): Patch<TStoreState>;
6
+ (state: UnwrappedState<TStoreState>, payload: TPayload): Patch<TStoreState>;
7
7
  };
@@ -1,7 +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
+ import type { UnwrappedState } from './UnwrappedState.tsx';
4
4
  export type StoreContextValue<TStoreState extends StoreState = StoreState> = {
5
5
  instanceKey: InstanceKey;
6
- uninitializedState: UnlockedState<TStoreState>;
6
+ uninitializedState: UnwrappedState<TStoreState>;
7
7
  };
@@ -6,5 +6,5 @@ export type StoreInstance<TStoreState extends StoreState = StoreState> = {
6
6
  deferredActions: DeferredAction<TStoreState>[];
7
7
  listeners: Set<Listener<TStoreState>>;
8
8
  updatedLockedWarnedReducers: Set<Reducer<TStoreState, any>>;
9
- wrappedUnlockedWarnedReducers: Set<Reducer<TStoreState, any>>;
9
+ wrappedNotLockedWarnedReducers: Set<Reducer<TStoreState, any>>;
10
10
  };
@@ -0,0 +1,3 @@
1
+ import type { Locked } from './Locked.tsx';
2
+ import type { OverrideLocked } from './OverrideLocked.tsx';
3
+ export type Unwrapped<TValue = unknown> = TValue extends Locked<infer TInnerValue> ? TInnerValue : TValue extends OverrideLocked<infer TInnerValue> ? TInnerValue : TValue;
@@ -0,0 +1,5 @@
1
+ import type { StoreState } from './StoreState.tsx';
2
+ import type { Unwrapped } from './Unwrapped.tsx';
3
+ export type UnwrappedState<TStoreState extends StoreState = StoreState> = {
4
+ [TKey in keyof TStoreState]: Unwrapped<TStoreState[TKey]>;
5
+ };
@@ -4,9 +4,9 @@ import type { SpecialInitializedStateLink } from './SpecialInitializedStateLink.
4
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
+ import type { Unwrapped } from './Unwrapped.tsx';
8
8
  export type UseProp = {
9
9
  <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): boolean;
10
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
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): Unwrapped<TStoreState[TStateName]>;
12
12
  };
@@ -2,8 +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
+ import type { Unwrapped } from './Unwrapped.tsx';
6
+ import type { UnwrappedState } from './UnwrappedState.tsx';
7
7
  export type UsePropAll = {
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]>][];
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: UnwrappedState<TStoreState>) => boolean)): [instanceKey: InstanceKey, state: Unwrapped<TStoreState[TStateName]>][];
9
9
  };
@@ -4,9 +4,9 @@ import type { SpecialInitializedStateLink } from './SpecialInitializedStateLink.
4
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
+ import type { Unwrapped } from './Unwrapped.tsx';
8
8
  export type UsePropSelector = {
9
9
  <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: SpecialInitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): () => boolean;
10
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
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): () => Unwrapped<TStoreState[TStateName]>;
12
12
  };
@@ -2,8 +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
+ import type { Unwrapped } from './Unwrapped.tsx';
6
+ import type { UnwrappedState } from './UnwrappedState.tsx';
7
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]>][];
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: UnwrappedState<TStoreState>) => boolean)): () => [instanceKey: InstanceKey, state: Unwrapped<TStoreState[TStateName]>][];
9
9
  };
@@ -0,0 +1,5 @@
1
+ import type { Locked } from './Locked.tsx';
2
+ import type { StoreState } from './StoreState.tsx';
3
+ export type WithLocked<TStoreState extends StoreState = StoreState, TStateName extends keyof TStoreState = keyof TStoreState> = {
4
+ [TKey in keyof TStoreState]: TKey extends TStateName ? Locked<TStoreState[TKey]> : TStoreState[TKey];
5
+ };
@@ -0,0 +1 @@
1
+ export declare function unwrap(value: unknown): unknown;
@@ -11,7 +11,7 @@ const INSTANCE_KEY_STATE_NAME = `$$instanceKey`;
11
11
  const INTERNAL_BUG_MESSAGE = `This must never happen and may mean a bug inside the library itself. Please report it to the library developers.`;
12
12
  const INTERNAL_STORE_PROPS_ACCESSOR = Symbol(`INTERNAL_STORE_PROPS`);
13
13
  const LOCKED_FLAG = Symbol(`LOCKED`);
14
- const LOCKED_OVERRIDE_FLAG = Symbol(`LOCKED_OVERRIDE`);
14
+ const OVERRIDE_LOCKED_FLAG = Symbol(`OVERRIDE_LOCKED`);
15
15
  const REDUCER_LINK_FLAG = Symbol(`REDUCER_LINK`);
16
16
  const STATE_LINK_FLAG = Symbol(`STATE_LINK`);
17
17
  const STORE_INSTANCE_UNREGISTERED = Symbol(`STORE_INSTANCE_UNREGISTERED`);
@@ -20,12 +20,12 @@ function isLocked(value) {
20
20
  return typeof value === `object` && value !== null && `kind` in value && value.kind === LOCKED_FLAG;
21
21
  }
22
22
 
23
- function isLockedOverride(value) {
24
- return typeof value === `object` && value !== null && `kind` in value && value.kind === LOCKED_OVERRIDE_FLAG;
23
+ function isOverrideLocked(value) {
24
+ return typeof value === `object` && value !== null && `kind` in value && value.kind === OVERRIDE_LOCKED_FLAG;
25
25
  }
26
26
 
27
- function unlock(value) {
28
- if (isLocked(value) || isLockedOverride(value)) {
27
+ function unwrap(value) {
28
+ if (isLocked(value) || isOverrideLocked(value)) {
29
29
  return value.value;
30
30
  }
31
31
  else {
@@ -33,10 +33,10 @@ function unlock(value) {
33
33
  }
34
34
  }
35
35
 
36
- function mergePrefill(unlockedInitialState, prefill = {}) {
37
- const state = { ...unlockedInitialState };
36
+ function mergePrefill(unwrappedInitialState, prefill = {}) {
37
+ const state = { ...unwrappedInitialState };
38
38
  for (const stateName of Object.keys(prefill)) {
39
- const value = unlock(prefill[stateName]);
39
+ const value = unwrap(prefill[stateName]);
40
40
  if (value !== undefined) {
41
41
  state[stateName] = value;
42
42
  }
@@ -54,7 +54,7 @@ function createStoreProvider(useStore) {
54
54
  return initInstance(prefillRef.current.prefill);
55
55
  });
56
56
  const contextValue = React.useMemo(() => {
57
- return { instanceKey: actualInstanceKey, uninitializedState: mergePrefill(internalStoreProps.unlockedInitialState, prefillRef.current.prefill) };
57
+ return { instanceKey: actualInstanceKey, uninitializedState: mergePrefill(internalStoreProps.unwrappedInitialState, prefillRef.current.prefill) };
58
58
  }, [actualInstanceKey, internalStoreProps]);
59
59
  return (jsxRuntime.jsx(Context.Provider, { value: contextValue, children: props.children }));
60
60
  };
@@ -93,7 +93,7 @@ class InternalStore {
93
93
  };
94
94
  this.ensureInstance = (instanceKey) => {
95
95
  if (!this.instances[instanceKey]) {
96
- this.instances[instanceKey] = { deferredActions: [], listeners: new Set(), updatedLockedWarnedReducers: new Set(), wrappedUnlockedWarnedReducers: new Set() };
96
+ this.instances[instanceKey] = { deferredActions: [], listeners: new Set(), updatedLockedWarnedReducers: new Set(), wrappedNotLockedWarnedReducers: new Set() };
97
97
  }
98
98
  };
99
99
  this.getInstance = (instanceKey) => {
@@ -117,7 +117,7 @@ class InternalStore {
117
117
  return this.stateAll;
118
118
  };
119
119
  // TODO Охота изменить порядок параметров
120
- this.initInstance = (instanceKey, initReducer, unlockedInitialState, prefill = {}) => {
120
+ this.initInstance = (instanceKey, initReducer, unwrappedInitialState, prefill = {}) => {
121
121
  this.ensureInstance(instanceKey);
122
122
  const instance = this.getInstance(instanceKey);
123
123
  if (this.isInitialized(instanceKey)) {
@@ -128,15 +128,15 @@ class InternalStore {
128
128
  // TODO Смущает наличие двух этих вызовов подряд...
129
129
  // Такое ощущение, что надо бы обойтись одним.
130
130
  // TODO Надо спросить у ИИ что будет если от первого вызова избавиться и зачем он тут нужен
131
- const unlockedPrefill = {};
131
+ const unwrappedPrefill = {};
132
132
  for (const stateName of Object.keys(prefill)) {
133
- unlockedPrefill[stateName] = unlock(prefill[stateName]);
134
- if (unlockedPrefill[stateName] !== prefill[stateName]) {
133
+ unwrappedPrefill[stateName] = unwrap(prefill[stateName]);
134
+ if (unwrappedPrefill[stateName] !== prefill[stateName]) {
135
135
  console.warn(`You used \`LOCKED\` or \`OVERRIDE_LOCKED\` in prefill [store: ${this.name}, instanceKey: ${String(instanceKey)}, property: ${stateName}]. Pass an unwrapped value instead.`);
136
136
  }
137
137
  }
138
- this.applyState(instanceKey, mergePrefill(unlockedInitialState, unlockedPrefill));
139
- this.dispatch(instanceKey, initReducer, unlockedPrefill);
138
+ this.applyState(instanceKey, mergePrefill(unwrappedInitialState, unwrappedPrefill));
139
+ this.dispatch(instanceKey, initReducer, unwrappedPrefill);
140
140
  // TODO Требуется комментарий в коде...
141
141
  // Почему мы сначала сохраняем в переменную массив, и только потом идем по нему? Почему нельзя
142
142
  // идти сразу по нему?
@@ -150,15 +150,15 @@ class InternalStore {
150
150
  return instanceKey in this.stateAll;
151
151
  };
152
152
  this.patchState = (instanceKey, reducer, payload, prevState) => {
153
- const patch = reducer(prevState, payload);
153
+ const patch = reducer(prevState, payload) ?? {};
154
154
  const updatedLockedStateNames = [];
155
155
  const wrappedStateNames = [];
156
156
  let nextState = prevState;
157
157
  for (const stateName of Object.keys(patch)) {
158
- const value = unlock(patch[stateName]);
158
+ const value = unwrap(patch[stateName]);
159
159
  if (value !== undefined) {
160
160
  if (this.lockedStateNames.includes(stateName)) {
161
- if (!isLockedOverride(patch[stateName])) {
161
+ if (!isOverrideLocked(patch[stateName])) {
162
162
  updatedLockedStateNames.push(stateName);
163
163
  }
164
164
  }
@@ -178,8 +178,8 @@ class InternalStore {
178
178
  instance.updatedLockedWarnedReducers.add(reducer);
179
179
  console.warn(`You updated a property, which is marked as locked [store: ${this.name}, instanceKey: ${String(instanceKey)}, action: ${reducer.name}, property: ${updatedLockedStateNames.join(`, `)}]. Use \`OVERRIDE_LOCKED\`, if you really need to update it.`);
180
180
  }
181
- if (wrappedStateNames.length && !instance.wrappedUnlockedWarnedReducers.has(reducer)) {
182
- instance.wrappedUnlockedWarnedReducers.add(reducer);
181
+ if (wrappedStateNames.length && !instance.wrappedNotLockedWarnedReducers.has(reducer)) {
182
+ instance.wrappedNotLockedWarnedReducers.add(reducer);
183
183
  console.warn(`You used \`LOCKED\` or \`OVERRIDE_LOCKED\` for a property, which is not marked as locked [store: ${this.name}, instanceKey: ${String(instanceKey)}, action: ${reducer.name}, property: ${wrappedStateNames.join(`, `)}]. Return an unwrapped value instead.`);
184
184
  }
185
185
  return nextState;
@@ -199,7 +199,7 @@ class InternalStore {
199
199
  const nextState = this.patchState(instanceKey, resetReducer, undefined, prevState);
200
200
  this.applyState(instanceKey, undefined);
201
201
  instance.updatedLockedWarnedReducers.clear();
202
- instance.wrappedUnlockedWarnedReducers.clear();
202
+ instance.wrappedNotLockedWarnedReducers.clear();
203
203
  instance.listeners.forEach((listener) => listener(instanceKey, resetReducer, undefined));
204
204
  this.listenersAll.forEach((listener) => listener(instanceKey, resetReducer, undefined));
205
205
  // TODO Убрать в логгер
@@ -300,7 +300,7 @@ function createUseProp(storeRegistry) {
300
300
  const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
301
301
  const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
302
302
  ? storeContextValue.uninitializedState
303
- : internalStoreProps.unlockedInitialState;
303
+ : internalStoreProps.unwrappedInitialState;
304
304
  const subscribe = React.useCallback((listener) => {
305
305
  return internalStore.subscribe(actualInstanceKey, listener);
306
306
  }, [actualInstanceKey, internalStore]);
@@ -392,7 +392,7 @@ function createUsePropSelector(storeRegistry) {
392
392
  const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
393
393
  const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
394
394
  ? storeContextValue.uninitializedState
395
- : internalStoreProps.unlockedInitialState;
395
+ : internalStoreProps.unwrappedInitialState;
396
396
  return React.useCallback(() => {
397
397
  if (actualStateLink.stateName === INITIALIZED_STATE_NAME) {
398
398
  return internalStore.isInitialized(actualInstanceKey);
@@ -462,7 +462,7 @@ function createUseStore(storeRegistry) {
462
462
  console.log(`Store instance initialization [store: ${internalStore.name}, instanceKey: ${instanceKey.toString()}]`);
463
463
  // TODO Убрать в логгер
464
464
  console.log({ storeRegistry });
465
- internalStore.initInstance(instanceKey, internalStoreProps.$$init, internalStoreProps.unlockedInitialState, prefill);
465
+ internalStore.initInstance(instanceKey, internalStoreProps.$$init, internalStoreProps.unwrappedInitialState, prefill);
466
466
  }
467
467
  else {
468
468
  console.warn(`Store instance is already initialized, initialization skipped [store: ${internalStore.name}, instanceKey: ${instanceKey.toString()}]`);
@@ -530,22 +530,22 @@ function createStoreRegistry() {
530
530
  function createStore(name, initialState, reducerMap) {
531
531
  const context = React.createContext(null);
532
532
  const lockedStateNames = [];
533
- const unlockedInitialState = { ...initialState };
533
+ const unwrappedInitialState = { ...initialState };
534
534
  for (const key in initialState) {
535
535
  const value = initialState[key];
536
536
  if (isLocked(value)) {
537
537
  lockedStateNames.push(key);
538
- unlockedInitialState[key] = value.value;
538
+ unwrappedInitialState[key] = value.value;
539
539
  }
540
- else if (isLockedOverride(value)) {
540
+ else if (isOverrideLocked(value)) {
541
541
  lockedStateNames.push(key);
542
- unlockedInitialState[key] = value.value;
542
+ unwrappedInitialState[key] = value.value;
543
543
  console.warn(`You used \`OVERRIDE_LOCKED\` in initial state [store: ${name}, property: ${key}]. Use \`LOCKED\` instead.`);
544
544
  }
545
545
  else {
546
- unlockedInitialState[key] = value;
546
+ unwrappedInitialState[key] = value;
547
547
  }
548
- if (unlockedInitialState[key] === undefined) {
548
+ if (unwrappedInitialState[key] === undefined) {
549
549
  console.warn(`Store property must not be \`undefined\`, use \`null\` instead [store: ${name}, property: ${key}]`);
550
550
  }
551
551
  }
@@ -557,7 +557,7 @@ function createStore(name, initialState, reducerMap) {
557
557
  lockedStateNames,
558
558
  name,
559
559
  uniqKey: Symbol(`Store: ` + name),
560
- unlockedInitialState,
560
+ unwrappedInitialState,
561
561
  };
562
562
  const store = {
563
563
  [INTERNAL_STORE_PROPS_ACCESSOR]: internalStoreProps,
@@ -597,7 +597,7 @@ function LOCKED(value) {
597
597
  }
598
598
 
599
599
  function OVERRIDE_LOCKED(value) {
600
- return Object.freeze({ kind: LOCKED_OVERRIDE_FLAG, value });
600
+ return Object.freeze({ kind: OVERRIDE_LOCKED_FLAG, value });
601
601
  }
602
602
 
603
603
  const requestStateDefault = {
@@ -9,7 +9,7 @@ const INSTANCE_KEY_STATE_NAME = `$$instanceKey`;
9
9
  const INTERNAL_BUG_MESSAGE = `This must never happen and may mean a bug inside the library itself. Please report it to the library developers.`;
10
10
  const INTERNAL_STORE_PROPS_ACCESSOR = Symbol(`INTERNAL_STORE_PROPS`);
11
11
  const LOCKED_FLAG = Symbol(`LOCKED`);
12
- const LOCKED_OVERRIDE_FLAG = Symbol(`LOCKED_OVERRIDE`);
12
+ const OVERRIDE_LOCKED_FLAG = Symbol(`OVERRIDE_LOCKED`);
13
13
  const REDUCER_LINK_FLAG = Symbol(`REDUCER_LINK`);
14
14
  const STATE_LINK_FLAG = Symbol(`STATE_LINK`);
15
15
  const STORE_INSTANCE_UNREGISTERED = Symbol(`STORE_INSTANCE_UNREGISTERED`);
@@ -18,12 +18,12 @@ function isLocked(value) {
18
18
  return typeof value === `object` && value !== null && `kind` in value && value.kind === LOCKED_FLAG;
19
19
  }
20
20
 
21
- function isLockedOverride(value) {
22
- return typeof value === `object` && value !== null && `kind` in value && value.kind === LOCKED_OVERRIDE_FLAG;
21
+ function isOverrideLocked(value) {
22
+ return typeof value === `object` && value !== null && `kind` in value && value.kind === OVERRIDE_LOCKED_FLAG;
23
23
  }
24
24
 
25
- function unlock(value) {
26
- if (isLocked(value) || isLockedOverride(value)) {
25
+ function unwrap(value) {
26
+ if (isLocked(value) || isOverrideLocked(value)) {
27
27
  return value.value;
28
28
  }
29
29
  else {
@@ -31,10 +31,10 @@ function unlock(value) {
31
31
  }
32
32
  }
33
33
 
34
- function mergePrefill(unlockedInitialState, prefill = {}) {
35
- const state = { ...unlockedInitialState };
34
+ function mergePrefill(unwrappedInitialState, prefill = {}) {
35
+ const state = { ...unwrappedInitialState };
36
36
  for (const stateName of Object.keys(prefill)) {
37
- const value = unlock(prefill[stateName]);
37
+ const value = unwrap(prefill[stateName]);
38
38
  if (value !== undefined) {
39
39
  state[stateName] = value;
40
40
  }
@@ -52,7 +52,7 @@ function createStoreProvider(useStore) {
52
52
  return initInstance(prefillRef.current.prefill);
53
53
  });
54
54
  const contextValue = useMemo(() => {
55
- return { instanceKey: actualInstanceKey, uninitializedState: mergePrefill(internalStoreProps.unlockedInitialState, prefillRef.current.prefill) };
55
+ return { instanceKey: actualInstanceKey, uninitializedState: mergePrefill(internalStoreProps.unwrappedInitialState, prefillRef.current.prefill) };
56
56
  }, [actualInstanceKey, internalStoreProps]);
57
57
  return (jsx(Context.Provider, { value: contextValue, children: props.children }));
58
58
  };
@@ -91,7 +91,7 @@ class InternalStore {
91
91
  };
92
92
  this.ensureInstance = (instanceKey) => {
93
93
  if (!this.instances[instanceKey]) {
94
- this.instances[instanceKey] = { deferredActions: [], listeners: new Set(), updatedLockedWarnedReducers: new Set(), wrappedUnlockedWarnedReducers: new Set() };
94
+ this.instances[instanceKey] = { deferredActions: [], listeners: new Set(), updatedLockedWarnedReducers: new Set(), wrappedNotLockedWarnedReducers: new Set() };
95
95
  }
96
96
  };
97
97
  this.getInstance = (instanceKey) => {
@@ -115,7 +115,7 @@ class InternalStore {
115
115
  return this.stateAll;
116
116
  };
117
117
  // TODO Охота изменить порядок параметров
118
- this.initInstance = (instanceKey, initReducer, unlockedInitialState, prefill = {}) => {
118
+ this.initInstance = (instanceKey, initReducer, unwrappedInitialState, prefill = {}) => {
119
119
  this.ensureInstance(instanceKey);
120
120
  const instance = this.getInstance(instanceKey);
121
121
  if (this.isInitialized(instanceKey)) {
@@ -126,15 +126,15 @@ class InternalStore {
126
126
  // TODO Смущает наличие двух этих вызовов подряд...
127
127
  // Такое ощущение, что надо бы обойтись одним.
128
128
  // TODO Надо спросить у ИИ что будет если от первого вызова избавиться и зачем он тут нужен
129
- const unlockedPrefill = {};
129
+ const unwrappedPrefill = {};
130
130
  for (const stateName of Object.keys(prefill)) {
131
- unlockedPrefill[stateName] = unlock(prefill[stateName]);
132
- if (unlockedPrefill[stateName] !== prefill[stateName]) {
131
+ unwrappedPrefill[stateName] = unwrap(prefill[stateName]);
132
+ if (unwrappedPrefill[stateName] !== prefill[stateName]) {
133
133
  console.warn(`You used \`LOCKED\` or \`OVERRIDE_LOCKED\` in prefill [store: ${this.name}, instanceKey: ${String(instanceKey)}, property: ${stateName}]. Pass an unwrapped value instead.`);
134
134
  }
135
135
  }
136
- this.applyState(instanceKey, mergePrefill(unlockedInitialState, unlockedPrefill));
137
- this.dispatch(instanceKey, initReducer, unlockedPrefill);
136
+ this.applyState(instanceKey, mergePrefill(unwrappedInitialState, unwrappedPrefill));
137
+ this.dispatch(instanceKey, initReducer, unwrappedPrefill);
138
138
  // TODO Требуется комментарий в коде...
139
139
  // Почему мы сначала сохраняем в переменную массив, и только потом идем по нему? Почему нельзя
140
140
  // идти сразу по нему?
@@ -148,15 +148,15 @@ class InternalStore {
148
148
  return instanceKey in this.stateAll;
149
149
  };
150
150
  this.patchState = (instanceKey, reducer, payload, prevState) => {
151
- const patch = reducer(prevState, payload);
151
+ const patch = reducer(prevState, payload) ?? {};
152
152
  const updatedLockedStateNames = [];
153
153
  const wrappedStateNames = [];
154
154
  let nextState = prevState;
155
155
  for (const stateName of Object.keys(patch)) {
156
- const value = unlock(patch[stateName]);
156
+ const value = unwrap(patch[stateName]);
157
157
  if (value !== undefined) {
158
158
  if (this.lockedStateNames.includes(stateName)) {
159
- if (!isLockedOverride(patch[stateName])) {
159
+ if (!isOverrideLocked(patch[stateName])) {
160
160
  updatedLockedStateNames.push(stateName);
161
161
  }
162
162
  }
@@ -176,8 +176,8 @@ class InternalStore {
176
176
  instance.updatedLockedWarnedReducers.add(reducer);
177
177
  console.warn(`You updated a property, which is marked as locked [store: ${this.name}, instanceKey: ${String(instanceKey)}, action: ${reducer.name}, property: ${updatedLockedStateNames.join(`, `)}]. Use \`OVERRIDE_LOCKED\`, if you really need to update it.`);
178
178
  }
179
- if (wrappedStateNames.length && !instance.wrappedUnlockedWarnedReducers.has(reducer)) {
180
- instance.wrappedUnlockedWarnedReducers.add(reducer);
179
+ if (wrappedStateNames.length && !instance.wrappedNotLockedWarnedReducers.has(reducer)) {
180
+ instance.wrappedNotLockedWarnedReducers.add(reducer);
181
181
  console.warn(`You used \`LOCKED\` or \`OVERRIDE_LOCKED\` for a property, which is not marked as locked [store: ${this.name}, instanceKey: ${String(instanceKey)}, action: ${reducer.name}, property: ${wrappedStateNames.join(`, `)}]. Return an unwrapped value instead.`);
182
182
  }
183
183
  return nextState;
@@ -197,7 +197,7 @@ class InternalStore {
197
197
  const nextState = this.patchState(instanceKey, resetReducer, undefined, prevState);
198
198
  this.applyState(instanceKey, undefined);
199
199
  instance.updatedLockedWarnedReducers.clear();
200
- instance.wrappedUnlockedWarnedReducers.clear();
200
+ instance.wrappedNotLockedWarnedReducers.clear();
201
201
  instance.listeners.forEach((listener) => listener(instanceKey, resetReducer, undefined));
202
202
  this.listenersAll.forEach((listener) => listener(instanceKey, resetReducer, undefined));
203
203
  // TODO Убрать в логгер
@@ -298,7 +298,7 @@ function createUseProp(storeRegistry) {
298
298
  const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
299
299
  const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
300
300
  ? storeContextValue.uninitializedState
301
- : internalStoreProps.unlockedInitialState;
301
+ : internalStoreProps.unwrappedInitialState;
302
302
  const subscribe = useCallback((listener) => {
303
303
  return internalStore.subscribe(actualInstanceKey, listener);
304
304
  }, [actualInstanceKey, internalStore]);
@@ -390,7 +390,7 @@ function createUsePropSelector(storeRegistry) {
390
390
  const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
391
391
  const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
392
392
  ? storeContextValue.uninitializedState
393
- : internalStoreProps.unlockedInitialState;
393
+ : internalStoreProps.unwrappedInitialState;
394
394
  return useCallback(() => {
395
395
  if (actualStateLink.stateName === INITIALIZED_STATE_NAME) {
396
396
  return internalStore.isInitialized(actualInstanceKey);
@@ -460,7 +460,7 @@ function createUseStore(storeRegistry) {
460
460
  console.log(`Store instance initialization [store: ${internalStore.name}, instanceKey: ${instanceKey.toString()}]`);
461
461
  // TODO Убрать в логгер
462
462
  console.log({ storeRegistry });
463
- internalStore.initInstance(instanceKey, internalStoreProps.$$init, internalStoreProps.unlockedInitialState, prefill);
463
+ internalStore.initInstance(instanceKey, internalStoreProps.$$init, internalStoreProps.unwrappedInitialState, prefill);
464
464
  }
465
465
  else {
466
466
  console.warn(`Store instance is already initialized, initialization skipped [store: ${internalStore.name}, instanceKey: ${instanceKey.toString()}]`);
@@ -528,22 +528,22 @@ function createStoreRegistry() {
528
528
  function createStore(name, initialState, reducerMap) {
529
529
  const context = React.createContext(null);
530
530
  const lockedStateNames = [];
531
- const unlockedInitialState = { ...initialState };
531
+ const unwrappedInitialState = { ...initialState };
532
532
  for (const key in initialState) {
533
533
  const value = initialState[key];
534
534
  if (isLocked(value)) {
535
535
  lockedStateNames.push(key);
536
- unlockedInitialState[key] = value.value;
536
+ unwrappedInitialState[key] = value.value;
537
537
  }
538
- else if (isLockedOverride(value)) {
538
+ else if (isOverrideLocked(value)) {
539
539
  lockedStateNames.push(key);
540
- unlockedInitialState[key] = value.value;
540
+ unwrappedInitialState[key] = value.value;
541
541
  console.warn(`You used \`OVERRIDE_LOCKED\` in initial state [store: ${name}, property: ${key}]. Use \`LOCKED\` instead.`);
542
542
  }
543
543
  else {
544
- unlockedInitialState[key] = value;
544
+ unwrappedInitialState[key] = value;
545
545
  }
546
- if (unlockedInitialState[key] === undefined) {
546
+ if (unwrappedInitialState[key] === undefined) {
547
547
  console.warn(`Store property must not be \`undefined\`, use \`null\` instead [store: ${name}, property: ${key}]`);
548
548
  }
549
549
  }
@@ -555,7 +555,7 @@ function createStore(name, initialState, reducerMap) {
555
555
  lockedStateNames,
556
556
  name,
557
557
  uniqKey: Symbol(`Store: ` + name),
558
- unlockedInitialState,
558
+ unwrappedInitialState,
559
559
  };
560
560
  const store = {
561
561
  [INTERNAL_STORE_PROPS_ACCESSOR]: internalStoreProps,
@@ -595,7 +595,7 @@ function LOCKED(value) {
595
595
  }
596
596
 
597
597
  function OVERRIDE_LOCKED(value) {
598
- return Object.freeze({ kind: LOCKED_OVERRIDE_FLAG, value });
598
+ return Object.freeze({ kind: OVERRIDE_LOCKED_FLAG, value });
599
599
  }
600
600
 
601
601
  const requestStateDefault = {
package/package.json CHANGED
@@ -20,5 +20,5 @@
20
20
  "prepublishOnly": "npm run build"
21
21
  },
22
22
  "types": "dist/@types",
23
- "version": "0.1.13"
23
+ "version": "0.1.15"
24
24
  }
@@ -1,2 +0,0 @@
1
- import type { LockedOverride } from './types/LockedOverride.tsx';
2
- export declare function isLockedOverride(value: unknown): value is LockedOverride;
@@ -1,5 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import type { Locked } from './Locked.tsx';
2
- export type Unlocked<TValue = unknown> = TValue extends Locked<infer TInnerValue> ? TInnerValue : TValue;
@@ -1,5 +0,0 @@
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 +0,0 @@
1
- export declare function unlock(value: unknown): unknown;