fix(material): when the assets exist, use onChangeAssets api, the callback is called immediately

This commit is contained in:
liujuping 2023-08-11 17:20:32 +08:00 committed by 林熠
parent 0eeee1feee
commit c458b1b2ec
3 changed files with 25 additions and 1 deletions

View File

@ -222,6 +222,16 @@ export class Editor extends EventEmitter implements IEditor {
};
}
onChange<T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
keyOrType: KeyOrType,
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void,
): () => void {
this.setWait(keyOrType, fn);
return () => {
this.delWait(keyOrType, fn);
};
}
register(data: any, key?: IPublicTypeEditorValueKey): void {
this.context.set(key || data, data);
this.notifyGot(key || data);

View File

@ -181,7 +181,7 @@ export class Material implements IPublicApiMaterial {
onChangeAssets(fn: () => void): IPublicTypeDisposable {
const dispose = [
// 设置 assets经过 setAssets 赋值
this[editorSymbol].onGot('assets', fn),
this[editorSymbol].onChange('assets', fn),
// 增量设置 assets经过 loadIncrementalAssets 赋值
this[editorSymbol].eventBus.on('designer.incrementalAssetsReady', fn),
];

View File

@ -15,13 +15,27 @@ export interface IPublicModelEditor extends StrictEventEmitter<EventEmitter, Glo
set: (key: IPublicTypeEditorValueKey, data: any) => void | Promise<void>;
/**
* keyOrType
*/
onceGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(keyOrType: KeyOrType) => Promise<IPublicTypeEditorGetResult<T, KeyOrType>>;
/**
* keyOrType
*/
onGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
keyOrType: KeyOrType,
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void
) => () => void;
/**
* keyOrType
*/
onChange: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
keyOrType: KeyOrType,
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void
) => () => void;
register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void;
get eventBus(): IPublicApiEvent;