Aurelia:EventAggregator发射两次



订阅函数调用的函数会触发两次。

发布者不是在激活或附加的函数中使用,而是在不同类的异步函数中使用。两个类都通过绑定接收相同的EventAggregator。Console.Trace((在这两种情况下都有相同的路由。"发布/订阅"集是唯一的,不被任何其他类使用。

async sender(item:any):Promise<void> {
this.dialogService.open({
viewModel: CaModalConfirm,
model: {
color:   this.color
}
}).whenClosed(async response => {
if (response.wasCancelled === false) {
this.moduleName = params.params.moduleId;
await this.selectionEventAggregator.publish('requestSelection',{item: item});
this.elementEventAggregator.publish('hideSidebar');
}
});
}
---------------------------------------------
attached() {
this.subscriptions.push(
this.selectionEventAggregator.subscribe(
'requestSelection',
params => this.sendSelection(params)
)
);
}

sendSelection(params):void {
console.trace(params);
this.selectionEventAggregator.publish(
'sendSelected',
{
selection:  this.itemSelection,
item:      params.item
}
);
}

包含订阅的自定义元素的自定义元素已被使用两次,这导致了问题。这不是EventAggregator问题。

最新更新