feat: removing a single event listener / `Plugin#removeListener`
See original GitHub issueFeature Request
Description
Allow removing listeners on plugins selectively, instead of just removeAllListeners()
.
Platform(s)
Android, iOS, web
Preferred Solution
Add a removeListener(eventName: string, listenerFunc: ListenerCallback)
method to all plugins that support addListener
. The removeListener
method already exists as private API on WebPlugin
.
It expects an eventName
and a stable listenerFunc
reference. If the given pair is not currently registered, it no-ops.
Bonus points for adding { once: boolean }
as an option to addListener
.
Additional Context
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
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 >Removing an anonymous event listener - Stack Overflow
There is no way to cleanly remove an event handler unless you stored a reference to the event handler at creation.
Read more >An in-depth guide to event listeners - Aurelio De Rosa blog
In this article, I'll explain what event listeners are, and how to add and remove them from a web page. I'll show several...
Read more >Java Widget Fundamentals - 1.3 Events and Listeners - InformIT
It is also possible to remove listeners using removeListener(). ... However, for events that are particular to your widget, you will also ...
Read more >Removing Event Listeners - YouTube
When you add event listeners to DOM elements you also open up the possibility of creating a memory leak and adversely affecting memory...
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
Would this existing mechanism meet your needs? (Example In TypeScript)
See “Plugin Events” in: https://capacitorjs.com/docs/plugins/ios https://capacitorjs.com/docs/plugins/android
I am a first-time Capacitor user (not on the dev team). I am currently working on a plugin and happened to see your post while doing some research. Glad I could be helpful. Cheers.