From a1e7f21e21c694c7d9991d5554f20748ff77439e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 22 Oct 2020 17:42:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9=20c?= =?UTF-8?q?omponentsMap=20=E5=90=8E=E6=97=A0=E6=B3=95=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/.eslintrc.js | 1 + packages/designer/jest.config.js | 18 ++++++------------ packages/designer/src/document/node/node.ts | 13 +++++++++++++ .../tests/fixtures/schema/{form.js => form.ts} | 0 .../{project.test.js => project.test.ts} | 4 ++-- .../tests/utils/{index.js => index.ts} | 0 packages/react-renderer/package.json | 2 +- .../react-simulator-renderer/src/renderer.ts | 10 +++++----- 8 files changed, 28 insertions(+), 20 deletions(-) rename packages/designer/tests/fixtures/schema/{form.js => form.ts} (100%) rename packages/designer/tests/project/{project.test.js => project.test.ts} (98%) rename packages/designer/tests/utils/{index.js => index.ts} (100%) diff --git a/packages/designer/.eslintrc.js b/packages/designer/.eslintrc.js index 36bb033f3..a44376585 100644 --- a/packages/designer/.eslintrc.js +++ b/packages/designer/.eslintrc.js @@ -1,5 +1,6 @@ module.exports = { extends: 'eslint-config-ali/typescript/react', + ignorePatterns: [ 'tests/* '], rules: { 'react/no-multi-comp': 0, 'no-unused-expressions': 1, diff --git a/packages/designer/jest.config.js b/packages/designer/jest.config.js index e48c977d3..83eb1dc90 100644 --- a/packages/designer/jest.config.js +++ b/packages/designer/jest.config.js @@ -1,17 +1,11 @@ -// jest.config.js -const { pathsToModuleNameMapper } = require('ts-jest/utils'); -// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file -// which contains the path mapping (ie the `compilerOptions.paths` option): - const esModules = ['@recore/obx-react'].join('|'); -// console.log('>>> compilerOptions', compilerOptions); -// console.log('>>> compilerOptions', pathsToModuleNameMapper(compilerOptions.paths)); + module.exports = { - /* transform: { - '^.+\\.[jt]sx?$': 'babel-jest', - // '^.+\\.(ts|tsx)$': 'ts-jest', - // '^.+\\.(js|jsx)$': 'babel-jest', - }, */ + // transform: { + // '^.+\\.[jt]sx?$': 'babel-jest', + // // '^.+\\.(ts|tsx)$': 'ts-jest', + // // '^.+\\.(js|jsx)$': 'babel-jest', + // }, // testMatch: ['(/tests?/.*(test))\\.[jt]s$'], transformIgnorePatterns: [ `/node_modules/(?!${esModules})/`, diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index 044237c7c..fd486a4be 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -263,6 +263,16 @@ export class Node { } } + private didDropOut(dragment: Node) { + const callbacks = this.componentMeta.getMetadata().experimental?.callbacks; + if (callbacks?.onNodeRemove) { + callbacks?.onNodeRemove.call(this, dragment, this); + } + if (this._parent) { + this._parent.didDropOut(dragment); + } + } + /** * 内部方法,请勿使用 * @param useMutator 是否触发联动逻辑 @@ -280,6 +290,9 @@ export class Node { this._parent.children.unlinkChild(this); } } + // if (useMutator) { + // this._parent?.didDropOut(this); + // } // 建立新的父子关系 this._parent = parent; if (parent) { diff --git a/packages/designer/tests/fixtures/schema/form.js b/packages/designer/tests/fixtures/schema/form.ts similarity index 100% rename from packages/designer/tests/fixtures/schema/form.js rename to packages/designer/tests/fixtures/schema/form.ts diff --git a/packages/designer/tests/project/project.test.js b/packages/designer/tests/project/project.test.ts similarity index 98% rename from packages/designer/tests/project/project.test.js rename to packages/designer/tests/project/project.test.ts index eafa8aa3a..c98c82592 100644 --- a/packages/designer/tests/project/project.test.js +++ b/packages/designer/tests/project/project.test.ts @@ -27,7 +27,7 @@ jest.mock('../../src/designer/designer', () => { let designer = null; beforeAll(() => { - designer = new Designer({}); + designer = new Designer({} as any); }); describe('schema 渲染测试', () => { @@ -47,7 +47,7 @@ describe('schema 渲染测试', () => { }, }], }], - }); + } as any); project.open(); expect(project).toBeTruthy(); const { currentDocument } = project; diff --git a/packages/designer/tests/utils/index.js b/packages/designer/tests/utils/index.ts similarity index 100% rename from packages/designer/tests/utils/index.js rename to packages/designer/tests/utils/index.ts diff --git a/packages/react-renderer/package.json b/packages/react-renderer/package.json index db121f1ea..7dd2278f4 100644 --- a/packages/react-renderer/package.json +++ b/packages/react-renderer/package.json @@ -54,5 +54,5 @@ "publishConfig": { "registry": "http://registry.npm.alibaba-inc.com" }, - "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.13.1-4/build/index.html" + "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.13.1-5/build/index.html" } diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index d2afc06de..b07935f0b 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -178,7 +178,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { constructor() { this.dispose = host.connect(this, async () => { - await host.waitForCurrentDocument(); // sync layout config this._layout = host.project.get('config').layout; @@ -186,6 +185,9 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { if (this._libraryMap !== host.libraryMap || this._componentsMap !== host.designer.componentsMap) { this._libraryMap = host.libraryMap || {}; this._componentsMap = host.designer.componentsMap; + // 需要注意的是,autorun 依赖收集的是同步执行的代码,所以 await / promise / callback 里的变量不会被收集依赖 + // 此例中,host.designer.componentsMap 是需要被收集依赖的,否则无法响应式 + await host.waitForCurrentDocument(); this.buildComponents(); } @@ -211,10 +213,8 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { : '/'; if (firstRun) { initialEntry = path; - } else { - if (this.history.location.pathname !== path) { - this.history.replace(path); - } + } else if (this.history.location.pathname !== path) { + this.history.replace(path); } }); const history = createMemoryHistory({