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

Comparison With Other Frameworks

[Sycamore] and [Leptos] are 2 other signals based Rust frameworks. They are evolving quickly at the time of writing this comparison, as is [Silkenweb]. Also bear in mind I'm not that familiar with [Sycamore] or [Leptos].

Design Tradeoffs

No VDOM

The use of a signals-based approach can provide better performance because it allows the compiler to know the data dependencies within your application at compile time. This allows changes to be efficiently calculated at runtime. On the other hand, with a basic VDOM based approach, the changes need to be identified at runtime.

The drawback of a signals-based approach is that the code tends to be more complicated. However, in actual implementation, VDOM-based approaches often implement mechanisms to prevent complete re-rendering of the VDOM every time a change occurs, which adds some level of complexity to code using the VDOM approach.

No Macro DSL

Using plain Rust syntax has numerous benefits, such as:

While a macro DSL could be developed to work with Silkenweb, the syntax in Rust is already well suited for defining document structure.

Learning

Pre Built Examples