There is a framework that allows using Rust to write web frontends (it builds on stdweb, compiles to asm.js & WebAssembly).
I’ve been using it for a project in my spare time (after using Halogen at my job for a while)…
Unfortunately, yew is not as nice to use as Halogen, in several ways:
- one can’t do async stuff (like ajax) “inline” in a Component’s
updatemethod (the equivalent of
evalin Halogen). Instead it requires adding a new variant to the
Msgis similar to
Queryin Halogen) and splitting the code up (like in Elm) to handle the result in another case handler.
- querying child components is VERY cumbersome (especially when the child should return a value from the query) and can’t be done without changing the parent’s state, passing properties to the child and causing the parent’s DOM to be re-rendered (to actually pass the properties down). For letting the child respond, it requires passing a closure (which sends a
Msg) down to it, as a property, that it calls with the response value. All this makes it very verbose and requires adding a lot of state to the parent component’s Model struct, that wouldn’t be required in Halogen.
I described this issue in more detail here: https://github.com/DenisKolodin/yew/issues/350
I’d be very interested if you have any ideas how to use Rust’s type system better to get Halogen-like / type-safe querying of child components (incl. queries with return value from child to parent) without forcing the parent’s DOM to re-render and without having to add state to the parent component’s Model struct.
And to be able to do the querying by (something like a type-safe) SlotID instead of having to pass everything through properties. So my questions are:
Do you have any ideas how Rust’s type system can be used in a better way to get Halogen-like levels of type-safe convenience for querying child components (incl. queries with return values) in yew?
frunkcrate provides a Coproduct,. Do we also need
Which type system features (that Rust doesn’t have yet) would be necessary to be able to port Halogen completely to Rust (without the async-inline requirement for now)? (separate from the yew project)
(The async-inline-ability is a separate/orthogonal concern. Rust doesn’t have HKTs (yet), so no monads, but it has futures (and async/await syntax soon (currently with the mdo crate) and generic associated types in traits).)
(Sorry for breaking the links, I couldn’t submit without it: “Sorry, new users can only put 2 links in a post.”)