Skip to content
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

How to unbind an event? #360

Open
xland opened this issue May 22, 2024 · 6 comments
Open

How to unbind an event? #360

xland opened this issue May 22, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@xland
Copy link
Contributor

xland commented May 22, 2024

When I bind a callback method using webui_bind,
How do I unbind it?

I know that webui_bind returns a unique bind ID.
But what is the use of this ID?
Isn't it used to unbind?

@fibodevy
Copy link
Collaborator

You cant unbind it, but you can "ignore" events for specific IDs in your app

@AlbertShown
Copy link
Contributor

How do I unbind it?

The webui.js get generated at runtime based on your bind elements, and you can not unbind it. But, as @fibodevy said, you can easily ignore it in your back-end app.

what is the use of this ID?

Many wrappers has an internal table to map events with back-end functions, like Python wrapper, those wrappers use those IDs to identify the back-end function. So, you can save the IDs if you want and ignore their events later when you need, or use .element to get the bind name (element name) instead of ID, whatever you prefer.

@ttytm
Copy link
Member

ttytm commented May 22, 2024

Yes, as you mention @xland, the call to webui_bind returns the ID. It is used e.g. to identify a function in an event. This would also allow to conditionally ignore the bound function when a state is reached where it is necessary, so you can store the ID and keep it in the relevant context.

Maybe you can share an example use-case for unbinding, then things can be further concertized.

@ttytm
Copy link
Member

ttytm commented May 27, 2024

Regarding providing an example. An API for unbinding could be provided theoretically. So if there is a good use-case maybe its gonna be added.

@xland
Copy link
Contributor Author

xland commented May 28, 2024

I didn't delve into the webui code.
So I'm not sure if it's necessary to add the webui_unbind API.

Let's say I'm going to keep creating btn in HTML : <button id='btn_n'>btn_n</button>.
And keep binding events to those buttons : webui_bind(winId, "btn_n", same_function);
Then keep removing the previously created Button : document.getElementById("btn_n").remove();

This could be what happens when the user switches between tab pages.
btn_1 may be repeatedly bound to an event.
btn_999999... may be bound to an event.

Does this cause OOM exception?

@hassandraga
Copy link
Member

A propre unbind will be removing the ID from the core's table, and from webui.js as well, new internal cmd is needed, and a new API. Need time to implement, but good to have.

Thank you @xland for the suggestion.

@hassandraga hassandraga added the enhancement New feature or request label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants