Sketch: An Axum/Bevy inspired component model for Xilem #1070
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is the result of an experiment I started during travel back from RustWeek, thinking about the shortcomings of Xilem's lifecycle/threading model (e.g. #1032, the hacks in #921).
Warning
This work is extremely incomplete.
I'd love to push this work forward, but I don't have anywhere near all the answers for how this will work.
This PR is largely to have something to point towards when discussing this idea.
The current model in Xilem has two distinct phases, the app logic and view "rebuild"/reconciliation. In the theoretical version of the model, the app logic is where all "user code" happens, and produces a pure view tree. However, in practise, the app logic cannot have local state, and so work is deferred to "rebuild" in order to access local state; see e.g.
memoize
. However, rebuild time doesn't have access to the app state.Essentially, the idea in this work is to have a formalisation of the app logic into explicit "components", which both have access to the app state, and to their own local state. Components know how to create a view, which is the true lightweight description of the state of a widget tree.
The true advancement of this model, is that any function which returns a component is itself a component. That child component "works" by running the function, then running the component method on the function's return value. The user generally "actually writes" these components.
Importantly, these component functions can have parameters other than the app state, including e.g. "local" variables, as seen in Bevy.
(This isn't implemented yet, but it's worth noting that I have been in the weeds of the equivalent in Bevy, and understand how it works)
Note that in theory, we could go even further here, and also give the components access to the tree element itself; this would mix app logic and rebuild time directly. This might be the more natural expansion of the Xilem model. I haven't reasoned carefully about how that would look like.
This is likely the direction I'd like this exploration to go in next.
Other notes: