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

Add Widget::Action associated type #664

Open
PoignardAzur opened this issue Oct 9, 2024 · 4 comments
Open

Add Widget::Action associated type #664

PoignardAzur opened this issue Oct 9, 2024 · 4 comments

Comments

@PoignardAzur
Copy link
Contributor

During various passes, widgets that want to signal a semantically meaningful event from the UI (eg a button that was clicked) can emit actions.

Actions are a centralized queue of messages intended for the root application, mostly for the app driver (eg Xilem) to handle. They are inspired by Facebook's Flux architecture.

Actions are currently under-designed. Right now, they only store the emitter's id, plus a payload among a small set of types with Box<dyn Any> as a wildcard. Ideally, we'd want a way to connect the type of an action from the widget that sent it, so that each widget would have an associated action type. This associated type would only exist for sized Widgets so that the trait remains dyn-safe.

@DJMcNab
Copy link
Member

DJMcNab commented Oct 17, 2024

To clarify, this would mean that the action type is always downcasted? That seems reasonable to me.

I think Xilem would be able to make use of this for a slight ease-of-use improvement.

@PoignardAzur
Copy link
Contributor Author

To clarify, this would mean that the action type is always downcasted?

Basically yes.

@test3211234
Copy link

test3211234 commented Nov 10, 2024

This idea seemed great to me at first, but I'm not sure I really see how/why it would be used. Actions would still be Box<dyn Any> so that they can be stored in the central queue, so Widgets would just pass in whatever their event is to submit_action like normal. I don't see why the associated type exists, no method would use it. Or would they? I'm also curious why Daniel says this could make stuff easier in Xilem.

@Philipp-M
Copy link
Contributor

I'm also curious why Daniel says this could make stuff easier in Xilem.

I think it's because View::message basically already receives a message: Box<dyn Any> which may just be casted down to View::Element::Action, it's "just" type information what the action may be for the relevant widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants