简体   繁体   中英

Aurelia: EventAggregator fires twice

The function called by the subscription function triggers twice.

The publisher is not being used in an activate or attached function, but in an async function of a different class. Both classes recieve the same EventAggregator through binding. Console.Trace() has the same routes in both cases. The Publish/Subscribe set is unique and not used by any other classes.

 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 } ); }

The Custom Element which contained the custom Element with the Subscription has been used twice, which caused the issue. This was not an EventAggregator issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM