Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c458b1b

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

File tree

Expand file treeCollapse file tree

3 files changed

+25
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-1
lines changed
Open diff view settings
Collapse file

‎packages/editor-core/src/editor.ts‎

Copy file name to clipboardExpand all lines: packages/editor-core/src/editor.ts
+10Lines 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);
Collapse file

‎packages/shell/src/api/material.ts‎

Copy file name to clipboardExpand all lines: packages/shell/src/api/material.ts
+1-1Lines 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
];
Collapse file

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

Copy file name to clipboardExpand all lines: packages/types/src/shell/model/editor.ts
+14Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.