-
Notifications
You must be signed in to change notification settings - Fork 325
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
"handle_on" depends on order of components in a form (it should not) #1484
Comments
concerns about |
Maybe it would be better for now to recommend to use on only for buttons. #1480 (reply in thread): Code_B9HpcaWUDu.mp4The only thing that worked for me is to replace on with my own set of decorators, namely: @app("/")
async def serve(q: Q) -> None:
if q.client.toggle_01 is None:
q.client.toggle_01 = False
if q.client.toggle_02 is None:
q.client.toggle_02 = False
await handle_changes(q, compared_to=q.client)
print(f"q.args : {q.args}")
print(f"on_change.handlers: {on_change.handlers}")
await setup_page(q)
await q.page.save()
@on_change("toggle_{id}")
async def toggle_handler(q: Q, val, id):
print(f"toggle_{id} changed, new val: {val}")
q.client[f"toggle_{id}"] = val
async def setup_page(q: Q):
q.page["example"] = ui.form_card(
box="1 1 2 2",
items=[
ui.toggle(name="toggle_01", value=q.client.toggle_01, trigger=True),
ui.toggle(name="toggle_02", value=q.client.toggle_02, trigger=True),
],
) |
@lo5 wouldn't the following be an option: I believe currently q.events is only used for wave.emit() stuff. What if it would always hold the "source event" that led to invoking serve? For example: Let's say we have an ui.toggle with trigger = True and we "click" it. Let's further assume the value changes from
That would enable a quite convenient usecase for @on in my opinion: @on("toggle.triggered")
def toggle_handler(q: Q):
... edit: q.events = {"button.clicked": True}
q.args = {"button" : True} For sake of backwards compatibility we can't remove it from q.args. So the redundancy could be an argument against it. But I feel one could still argue, that q.events holds the implicit "trigger = True" for the button and q.args it's value. So non-clicks could still be this, I guess: q.events = {}
q.args = {"button" : False} |
@Far0n - I really like your suggestion. It's backwards-compatible, too. Seems obvious in hindsight :) |
This might be the |
Extra note: I also think button clicks should find their way into q.events, like so: q.events = {"button.clicked": True}
q.args = {"button" : True} For sake of backwards compatibility we can't remove it from q.args. So the redundancy could be an argument against it. But I feel one could still argue, that q.events holds the implicit "trigger = True" for the button and q.args its value. So non-clicks could still be this, I guess: q.events = {}
q.args = {"button" : False} |
@Far0n : Could you share the code you used in +1 for including these handlers in the main branch for dealing with triggered events...or the |
@pshafer-als our wave extensions are here: https://github.com/h2oai/model-validation/blob/master/mv/ui/wave/_routing_ex.py |
@Far0n : Thanks! It looks like I don't have access to that repo. If ok, could you please add me to viewers? |
ahh sorry, its h2o internal only. |
I could create a little demo an put it into discussions. That's maybe a good place to check if others might find it helpful. |
That would be great. Thank you! |
I like @Far0n 's suggestion and would like to expand on it. I suggest deprecating the current This way, the callbacks would fire "on changed" rather than "on found" wrt The migration would be relatively painless: just import Needs discussion: @Far0n 's proposal suggest adding
Disclaimer: I still fully agree with @lo5 that the best solution is the one that is tailored for the given use case with no extra framework magic to understand what's going on. Will build the proposal in a separate branch for you folks to try out and get feedback. |
It gets a bit tricky currently to identify the root cause of a serve invokation if there are several components with So the typical use case is to trigger the "@on" associated to the root cause instead of what is is found in |
Correct. This complexity will be hidden from regular wave app devs. I just asked to make sure you do not need to differentiate between |
Yes, that's what I believe to remember at least :D (back when I thought about it .. so take it with a grain of salt ^^) edit: so yeah I think these 2 things: a) root cause b) solution for the "is not truthy" issue with current (handle_on, @on). And a proper solution to a) should also solve b) I guess. |
@mturoci but if I think about it: wouldn't it be in general benefical of have the "root cause" accessible in q.events? So that we can make use of it in apps, that don't use [new]_handle_on? |
I currently expose the name of the cause in |
Looking for feedback in #2113 whoever is interested. |
See discussion: #1480 (reply in thread)
Solution: Add a
sort_args=False
tohandle_on
. If set to True, sortq.args
before iterating.The text was updated successfully, but these errors were encountered: