mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
fix: project event listeners will not be invoked sometimes
This commit is contained in:
parent
12f67dcdeb
commit
a0c772fb90
@ -136,41 +136,40 @@ export default class Project {
|
||||
* 当前 project 内的 document 变更事件
|
||||
*/
|
||||
onChangeDocument(fn: (doc: DocumentModel) => void) {
|
||||
if (this[projectSymbol].currentDocument) {
|
||||
fn(DocumentModel.create(this[projectSymbol].currentDocument)!);
|
||||
return () => {};
|
||||
}
|
||||
return this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
|
||||
const offFn = this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
|
||||
fn(DocumentModel.create(originalDoc)!);
|
||||
});
|
||||
if (this[projectSymbol].currentDocument) {
|
||||
fn(DocumentModel.create(this[projectSymbol].currentDocument)!);
|
||||
}
|
||||
return offFn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前 project 的模拟器 ready 事件
|
||||
*/
|
||||
onSimulatorHostReady(fn: (host: SimulatorHost) => void) {
|
||||
if (this[simulatorHostSymbol]) {
|
||||
fn(SimulatorHost.create(this[simulatorHostSymbol])!);
|
||||
return () => {};
|
||||
}
|
||||
return this[projectSymbol].onSimulatorReady((simulator: BuiltinSimulatorHost) => {
|
||||
const offFn = this[projectSymbol].onSimulatorReady((simulator: BuiltinSimulatorHost) => {
|
||||
this[simulatorHostSymbol] = simulator;
|
||||
fn(SimulatorHost.create(simulator)!);
|
||||
});
|
||||
if (this[simulatorHostSymbol]) {
|
||||
fn(SimulatorHost.create(this[simulatorHostSymbol])!);
|
||||
}
|
||||
return offFn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前 project 的渲染器 ready 事件
|
||||
*/
|
||||
onSimulatorRendererReady(fn: () => void) {
|
||||
if (this[simulatorRendererSymbol]) {
|
||||
fn();
|
||||
return () => {};
|
||||
}
|
||||
// TODO: 补充 renderer 实例
|
||||
return this[projectSymbol].onRendererReady((renderer: any) => {
|
||||
const offFn = this[projectSymbol].onRendererReady((renderer: any) => {
|
||||
this[simulatorRendererSymbol] = renderer;
|
||||
fn();
|
||||
});
|
||||
if (this[simulatorRendererSymbol]) {
|
||||
fn();
|
||||
}
|
||||
return offFn;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user