2

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
            }
        );
    }
JustynaT
  • 31
  • 3
  • 1
    it's more likely you have multiple subscription on the event, rather than the event fire twice. share some code - we'll try to help. – avrahamcool Feb 20 '20 at 20:09
  • 1
    @avrahamcool i updated with a simplified version of my code. I have run a search over my entire code to make sure there is no double subscription. – JustynaT Feb 21 '20 at 10:14
  • multiple subscription don't always mean that you have written it twice in your code. but rather that you are using it twice for some reason. – avrahamcool Mar 07 '20 at 17:44

1 Answers1

1

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.

JustynaT
  • 31
  • 3