Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: not deep clone the initialState #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/model/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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`,
Expand All @@ -90,7 +90,7 @@ export const defineModel = <
const getInitialState = <T extends object>(
obj: T,
): T & GetInitialState<State> => {
return defineGetter(obj, 'initialState', () => parseState(initialStateStr));
return defineGetter(obj, 'initialState', () => options.initialState);
};

const actionCtx: ActionCtx<State> = composeGetter(
Expand Down Expand Up @@ -228,7 +228,7 @@ export const defineModel = <
uniqueName,
createReducer({
name: uniqueName,
initialState: parseState(initialStateStr),
initialState: options.initialState,
allowRefresh: !skipRefresh,
}),
);
Expand Down