Skip to content

Commit c458b1b

Browse files
liujupingJackLian
authored andcommitted
fix(material): when the assets exist, use onChangeAssets api, the callback is called immediately
1 parent 0eeee1f commit c458b1b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

packages/editor-core/src/editor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ export class Editor extends EventEmitter implements IEditor {
222222
};
223223
}
224224

225+
onChange<T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
226+
keyOrType: KeyOrType,
227+
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void,
228+
): () => void {
229+
this.setWait(keyOrType, fn);
230+
return () => {
231+
this.delWait(keyOrType, fn);
232+
};
233+
}
234+
225235
register(data: any, key?: IPublicTypeEditorValueKey): void {
226236
this.context.set(key || data, data);
227237
this.notifyGot(key || data);

packages/shell/src/api/material.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class Material implements IPublicApiMaterial {
181181
onChangeAssets(fn: () => void): IPublicTypeDisposable {
182182
const dispose = [
183183
// 设置 assets,经过 setAssets 赋值
184-
this[editorSymbol].onGot('assets', fn),
184+
this[editorSymbol].onChange('assets', fn),
185185
// 增量设置 assets,经过 loadIncrementalAssets 赋值
186186
this[editorSymbol].eventBus.on('designer.incrementalAssetsReady', fn),
187187
];

packages/types/src/shell/model/editor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,27 @@ export interface IPublicModelEditor extends StrictEventEmitter<EventEmitter, Glo
1515

1616
set: (key: IPublicTypeEditorValueKey, data: any) => void | Promise<void>;
1717

18+
/**
19+
* 获取 keyOrType 一次
20+
*/
1821
onceGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(keyOrType: KeyOrType) => Promise<IPublicTypeEditorGetResult<T, KeyOrType>>;
1922

23+
/**
24+
* 获取 keyOrType 多次
25+
*/
2026
onGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
2127
keyOrType: KeyOrType,
2228
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void
2329
) => () => void;
2430

31+
/**
32+
* 监听 keyOrType 变化
33+
*/
34+
onChange: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
35+
keyOrType: KeyOrType,
36+
fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void
37+
) => () => void;
38+
2539
register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void;
2640

2741
get eventBus(): IPublicApiEvent;

0 commit comments

Comments
 (0)