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.

Add a way of clearing the event listeners array and remove by ID

See original GitHub issue

Feature request

  1. Add a method to remove every event listener on the timer (eg. myTimer.clearEventListeners())
  2. removeEventListener works by using indexOf() with a function, which can be unusable if using generated arrow functions. This could be solved by allowing an optional id to be passed along on addEventListener, which can later be used to identify the listener to be removed (eg. myTimer.removeEventListenerByID('secondsUpdated', 'myListener1')). If two listeners are added with the same id, the second should override the first

Looking at the code changes needed for this it don’t look like they should be too big. I may have some time to submit a PR if you need contribution

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JRebellacommented, Aug 12, 2021

Hi!

I have just published the version 4.5.0 with your removeAllEventListeners method.

Thanks a lot for your contribution 😃.

Awesome, glad to be of help, thank you for the awesome library!

1reaction
albert-gonzalezcommented, Aug 12, 2021

Hi!

I have just published the version 4.5.0 with your removeAllEventListeners method.

Thanks a lot for your contribution 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove all event listeners of a DOM object?
Another way to remove the event (which will also remove all the events) is to remove the node and create a new one,...
Read more >
EventTarget.removeEventListener() - Web APIs | MDN
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.
Read more >
JavaScript removeEventListener() method with examples
The Javascript removeEventListener() is an inbuilt function that is used to remove removes an event handler that was previously added using ...
Read more >
Remove an Event Handler - JavaScript Tutorial
This tutorial shows you how to use the removeEventListener() method to remove an event handler from an event of an element.
Read more >
Removing event listeners through an identifier #208 - GitHub
An alternative to overloading obj.removeEventListener() would be adding something like obj.removeEventListenerClass("clicker") , but that seems ...
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