A library for building reactive web apps.
button().on_click(...)
passes your event handler a web_sys::HtmlInputElement
and a web_sys::MouseEvent
.```rust use futures_signals::signal::{Mutable, SignalExt}; use silkenweb::{elements::html::, prelude::, value::Sig};
fn main() { let count = Mutable::new(0); let counttext = count.signal().map(|i| format!("{}", i)); let inc = move |, | { count.replacewith(|i| *i + 1); };
let app = div()
.child(button().on_click(inc).text("+"))
.child(p().text(Sig(count_text)));
mount("app", app);
}
```
bash
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
cd examples/counter
trunk serve --open
There are potential performance advantages to using a signals based approach, as you're telling the compiler explicitly what the dependencies within your app are, at compile time. With a simple VDOM based approach, you have to figure out what changed at runtime. The tradeoff here is slightly more complex code when using a signals based approach.
What tends to happen in practice is that VDOM based approaches will add some mechanism so that every time someting changes, your app doesn't need to completely re-render the VDOM. This inevitably adds some complexity to VDOM based approaches.
There are many advantages to using plain Rust syntax:
rust-analyser
.rustdoc
.rustfmt
.rustc
.if
, match
, dyn traits
, or whatever else Rust provides.There's nothing to stop a macro DSL being built on top of Silkenweb, to complement the builder APIs.
The advantage of using a macro DSL is that syntax is tailored to defining document structure. Rust syntax is fairly well suited to this, so it's not much of a benefit in reality.
cargo doc --open