Replies: 3 comments 8 replies
-
Just for the sake of context and to provide a more helpful response: How much Rust UI code have you written/using which frameworks? |
Beta Was this translation helpful? Give feedback.
-
The short version: non- The medium version: Creating something like an event listener in the DOM requires that the function you use as an event listener be This should hopefully sense because of the way a Rust UI runs, especially when it is building on top of another retained-mode UI toolkit like the DOM. Running something like a
After 3, the only things that still exist are those things that have passed ownership into JS, in one way or another: references created anywhere in the call stack can't outlive As a result it's pretty straightforwardly true that either A) is the typical path in Rust UI frameworks. There is actually an approach C (see Iced, Sauron) in which things like event listeners do not have any access to state at all, but just return a message type. This is elegant, verbose, and hides a huge amount of VDOM overhead from users; it feels good to say "yes I have a The long version: So, pretty much all Rust UI frameworks use To compare the same simple example in Yew and Leptos. Yew: let state = use_state(|| 0);
let incr_counter = {
let state = state.clone();
Callback::from(move |_| state.set(*state + 1))
};
html! {
<button onclick={incr_counter}> {*state} </button>
} Leptos: let state = RwSignal::new(0);
let incr_counter = move |_| state.update(|n| *n += 1);
view! {
<button on:click={incr_counter}> {*state} </button>
} The difference here is simply a matter of whether you need to clone into the closure or not. This is not a big deal for a one-line example but is genuinely painful in the case of larger applications, nested components, etc. (For more on the clone into closure pattern, see here.) What Leptos does is simply to use an arena to allocate signals per reactive owner, and give you a It's not clear to me whether you say it's "inefficient" because of a misunderstanding of how/when signals are disposed, or whether you're just being hardcore and the overhead of the arena seems bad to you. |
Beta Was this translation helpful? Give feedback.
-
Another option is to spawn a future with |
Beta Was this translation helpful? Give feedback.
-
I'm confused about why Leptos considers 'static signals an innovation; to me, it looks very inefficient and poorly thought out. Is there any work going on to explore more efficient reactivity concepts, such as by building on top of qcell::LCell and bumpalo
Beta Was this translation helpful? Give feedback.
All reactions