beestate 0.1.14 → 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.
- package/dist/@types/OVERRIDE_LOCKED.d.ts +2 -2
- package/dist/@types/constants.d.ts +1 -1
- package/dist/@types/createStore.d.ts +3 -3
- package/dist/@types/index.d.ts +4 -0
- package/dist/@types/isOverrideLocked.d.ts +2 -0
- package/dist/@types/mergePrefill.d.ts +2 -2
- package/dist/@types/pickPropAll.d.ts +3 -3
- package/dist/@types/types/InternalStore/ApplyState.d.ts +2 -2
- package/dist/@types/types/InternalStore/GetState.d.ts +2 -2
- package/dist/@types/types/InternalStore/GetStateAll.d.ts +2 -2
- package/dist/@types/types/InternalStore/InitInstance.d.ts +2 -2
- package/dist/@types/types/InternalStore/PatchState.d.ts +2 -2
- package/dist/@types/types/InternalStoreProps.d.ts +2 -2
- package/dist/@types/types/OverrideLocked.d.ts +5 -0
- package/dist/@types/types/Patch.d.ts +2 -2
- package/dist/@types/types/Prefill.d.ts +2 -2
- package/dist/@types/types/Reducer.d.ts +2 -2
- package/dist/@types/types/StoreContextValue.d.ts +2 -2
- package/dist/@types/types/StoreInstance.d.ts +1 -1
- package/dist/@types/types/Unwrapped.d.ts +3 -0
- package/dist/@types/types/UnwrappedState.d.ts +5 -0
- package/dist/@types/types/UseProp.d.ts +2 -2
- package/dist/@types/types/UsePropAll.d.ts +3 -3
- package/dist/@types/types/UsePropSelector.d.ts +2 -2
- package/dist/@types/types/UsePropSelectorAll.d.ts +3 -3
- package/dist/@types/types/WithLocked.d.ts +5 -0
- package/dist/@types/unwrap.d.ts +1 -0
- package/dist/cjs/index.cjs.js +32 -32
- package/dist/esm/index.esm.js +32 -32
- package/package.json +1 -1
- package/dist/@types/isLockedOverride.d.ts +0 -2
- package/dist/@types/types/LockedOverride.d.ts +0 -5
- package/dist/@types/types/Unlocked.d.ts +0 -2
- package/dist/@types/types/UnlockedState.d.ts +0 -5
- package/dist/@types/unlock.d.ts +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function OVERRIDE_LOCKED<TValue extends null | NonNullable<unknown>>(value: 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
|
|
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 {
|
|
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 {
|
|
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
|
|
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;
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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';
|
|
4
5
|
export { type Prefill } from './types/Prefill.tsx';
|
|
5
6
|
export { type RequestState } from './types/RequestState.tsx';
|
|
@@ -8,6 +9,9 @@ export { type RequestFulfilledState } from './types/RequestState/RequestFulfille
|
|
|
8
9
|
export { type RequestIdleState } from './types/RequestState/RequestIdleState.tsx';
|
|
9
10
|
export { type RequestPendingState } from './types/RequestState/RequestPendingState.tsx';
|
|
10
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';
|
|
11
15
|
export { DESTROY } from './constants.tsx';
|
|
12
16
|
export { createStore } from './createStore.tsx';
|
|
13
17
|
export { createStoreRegistry } from './createStoreRegistry.tsx';
|
|
@@ -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 {
|
|
4
|
-
export declare function mergePrefill<TStoreState extends StoreState = StoreState>(
|
|
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 {
|
|
4
|
-
import type {
|
|
5
|
-
export declare function pickPropAll<TStoreState extends StoreState = StoreState, TStateName extends keyof TStoreState = keyof TStoreState>(stateAll: Record<InstanceKey,
|
|
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 {
|
|
3
|
+
import type { UnwrappedState } from '../UnwrappedState.tsx';
|
|
4
4
|
export type ApplyState<TStoreState extends StoreState = StoreState> = {
|
|
5
|
-
(instanceKey: InstanceKey, state: undefined |
|
|
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 {
|
|
3
|
+
import type { UnwrappedState } from '../UnwrappedState.tsx';
|
|
4
4
|
export type GetState<TStoreState extends StoreState = StoreState> = {
|
|
5
|
-
(instanceKey: InstanceKey):
|
|
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 {
|
|
3
|
+
import type { UnwrappedState } from '../UnwrappedState.tsx';
|
|
4
4
|
export type GetStateAll<TStoreState extends StoreState = StoreState> = {
|
|
5
|
-
(): Record<InstanceKey,
|
|
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 {
|
|
5
|
+
import type { UnwrappedState } from '../UnwrappedState.tsx';
|
|
6
6
|
export type InitInstance<TStoreState extends StoreState = StoreState> = {
|
|
7
|
-
(instanceKey: InstanceKey, initReducer: Reducer<TStoreState, Prefill<TStoreState>>,
|
|
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 {
|
|
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:
|
|
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 {
|
|
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
|
-
|
|
14
|
+
unwrappedInitialState: UnwrappedState<TStoreState>;
|
|
15
15
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locked } from './Locked.tsx';
|
|
2
|
-
import type {
|
|
2
|
+
import type { OverrideLocked } from './OverrideLocked.tsx';
|
|
3
3
|
import type { StoreState } from './StoreState.tsx';
|
|
4
4
|
export type Patch<TStoreState extends StoreState = StoreState> = null | {
|
|
5
|
-
[TKey in keyof TStoreState]?: undefined | (TStoreState[TKey] extends Locked<infer TValue> ?
|
|
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 {
|
|
2
|
+
import type { Unwrapped } from './Unwrapped.tsx';
|
|
3
3
|
export type Prefill<TStoreState extends StoreState = StoreState> = {
|
|
4
|
-
[TKey in keyof TStoreState]?: undefined |
|
|
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 {
|
|
4
|
+
import type { UnwrappedState } from './UnwrappedState.tsx';
|
|
5
5
|
export type Reducer<TStoreState extends StoreState = StoreState, TPayload extends void | Payload = void | Payload> = {
|
|
6
|
-
(state:
|
|
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 {
|
|
3
|
+
import type { UnwrappedState } from './UnwrappedState.tsx';
|
|
4
4
|
export type StoreContextValue<TStoreState extends StoreState = StoreState> = {
|
|
5
5
|
instanceKey: InstanceKey;
|
|
6
|
-
uninitializedState:
|
|
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
|
-
|
|
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;
|
|
@@ -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 {
|
|
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):
|
|
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 {
|
|
6
|
-
import type {
|
|
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:
|
|
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 {
|
|
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): () =>
|
|
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 {
|
|
6
|
-
import type {
|
|
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:
|
|
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;
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -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
|
|
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
|
|
24
|
-
return typeof value === `object` && value !== null && `kind` in value && value.kind ===
|
|
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
|
|
28
|
-
if (isLocked(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(
|
|
37
|
-
const state = { ...
|
|
36
|
+
function mergePrefill(unwrappedInitialState, prefill = {}) {
|
|
37
|
+
const state = { ...unwrappedInitialState };
|
|
38
38
|
for (const stateName of Object.keys(prefill)) {
|
|
39
|
-
const value =
|
|
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.
|
|
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(),
|
|
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,
|
|
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
|
|
131
|
+
const unwrappedPrefill = {};
|
|
132
132
|
for (const stateName of Object.keys(prefill)) {
|
|
133
|
-
|
|
134
|
-
if (
|
|
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(
|
|
139
|
-
this.dispatch(instanceKey, initReducer,
|
|
138
|
+
this.applyState(instanceKey, mergePrefill(unwrappedInitialState, unwrappedPrefill));
|
|
139
|
+
this.dispatch(instanceKey, initReducer, unwrappedPrefill);
|
|
140
140
|
// TODO Требуется комментарий в коде...
|
|
141
141
|
// Почему мы сначала сохраняем в переменную массив, и только потом идем по нему? Почему нельзя
|
|
142
142
|
// идти сразу по нему?
|
|
@@ -155,10 +155,10 @@ class InternalStore {
|
|
|
155
155
|
const wrappedStateNames = [];
|
|
156
156
|
let nextState = prevState;
|
|
157
157
|
for (const stateName of Object.keys(patch)) {
|
|
158
|
-
const value =
|
|
158
|
+
const value = unwrap(patch[stateName]);
|
|
159
159
|
if (value !== undefined) {
|
|
160
160
|
if (this.lockedStateNames.includes(stateName)) {
|
|
161
|
-
if (!
|
|
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.
|
|
182
|
-
instance.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
-
|
|
538
|
+
unwrappedInitialState[key] = value.value;
|
|
539
539
|
}
|
|
540
|
-
else if (
|
|
540
|
+
else if (isOverrideLocked(value)) {
|
|
541
541
|
lockedStateNames.push(key);
|
|
542
|
-
|
|
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
|
-
|
|
546
|
+
unwrappedInitialState[key] = value;
|
|
547
547
|
}
|
|
548
|
-
if (
|
|
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
|
-
|
|
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:
|
|
600
|
+
return Object.freeze({ kind: OVERRIDE_LOCKED_FLAG, value });
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
const requestStateDefault = {
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -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
|
|
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
|
|
22
|
-
return typeof value === `object` && value !== null && `kind` in value && value.kind ===
|
|
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
|
|
26
|
-
if (isLocked(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(
|
|
35
|
-
const state = { ...
|
|
34
|
+
function mergePrefill(unwrappedInitialState, prefill = {}) {
|
|
35
|
+
const state = { ...unwrappedInitialState };
|
|
36
36
|
for (const stateName of Object.keys(prefill)) {
|
|
37
|
-
const value =
|
|
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.
|
|
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(),
|
|
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,
|
|
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
|
|
129
|
+
const unwrappedPrefill = {};
|
|
130
130
|
for (const stateName of Object.keys(prefill)) {
|
|
131
|
-
|
|
132
|
-
if (
|
|
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(
|
|
137
|
-
this.dispatch(instanceKey, initReducer,
|
|
136
|
+
this.applyState(instanceKey, mergePrefill(unwrappedInitialState, unwrappedPrefill));
|
|
137
|
+
this.dispatch(instanceKey, initReducer, unwrappedPrefill);
|
|
138
138
|
// TODO Требуется комментарий в коде...
|
|
139
139
|
// Почему мы сначала сохраняем в переменную массив, и только потом идем по нему? Почему нельзя
|
|
140
140
|
// идти сразу по нему?
|
|
@@ -153,10 +153,10 @@ class InternalStore {
|
|
|
153
153
|
const wrappedStateNames = [];
|
|
154
154
|
let nextState = prevState;
|
|
155
155
|
for (const stateName of Object.keys(patch)) {
|
|
156
|
-
const value =
|
|
156
|
+
const value = unwrap(patch[stateName]);
|
|
157
157
|
if (value !== undefined) {
|
|
158
158
|
if (this.lockedStateNames.includes(stateName)) {
|
|
159
|
-
if (!
|
|
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.
|
|
180
|
-
instance.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
-
|
|
536
|
+
unwrappedInitialState[key] = value.value;
|
|
537
537
|
}
|
|
538
|
-
else if (
|
|
538
|
+
else if (isOverrideLocked(value)) {
|
|
539
539
|
lockedStateNames.push(key);
|
|
540
|
-
|
|
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
|
-
|
|
544
|
+
unwrappedInitialState[key] = value;
|
|
545
545
|
}
|
|
546
|
-
if (
|
|
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
|
-
|
|
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:
|
|
598
|
+
return Object.freeze({ kind: OVERRIDE_LOCKED_FLAG, value });
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
const requestStateDefault = {
|
package/package.json
CHANGED
package/dist/@types/unlock.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function unlock(value: unknown): unknown;
|