From 701a9d6f3043f77048f6b9be3bc2305adb14d57e Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 20 Jan 2025 14:58:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20deep-state-observer=20update=20?= =?UTF-8?q?=E7=9A=84data=E4=B8=8E=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=EF=BC=8C=E5=AF=BC=E8=87=B4get=20data?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/tests/App.spec.ts | 3 ++- packages/data-source/src/DataSourceManager.ts | 2 +- packages/data-source/src/data-sources/Base.ts | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/tests/App.spec.ts b/packages/core/tests/App.spec.ts index f3925933..5aa3d903 100644 --- a/packages/core/tests/App.spec.ts +++ b/packages/core/tests/App.spec.ts @@ -1,8 +1,9 @@ import { describe, expect, test } from 'vitest'; -import { MApp, NodeType, TMagicIteratorContainer } from '@tmagic/schema'; +import { MApp, NodeType } from '@tmagic/schema'; import App from '../src/App'; +import TMagicIteratorContainer from '../src/IteratorContainer'; const createAppDsl = (pageLength: number, nodeLength = 0) => { const dsl: MApp = { diff --git a/packages/data-source/src/DataSourceManager.ts b/packages/data-source/src/DataSourceManager.ts index 334936e6..ac0dc7e4 100644 --- a/packages/data-source/src/DataSourceManager.ts +++ b/packages/data-source/src/DataSourceManager.ts @@ -177,7 +177,7 @@ class DataSourceManager extends EventEmitter { this.removeDataSource(schema.id); - this.addDataSource(schema); + this.addDataSource(cloneDeep(schema)); const newDs = this.get(schema.id); if (newDs) { this.init(newDs); diff --git a/packages/data-source/src/data-sources/Base.ts b/packages/data-source/src/data-sources/Base.ts index a5515775..f69e9ef3 100644 --- a/packages/data-source/src/data-sources/Base.ts +++ b/packages/data-source/src/data-sources/Base.ts @@ -62,13 +62,15 @@ export default class DataSource e // eslint-disable-next-line @typescript-eslint/naming-convention const ObservedDataClass = options.ObservedDataClass || SimpleObservedData; if (this.app.platform === 'editor') { + const mocks = cloneDeep(options.schema.mocks || []); // 编辑器中有mock使用mock,没有使用默认值 - this.mockData = options.schema.mocks?.find((mock) => mock.useInEditor)?.data || this.getDefaultData(); + this.mockData = mocks.find((mock) => mock.useInEditor)?.data || this.getDefaultData(); data = cloneDeep(this.mockData); } else if (typeof options.useMock === 'boolean' && options.useMock) { + const mocks = cloneDeep(options.schema.mocks || []); // 设置了使用mock就使用mock数据 - this.mockData = options.schema.mocks?.find((mock) => mock.enable)?.data; - data = this.mockData || this.getDefaultData(); + this.mockData = mocks.find((mock) => mock.enable)?.data; + data = cloneDeep(this.mockData) || this.getDefaultData(); } else if (!options.initialData) { data = this.getDefaultData(); } else {