Dumle

🍬 Rust HTML templating and virtual DOM library
Alternatives To Dumle
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Incremental Dom3,4963711123 days ago10October 29, 201965apache-2.0TypeScript
An in-place DOM diffing library
Hyperhtml2,956143515 months ago232August 11, 202210iscHTML
A Fast & Light Virtual DOM Alternative
Yo Yo1,3134591452 years ago13May 23, 201733JavaScript
A tiny library for building modular UI components using DOM diffing and ES6 tagged template literals
Transparency973
3 years ago48mitJavaScript
Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
T7895346 years ago25November 20, 201611JavaScript
Lightweight virtual DOM templating library
Domvm5971828 months ago48February 01, 20229mitJavaScript
DOM ViewModel - A thin, fast, dependency-free vdom view layer
Blaze510
2484 months ago15October 04, 201625otherJavaScript
:fire: Meteor Blaze is a powerful library for creating live-updating user interfaces
Litedom38823 years ago5November 28, 201913mitJavaScript
A reactive Web Component library to create Custom Element and turns any HTML sections into components
Jadelet378443 months ago10February 02, 20175mitCoffeeScript
Pure and simple clientside templates
Enfocus362
886 years ago27October 05, 201513Clojure
DOM manipulation and templating library for ClojureScript inspired by Enlive.
Alternatives To Dumle
Select To Compare


Alternative Project Comparisons
Readme

dumle

Sweet virtual DOM library for Rust and WebAssembly.

Example

The following example creates a simple counter that can be incremented:

use dumle::{hook::UseState, html, Context};
use wasm_bindgen::{prelude::*, throw_str, UnwrapThrowExt};

#[wasm_bindgen(start)]
pub fn run() {
	// Get the document's `<body>`
	let body = web_sys::window()
		.and_then(|window| window.document())
		.and_then(|document| document.body())
		.unwrap_throw();

	// Render a simple virtual node with a counter
	let vnode = UseState::new(|state: &i32, set_state| {
		html! {
			<div>
				{ state.to_string() }
				<button click=move |_| set_state(&|state: &mut i32| *state += 1),>
					{"Increment"}
				</button>
			</div>
		}
	});

	// Patch the real DOM to match the virtual DOM
	Context::from(body.clone().into()).patch(None, Some(&vnode));

	throw_str("SimulateInfiniteLoop") // Exit with live runtime
}

Design

Dumle aims only to be a virtual DOM library, not a full web application framework. Constructing virtual trees with dumle should add near zero overhead. To accomplish that, zero-sized types with inlining is used. For example, the macro invocation

html! {
	<div>
		<button />
	</div>
	<img />
}

gets turned into Cons(Child(div, button), img) which is a zero-sized type. Thus the compiler can inline the whole reconciliation phase, should it want to. This means that dumle can get by with a simple macro_rules! macro instead of a full blown procedural macro while generating the same code.

While patching the DOM, dumle maintains a cursor pointing at the current DOM node instead of storing mounted DOM nodes in their corresponding virtual nodes. This makes supporting functionality otherwise provided by something like React Fragments trivial, and reduces the memory size of virtual trees at the cost of always having to traverse the DOM tree (which isn't too expensive). Upcoming features to the Rust ecosystem such as specialization and host bindings should improve performance for free.

No attempt is made at diffing similar sub-trees. That means that given

use dumle::{html, Either};
if switch {
	Either::A(html! {<div>{"One"}</div>})
} else {
	Either::B(html! {<div>{"Two"}</div>})
}

toggling switch would remove the <div> and then re-add the new <div>. This should rarely matter.

Popular Dom Projects
Popular Templates Projects
Popular Web User Interface Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Rust
Templating
Dom
Macro
Rust Library
Virtual Dom