[英]Aurelia: EventAggregator fires twice
订阅函数调用的函数触发两次。
发布者不是在激活或附加函数中使用,而是在不同类的异步函数中使用。 两个类都通过绑定接收相同的 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 问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.