uiBuilder Question on eventListeners

So, not a specific Node-RED but relevant to uiBuilder

Most addEventListener examples use an anonymous handler (i.e. (event) => {}) but of course this makes it very difficult to remove (I tried abort() but couldn't get it to work) so I have been using handler functions which increases the code.

So the question is - how does uiBuilder handle removing eventListeners, do I even need to worry about removing them?

Well, UIBUILDER is only for Node-RED so perfectly valid in the forum. :slight_smile:

Great question.

I think the thing to remember is the context. In the browser context, the page itself is fully reset if you reload so no need to cancel event handlers if they are global to the page and not dynamically removable.

The uibuilder client itself will unload its event handlers if there is a chance it might need to reset.

So the short answer is - if you might want to dynamically remove/re-add an element and you are adding an event handler to it, then yes, you should use a pre-defined function for the handler and should remove it appropriately.

But if you aren't ever removing elements dynamically from your page, you don't need to worry about it.