Remove the event listeners
See original GitHub issueThere 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:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Forgot to push the changes after publishing. I’ll close it. Thanks for the feedback!