fix: 修复组件元数据更新后 SettingTopEntry 未同步更新的 bug

This commit is contained in:
力皓 2021-06-18 12:01:17 +08:00
parent a2c8bc26f1
commit 8b0c9189e2
2 changed files with 23 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import { IconRemove } from './icons/remove';
import { IconClone } from './icons/clone';
import { ReactElement } from 'react';
import { IconHidden } from './icons/hidden';
import EventEmitter from 'events';
function ensureAList(list?: string | string[]): string[] | null {
if (!list) {
@ -66,6 +67,8 @@ export class ComponentMeta {
private _npm?: NpmInfo;
private emitter: EventEmitter = new EventEmitter();
get npm() {
return this._npm;
}
@ -229,6 +232,11 @@ export class ComponentMeta {
this._isContainer = false;
this._isModal = false;
}
this.emitter.emit('metadata_change');
}
refreshMetadata() {
this.parseMetadata(this.getMetadata());
}
private transformMetadata(metadta: ComponentMetadata): TransformedComponentMetadata {
@ -297,6 +305,13 @@ export class ComponentMeta {
return true;
}
onMetadataChange(fn: (args: any) => void): () => void {
this.emitter.on('metadata_change', fn);
return () => {
this.emitter.removeListener('metadata_change', fn);
};
}
// compatiable vision
prototype?: any;
}

View File

@ -80,6 +80,8 @@ export class SettingTopEntry implements SettingEntry {
// clear fields
this.setupItems();
this.setupEvents();
}
private setupComponentMeta() {
@ -120,6 +122,12 @@ export class SettingTopEntry implements SettingEntry {
}
}
private setupEvents() {
this.componentMeta?.onMetadataChange(() => {
this.setupItems();
});
}
/**
*
*/