fix: 调整 components 触发视图刷新的机制, designer _componentMetasMap 引用更新才触发 renderer components 更新

This commit is contained in:
力皓 2021-04-14 11:18:56 +08:00
parent dc5fa1d257
commit a9cead0339
3 changed files with 4 additions and 5 deletions

View File

@ -353,7 +353,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
async setupComponents(library) {
const libraryAsset: AssetList = this.buildLibrary(library);
await this.renderer.load(libraryAsset);
await this.renderer.buildComponents();
}
setupEvents() {

View File

@ -388,7 +388,7 @@ export class Designer {
this.editor.set('assets', newAssets);
}
// TODO: 因为涉及修改 prototype.view之后在 renderer 里修改了 vc 的 view 获取逻辑后,可删除
this._componentMetasMap = new Map(this._componentMetasMap);
// this._componentMetasMap = new Map(this._componentMetasMap);
// 完成加载增量资源后发送事件,方便插件监听并处理相关逻辑
this.editor.emit('designer.incrementalAssetsReady');
@ -433,7 +433,7 @@ export class Designer {
this.project.load(schema);
}
@obx.val private _componentMetasMap = new Map<string, ComponentMeta>();
@obx.ref private _componentMetasMap = new Map<string, ComponentMeta>();
private _lostComponentMetasMap = new Map<string, ComponentMeta>();

View File

@ -309,9 +309,9 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
...this._components,
};
}
private _components: any = {};
@obx.ref private _components: any = {};
get components(): object {
@computed get components(): object {
// 根据 device 选择不同组件,进行响应式
// 更好的做法是,根据 device 选择加载不同的组件资源,甚至是 simulatorUrl
return this._components;