Crates.io | dodrio |
lib.rs | dodrio |
version | 0.2.0 |
source | src |
created_at | 2019-03-13 18:52:41.226794 |
updated_at | 2020-05-08 22:23:21.131037 |
description | A fast, bump-allocated virtual DOM library. |
homepage | |
repository | https://github.com/fitzgen/dodrio |
max_upload_size | |
id | 120495 |
size | 243,836 |
A fast, bump-allocated virtual DOM library for Rust and WebAssembly. Note that Dodrio is still experimental.
I reiterate that Dodrio is in a very experimental state. It probably has bugs, and no one is using it in production.
Here is the classic "Hello, World!" example:
struct Hello {
who: String,
}
impl Render for Hello {
fn render<'a>(&self, cx: &mut RenderContext<a>) -> Node<'a> {
let who = bumpalo::format!(in cx.bump, "Hello, {}!", self.who);
div(cx)
.children([text(who.into_bump_str())])
.finish()
}
}
More examples can be found in the examples
directory, including:
counter
:
Incrementing and decrementing a counter.input-form
:
Reading an <input>
and displaying its contents.todomvc
:
An implementation of the infamous TodoMVC application.moire
: The
WebRender Moiré patterns demo.game-of-life
:
The Rust and WebAssembly book's Game of Life tutorial rendered with Dodrio
instead of to 2D canvas.js-component
:
Defines a rendering component in JavaScript with the dodrio-js-api
crate.log
— enable debugging-oriented log messages with the log
crate's
facade. You still have to initialize a logger for the messages to go anywhere,
such as console_log
.
serde
— enable serde::{Serialize, Deserialize}
implementations for
Cached<R>
where R
is serializable and deserializable.
Bump allocation is essentially the fastest method of allocating objects. It has constraints, but works particularly well when allocation lifetimes match program phases. And virtual DOMs are very phase oriented.
Dodrio maintains three bump allocation arenas:
Rendering happens as follows:
The change list that represents the difference between how the physical DOM currently looks, and our ideal virtual DOM state is encoded in a tiny stack machine language. A stack machine works particularly well for applying DOM diffs, a task that is essentially a tree traversal.
Dodrio is just a library. (And did I mention it is experimental?!) It is not a full-fledged, complete, batteries-included solution for all frontend Web development. And it never intends to become that either.