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

View-level Message type in Widget #39

Closed
raphlinus opened this issue Jan 21, 2023 · 2 comments
Closed

View-level Message type in Widget #39

raphlinus opened this issue Jan 21, 2023 · 2 comments

Comments

@raphlinus
Copy link
Contributor

One thing that came up in the review of #26 is that the Widget trait now depends on Message, which is conceptually at the Xilem level. That's arguably a layering violation, and may make life more difficult for other possible reactive layers on top of the widget set.

The most flexible thing to do would be to make the Widget trait generic on the message type, but that would add a lot of type noise. The Message type is perhaps an acceptable type to bring into the widget layer, as it's basically just a Vec<Id> and a Box<dyn Any>.

Part of the reason I'm writing this issue is to get feedback about other potential uses of the widget layer. Is just having widgets produce Message good enough, or do we really need the type to be more flexible? Accommodating other reactive layers than Xilem feels a bit YAGNI right now, and perhaps we want to do a more careful review of layering if and when we get to that point.

@dhardy
Copy link
Contributor

dhardy commented Mar 13, 2023

Sending a Box<dyn Any + Send> seems sensible. Adding a bound on Debug could be useful; unfortunately the only way I found of using this is sending the Box<dyn Any> alongside the pre-formatted debug repr.

Usually a message will only be sent to the corresponding View item (e.g. when a button widget is clicked), thus cx.add_message might be generic over M: Any + Debug + Send, and internally construct a Message with id_path resolved from the context (unfortunately a Cx does not currently contain the IdPath but only the Id).

Another possible application would be sending a message to a parent of the corresponding View item (for example, a Button contains a LabelWithShortcut which is activated on some key-press, and should trigger the button). This could be achieved by adapting View::model:

  • Return MessageResult::Unused(message) by default
  • While unwinding, if the result is Unused(..), try handling that message locally
    This is roughly KAS's current model for messages and I feel like it works well (but with the message routing logic provided; widgets only implement handle_message which does not expose the message path).

@DJMcNab
Copy link
Contributor

DJMcNab commented Jun 4, 2024

Since #205 (and especially #290), this is no longer true - the association between id paths and WidgetId is now stored in the ViewCtx.

I think the situation is slightly different for web, but I think since an analysis for xilem_web isn't provided here, we can close this

@DJMcNab DJMcNab closed this as completed Jun 4, 2024
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

3 participants