Silkenweb

tests crates.io Documentation MIT/Apache-2 licensed Discord

A library for building reactive web apps.

Features

Example: A Simple Counter

```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);

}

```

Quick Start

bash rustup target add wasm32-unknown-unknown cargo install --locked trunk cd examples/counter trunk serve --open

Design Tradeoffs

No VDOM

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.

No Macro DSL

There are many advantages to using plain Rust syntax:

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.

Learning

Pre Built Examples