簡體   English   中英

Aurelia:EventAggregator 觸發兩次

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM