Window addEventListener

Hi All,

When I add a handler to an event in the window it keeps getting added every time the playground is run. You can see that in this playground every time you run it the console logs incremented number of times on single event.

Originally I was testing gamepad but works with any like in this case mouseclick (anywhere on code panel)

Probably something is stored in cache I guess. I feel like its a noob question. Any ideas to get around this?

You can add an observable to the scene dispose and call removeEventListener there: EventTarget: removeEventListener() method - Web APIs | MDN (mozilla.org) :slight_smile:

2 Likes

Thanks, it works I think.