Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddEventListener does not work for multiple events of the same name #2161

Closed
filipzeta opened this issue Sep 1, 2022 · 1 comment
Closed

Comments

@filipzeta
Copy link
Contributor

If subscribing to an event using addEventListener in event.ts, this._eventListeners does not correctly concatenate if listening to multiple events with the same name. Therefore only the final listener will fire.

This is an issue if subscribing to the same event name multiple times in one script. We can see this by adding extra logging:

...
Add event listener, eventName= TradeEvent
...
Add event listener, eventName= OrderCompleteEvent
...
Add event listener, eventName= TradeEvent
this._eventListeners before: Map(2) { 'TradeEvent' => [ 0 ], 'OrderCompleteEvent' => [ 1 ] }
this._eventCallbacks before: Map(2) {
  0 => [ 'TradeEvent', [Function (anonymous)] ],
  1 => [ 'OrderCompleteEvent', [Function (anonymous)] ]
}
this._eventListeners after: Map(2) { 'TradeEvent' => [ 2 ], 'OrderCompleteEvent' => [ 1 ] }
this._eventCallbacks after: Map(3) {
  0 => [ 'TradeEvent', [Function (anonymous)] ],
  1 => [ 'OrderCompleteEvent', [Function (anonymous)] ],
  2 => [ 'TradeEvent', [Function (anonymous)] ]
}
...

this._eventListeners after adding should contain 'TradeEvent' => [ 0, 2 ], but instead is only 'TradeEvent' => [ 2 ]

I'm fixing this bug, but also wanted to open an issue to document it 😊

@Henry-E
Copy link

Henry-E commented Dec 7, 2022

Looks like this got merged, congrats!

@Henry-E Henry-E closed this as completed Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants