From 393d9cebf82026f1501fc653377e949c2b703584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 30 Mar 2021 17:30:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=20libraryMap=20refactor:=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=20setupComponents,=20=E7=9B=B4=E6=8E=A5=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20renderer=20=E7=9A=84=20load/buildComponents=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0,=20=E7=A1=AE=E4=BF=9D=E5=A4=9A=E4=B8=AA=20re?= =?UTF-8?q?nderer=20=E9=83=BD=E8=83=BD=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/builtin-simulator/host.ts | 4 +++- packages/designer/src/designer/designer.ts | 17 ++++++----------- .../react-simulator-renderer/src/renderer.ts | 11 +++-------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 077d5a895..e5b07de7c 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -261,6 +261,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost { + this.libraryMap[item.package] = item.library; if (item.async) { this.asyncLibraryMap[item.package] = item; } @@ -342,7 +343,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost { const { components, packages } = incrementalAssets; components && this.buildComponentMetasMap(components); - // 部分异步组件会在外层加载components,这里需要进行强制刷新 - this.forceUpdateComponentsMap(); - await this.project.simulator.setupComponents(packages); + if (packages) { + await this.project.simulator!.setupComponents(packages); + } if (components) { // 合并assets @@ -387,6 +387,8 @@ export class Designer { let newAssets = megreAssets(assets, incrementalAssets); this.editor.set('assets', newAssets); } + // TODO: 因为涉及修改 prototype.view,之后在 renderer 里修改了 vc 的 view 获取逻辑后,可删除 + this._componentMetasMap = new Map(this._componentMetasMap); // 完成加载增量资源后发送事件,方便插件监听并处理相关逻辑 this.editor.emit('designer.incrementalAssetsReady'); @@ -503,13 +505,6 @@ export class Designer { return maps; } - /** - * 强制刷新 componentsMap,使画布能拿到最新的组件 - */ - private forceUpdateComponentsMap() { - this._componentMetasMap = new Map(this._componentMetasMap); - } - private propsReducers = new Map(); transformProps(props: CompositeObject | PropsList, node: Node, stage: TransformStage) { diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index 37ff9ed38..adf4e07ec 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -348,20 +348,15 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { /** * 加载资源 */ - // load(asset: Asset): Promise { - // return loader.load(asset); - // } + load(asset: Asset): Promise { + return loader.load(asset); + } async loadAsyncLibrary(asyncLibraryMap) { await loader.loadAsyncLibrary(asyncLibraryMap); this.buildComponents(); } - async setupComponents(asset: Asset) { - await loader.load(asset); - this.buildComponents(); - } - getComponent(componentName: string) { const paths = componentName.split('.'); const subs: string[] = [];