Skip to content

Commit a1e5c11

Browse files
committed
feat(reactant-module): add initStateKey for module
1 parent b604e7c commit a1e5c11

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

packages/reactant-module/src/constants/moduleKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const containerKey: unique symbol = Symbol('container');
22
export const identifierKey: unique symbol = Symbol('identifier');
33
export const modulesKey: unique symbol = Symbol('modules');
44
export const nameKey: unique symbol = Symbol('name');
5+
export const initStateKey: unique symbol = Symbol('initState');

packages/reactant-module/src/core/createStore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable default-param-last */
12
/* eslint-disable guard-for-in */
23
/* eslint-disable @typescript-eslint/no-empty-function */
34
/* eslint-disable no-loop-func */
@@ -32,6 +33,7 @@ import {
3233
nameKey,
3334
stateKey,
3435
storeKey,
36+
initStateKey,
3537
subscriptionsKey,
3638
} from '../constants';
3739
import { getStagedState } from '../decorators';
@@ -173,6 +175,14 @@ export function createStore<T = any>({
173175
const initState = enableAutoFreeze
174176
? produce({ ...service[stateKey] }, () => {}) // freeze init state
175177
: service[stateKey]!;
178+
Object.assign(descriptors, {
179+
[initStateKey]: {
180+
enumerable: false,
181+
configurable: false,
182+
writable: false,
183+
value: initState,
184+
},
185+
});
176186
const serviceReducers = Object.keys(initState).reduce(
177187
(serviceReducersMapObject: ReducersMapObject, key) => {
178188
const value =

packages/reactant-module/src/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
identifierKey,
2929
nameKey,
3030
modulesKey,
31+
initStateKey,
3132
} from './constants';
3233
import { PluginModule } from './core';
3334

@@ -72,6 +73,7 @@ export interface Service<T extends Record<string, any> = Record<string, any>> {
7273
readonly [subscriptionsKey]?: Subscriptions;
7374
readonly [containerKey]?: Container;
7475
readonly [modulesKey]?: Record<string, any>;
76+
readonly [initStateKey]?: Record<string, any>;
7577
[identifierKey]?: string;
7678
[nameKey]?: string;
7779
}

0 commit comments

Comments
 (0)