fix: 修复无法获取 libraryMap

refactor: 移除 setupComponents, 直接调用 renderer 的 load/buildComponents 函数, 确保多个 renderer 都能 work
This commit is contained in:
力皓 2021-03-30 17:30:52 +08:00
parent c463b73580
commit 393d9cebf8
3 changed files with 12 additions and 20 deletions

View File

@ -261,6 +261,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const libraryAsset: AssetList = [];
if (library) {
library.forEach((item) => {
this.libraryMap[item.package] = item.library;
if (item.async) {
this.asyncLibraryMap[item.package] = item;
}
@ -342,7 +343,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
async setupComponents(library) {
const libraryAsset: AssetList = this.buildLibrary(library);
await this.renderer.setupComponents(libraryAsset);
await this.renderer.load(libraryAsset);
await this.renderer.buildComponents();
}
setupEvents() {

View File

@ -374,12 +374,12 @@ export class Designer {
this.props = props;
}
async loadIncrementalAssets(incrementalAssets: AssetsJson): void {
async loadIncrementalAssets(incrementalAssets: AssetsJson): Promise<void> {
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<TransformStage, PropsReducer[]>();
transformProps(props: CompositeObject | PropsList, node: Node, stage: TransformStage) {

View File

@ -348,20 +348,15 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
/**
*
*/
// load(asset: Asset): Promise<any> {
// return loader.load(asset);
// }
load(asset: Asset): Promise<any> {
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[] = [];