From 849dc070db67686960bbe0765293a0963ecb05a2 Mon Sep 17 00:00:00 2001 From: YeanSe <1730214056@qq.com> Date: Tue, 26 Jul 2022 01:52:41 +0800 Subject: [PATCH] chore: not deep clone the initialState --- src/model/defineModel.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/model/defineModel.ts b/src/model/defineModel.ts index d2506c5..0de70e3 100644 --- a/src/model/defineModel.ts +++ b/src/model/defineModel.ts @@ -40,7 +40,6 @@ export const defineModel = < const { actions, effects, computed, skipRefresh, events } = options; const isArrayState = Array.isArray(options.initialState); - const initialStateStr = stringifyState(options.initialState); if (process.env.NODE_ENV !== 'production') { const items = [ @@ -67,6 +66,7 @@ export const defineModel = < } if (process.env.NODE_ENV !== 'production') { + const initialStateStr = stringifyState(options.initialState); if (!deepEqual(parseState(initialStateStr), options.initialState)) { throw new Error( `[model:${uniqueName}] initialState 包含了不可系列化的数据,允许的类型为:Object, Array, Number, String, Undefined 和 Null`, @@ -90,7 +90,7 @@ export const defineModel = < const getInitialState = ( obj: T, ): T & GetInitialState => { - return defineGetter(obj, 'initialState', () => parseState(initialStateStr)); + return defineGetter(obj, 'initialState', () => options.initialState); }; const actionCtx: ActionCtx = composeGetter( @@ -228,7 +228,7 @@ export const defineModel = < uniqueName, createReducer({ name: uniqueName, - initialState: parseState(initialStateStr), + initialState: options.initialState, allowRefresh: !skipRefresh, }), );