-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to remove all event listeners #2531
Comments
I'm not an ionic programmer - I just do JS. But maybe I can help out. Is the target of your event an EventTarget from the JavaScript Web API? If so, you can extend EventTarget, overriding the addEventListener and removeEventListener methods to maintain a data structure containing handler function references as they are added and removed. I follow this approach in the Gist below, where I also have a few unit tests. You can run the tests in the browser JS console by copying the code from the Gist to your clipboard, pasting it into the browser JS console, and pressing enter. Please read strange JS from the internet before running it in your JS browser console. Fork and make a pull request if you think you made improvements. https://gist.github.com/angstyloop/504414aba95b61b98be0db580cb2a3b0 Hope this helped at all |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out. |
Im using live reload and the js layer is setting up a plugin event listener on every reload.
Unfortunately as the native layer is not reloading the listeners are multiplying on every reload and I can see in the logs that they are all firing events, even though only the newest one is hitting the reloaded js code.
As the js code has reloaded I no longer have a reference to the listeners and so can't remove them.
There also doesn't seem to be a way of detecting before the js code reloads.
So is there a way to remove all listeners from the plugin, I'm assuming what im seeing in the logs is the plugin / bridge firing an event for each listener that was setup
The text was updated successfully, but these errors were encountered: