Crates.io | silkenweb |
lib.rs | silkenweb |
version | 0.8.0 |
source | src |
created_at | 2021-04-29 10:58:14.743438 |
updated_at | 2024-05-02 18:15:00.683389 |
description | A library for building web apps |
homepage | https://github.com/silkenweb/silkenweb |
repository | https://github.com/silkenweb/silkenweb |
max_upload_size | |
id | 390986 |
size | 538,901 |
A library for building reactive web apps.
use futures_signals::signal::{Mutable, SignalExt};
use silkenweb::{elements::html::*, prelude::*, value::Sig};
fn main() {
let count = Mutable::new(0);
let count_text = count.signal().map(|i| format!("{i}"));
let inc = move |_, _| {
count.replace_with(|i| *i + 1);
};
let app = div()
.child(button().on_click(inc).text("+"))
.child(p().text(Sig(count_text)));
mount("app", app);
}
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
cd examples/counter
trunk serve --open
The Silkenweb book provides a high level introduction to Silkenweb's main concepts.
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.
cargo-leptos
and Perseus respectively, whereas Silkenweb doesn't have an ecosystem at this point.clone!
macro to make things a little easier, but otherwise doesn't address the problem. I'm not sure what the tradeoffs are for the Sycamore/Leptos approaches. Do they make cleaning up after derived signals harder? Do they mean more complex lifetime annotations? Do contexts need to be passed around everywhere?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.
Using plain Rust syntax has numerous benefits, such as:
rust-analyser
.rustdoc
.rustfmt
. While macro DSLs can be formatted with rustfmt
if designed with care, the syntax is limited by rustfmt
's capabilities.rustc
: Although macro DSLs can produce informative errors, a lot of work has been put into making rustc
error messsages great.While a macro DSL could be developed to work with Silkenweb, the syntax in Rust is already well suited for defining document structure.
cargo doc --open