3 ms·
Would there be an easy/straightforward way to put a jsx transpiler in front of the rust compilation step, potentially with hot reloading? I realize that jsx in
by Octoth0rpe 7y ago
Would there be an easy/straightforward way to put a jsx transpiler in front of the rust compilation step, potentially with hot reloading?
I realize that jsx in react is really just calls react.createElement, but I do think it's a very useful abstraction when you're ultimately constructing html.
- rimunroe 7y agoSince Rust supports macros, I think you can actually implement most of JSX's syntax in it directly without needing an additional compiler.
- steveklabnik 7y agohttps://crates.io/crates/typed-html https://crates.io/crates/typed-html
- mdtusz 7y agoLook into the framework Yew. It sits somewhere between elm and react in how it's designed, and makes use of an html macro that allows for jsx-like markup.
- rbalicki 7y agoThe main issue is that jsx can contain both mutable references to a variable and immutable references. For example <div onClick={() => count = count + 1}>{count}</div> contains both a mutable reference to count and an immutable reference. Thus, the naive way of storing this in a single struct will fail. The use of the elm architecture (where the onClick handler returns a message, instead of directly updating count) side steps the complicated borrow-checker issues. It is certainly possible to get around this with the proper procedural macro, but it is not easy, and will never be as "magic-free" as people want.