question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove the event listeners

See original GitHub issue

There are two global event listeners that wouldn’t be removed properly. One is the PIXI.ticker event in viewport.js and the other is a wheel event that would add to the wheel div or document.body.

Maybe it would be better to remove these two event listeners when the viewport is destroying ?

The use-case is when PIXI canvas is added to those web frameworks like Vue.js, the canvas and variables are removed when the component is destroyed, but the global variables or event listeners would be left behind.

I tried simply calling the following two functions would help releasing the event listeners,

this.ticker.remove(this.tickerFunction);
this.wheelListener.removeEventListener('wheel', this.wheelFunction);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davidfigcommented, Aug 10, 2018

Good suggestion. I added a viewport.removeListeners() with your code to pixi-viewport@3.2.0. It’ll still need to be called manually during cleanup.

0reactions
davidfigcommented, Aug 10, 2018

Forgot to push the changes after publishing. I’ll close it. Thanks for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

EventTarget.removeEventListener() - Web APIs | MDN
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.
Read more >
HTML DOM Element removeEventListener() Method
The removeEventListener() method removes an event handler from an element. Element Methods. The addEventListener() Method. The removeEventListener() Method ...
Read more >
JavaScript: How to Add and Remove Event Listeners
You can remove an event listener using the removeEventListener() method. This method takes the same two arguments: the event type you are ...
Read more >
JavaScript: remove event listener
var myClick = function( click_count ) { var handler = function(event) { click_count++; if(click_count == 50) { // to remove canvas.removeEventListener('click', ...
Read more >
JavaScript removeEventListener() method with examples
event : It is a string that describes the name of the event that has to be removed. · listener: It is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found