linebender / xilem

An experimental Rust native UI framework
Apache License 2.0
3.14k stars 92 forks source link

Port `Adapt` from old `xilem_core` #401

Closed Philipp-M closed 1 week ago

Philipp-M commented 2 weeks ago

Ports Adapt to new xilem_core. It also adds MapState which was previously called AdaptState and a new view MapAction which is basically about how elm works. MapAction and Adapt is shown in action in the added elm example, while MapState can be seen in action in the added components example.

Philipp-M commented 2 weeks ago

IMO, we need at least one instantion somewhere, whether in an example or in a test.

Yeah an example is certainly worth it, also because I don't think it's the easiest thing to grasp for newcomers. I guess I can add one for xilem itself? Or should that be in xilem_core?

DJMcNab commented 2 weeks ago

I think it would be good to have an example for Xilem itself.

I'd probably call it something like elm? Because really that's us emulating the elm architecture

jaredoconnell commented 2 weeks ago

Is it possible for you to add a runnable example at this stage? It'd help with testing.

Philipp-M commented 1 week ago

One thing I would say is that emulating the elm architecture is not necessarily the most idiomatic approach to using Xilem

Certainly not, though I could think that in an async context this could be useful, but that's a different story that needs more research.

I think we should explain that, but also explain that it is possible.

Probably (and I've added a comment at the top of that example). But on the other hand I don't think people will stumble over it and say "this is the better approach to handle state/messages in xilem" ^^. You likely need a good use-case for this.

Btw. does the name elm for the example still make sense? As there's also e.g. map_state in there.

DJMcNab commented 1 week ago

I'd consider splitting into two examples: components and elm.

But I'm worried that components might be a very small example. Maybe we can just stick it onto to_do_mvc?

Philipp-M commented 1 week ago

Maybe we can just stick it onto to_do_mvc

Hmm I'm not sure where it would fit best without complicating things, an adapt similar as in the xilem_web todomvc (i.e. send a message to the parent view, that the task can be deleted) would probably make more sense there. Or do you mean using adapt there instead of map_state?

Philipp-M commented 1 week ago

But I'm worried that components might be a very small example.

I don't think that's a bad thing, focus on one thing. A user can quickly see what it is about. I guess I'll do that components example instead, and leave adapt and map_action in the elm example