• This repository has been archived on 02/Mar/2021
  • Stars
    star
    1,236
  • Rank 37,991 (Top 0.8 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast, bump-allocated virtual DOM library for Rust and WebAssembly.

Dodrio

A fast, bump-allocated virtual DOM library for Rust and WebAssembly. Note that Dodrio is still experimental.

Warning

I reiterate that Dodrio is in a very experimental state. It probably has bugs, and no one is using it in production.

Examples

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.

Cargo Features

  • 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.

Design

Bump Allocation

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:

  1. The newest, most up-to-date virtual DOM. The virtual DOM nodes themselves and any temporary containers needed while creating them are allocated into this arena.
  2. The previous virtual DOM. This reflects the current state of the physical DOM.
  3. The difference between (1) and (2). This is a sequence of DOM mutation operations β€” colloquially known as a "change list" β€” which if applied to the physical DOM, will make the physical DOM match (1).

Rendering happens as follows:

  1. The application state is rendered into bump allocation arena (1).
  2. (1) is diffed with (2) and the changes are emitted into (3).
  3. JavaScript code applies the change list in (3) to the physical DOM.
  4. (1) and (2) are swapped, double-buffering style, and the new (1) has its bump allocation pointer reset, as does (3).
  5. Rinse and repeat.

Change List as Stack Machine

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.

Library β€” Not Framework

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.

More Repositories

1

bumpalo

A fast bump allocation arena for Rust
Rust
1,018
star
2

wu.js

wu.js is a JavaScript library providing higher order functions for ES6 iterators.
JavaScript
864
star
3

generational-arena

A safe arena allocator that allows deletion without suffering from the ABA problem by using generational indices.
Rust
611
star
4

state_machine_future

Easily create type-safe `Future`s from state machines β€” without the boilerplate.
Rust
322
star
5

github-api

Javascript bindings for the Github API.
JavaScript
170
star
6

glob-to-regexp

Convert a glob to a regular expression
JavaScript
145
star
7

operational-transformation

JavaScript implementation of Operational Transformation
JavaScript
141
star
8

oxischeme

A Scheme implementation, in Rust.
Rust
128
star
9

id-arena

A simple, id-based arena
Rust
88
star
10

bacon-rajan-cc

Rust
86
star
11

mach

A rust interface to the Mach 3.0 kernel that underlies OSX.
Rust
80
star
12

bindgen-tutorial-bzip2-sys

A tutorial/example crate for generating C/C++ bindings on-the-fly with libbindgen
Rust
75
star
13

inlinable_string

An owned, grow-able UTF-8 string that stores small strings inline and avoids heap-allocation.
Rust
69
star
14

intrusive_splay_tree

An intrusive splay tree implementation that is no-std compatible and free from allocation and moves
Rust
65
star
15

synth-loop-free-prog

Synthesis of Loop-free Programs in Rust
Rust
62
star
16

fart

fitzgen's art
Rust
61
star
17

peepmatic

A DSL and compiler for generating peephole optimizers for Cranelift
Rust
59
star
18

scrapmetal

Scrap Your Rust Boilerplate
Rust
55
star
19

operational-transformation-example

Example app using Operational Transformation
JavaScript
51
star
20

wasm-smith

A WebAssembly test case generator
44
star
21

source-map-mappings

Parse the `mappings` field in source maps
Rust
39
star
22

chronos

Avoids JavaScript timer congestion
JavaScript
38
star
23

wasm-nm

List the symbols within a wasm file
Rust
38
star
24

associative-cache

A generic, fixed-size, associative cache
Rust
35
star
25

fast-bernoulli

Efficient sampling with uniform probability
Rust
32
star
26

zoolander

Pure Python DSL for CSS.
Python
28
star
27

django-wysiwyg-forms

WYSIWYG form editor/creator django app
JavaScript
25
star
28

winliner

The WebAssembly Indirect Call Inliner
Rust
25
star
29

minisynth-rs

Program synthesis is possible in Rust
Rust
24
star
30

derive_is_enum_variant

Automatically derives `is_dog` and `is_cat` methods for `enum Pet { Dog, Cat }`.
Rust
22
star
31

tempest

Tempest jQuery Templating Plugin
JavaScript
22
star
32

pfds-js

Purely Functional Data Structures in JS
JavaScript
22
star
33

histo

Histograms with a configurable number of buckets, and a terminal-friendly Display.
Rust
21
star
34

one-page-wasm

Rust
21
star
35

shuffling-allocator

Rust
20
star
36

rpn-js

A reverse polish notation --> JavaScript compiler demoing source maps
JavaScript
19
star
37

bugzilla-todos

Bugzilla todo list of reviews, flag requests, and bugs to fix
JavaScript
19
star
38

dwprod

Rust
16
star
39

tryparenscript.com

The code behind TryParenScript.com
JavaScript
16
star
40

is_executable

Is there an executable file at the given path?
Rust
15
star
41

rent_to_own

A wrapper type for optionally giving up ownership of the underlying value.
Rust
12
star
42

noodles

Asynchronous, non-blocking, continuation-passing-style versions of the common higher order functions in `Array.prototype`.
JavaScript
12
star
43

rust-conf-2019

Flatulence, Crystals, and Happy Little Accidents
JavaScript
11
star
44

life

John Conway's Game of Life (in Erlang)
Erlang
10
star
45

peeking_take_while

Rust
9
star
46

bufrng

An RNG that generates "random" numbers copied from a given buffer
Rust
9
star
47

wasm-summit-2021

Stuff related to my Wasm Summit 2021 talk
Rust
9
star
48

geotoy

Polygons in Contact + Glium
Rust
9
star
49

preduce

A parallel, language agnostic, automatic test case reducer
Rust
8
star
50

erl-ot

Simple example of Operational Transformation in Erlang
Erlang
8
star
51

longest-increasing-subsequence

A crate for finding a longest increasing subsequence of some input
Rust
8
star
52

cl-pattern-matching

Erlang/Haskell style pattern matching macros for Common Lisp.
Common Lisp
7
star
53

parenscript-narwhal

Integrates ParenScript with Narwhal and provides a ParenScript REPL.
JavaScript
7
star
54

reform

A Narwhal module for working with HTML forms, similar to Django's forms.
JavaScript
7
star
55

ada-scheme

Following along with Peter Michaux's Scheme from Scratch series (http://peter.michaux.ca/articles/scheme-from-scratch-introduction) in Ada
6
star
56

wasm-debugging-capabilities

Collecting requirements for WebAssembly debugging capabilities
HTML
6
star
57

couchdb-io

Io library for working with CouchDB (not yet implemented)
Io
5
star
58

cool-rs

Rust
5
star
59

souper-ir

A library for manipulating Souper IR
Rust
4
star
60

canvas-tool

experimental canvas tool; WORK IN PROGRESS
JavaScript
4
star
61

code-size-benchmarks

Rust and WebAssembly code size micro benchmarks
Rust
4
star
62

dodrio-todomvc-wasm-instantiation

Rust
4
star
63

clife

Conway's life, in Rust.
Rust
3
star
64

class_views

Class based views for django
Python
3
star
65

Blimp

A very simple django blogging app for my site. Blog + Simple = Blimp?
Python
2
star
66

mxr

Search the Mozilla Cross Reference from the command line
Python
2
star
67

tokio-timeit-middleware

Rust
2
star
68

tasks

A demo app I used for my presentation on server side JS.
JavaScript
2
star
69

kahn

A build tool for AMD-style Common JS projects
JavaScript
2
star
70

boffo

Boffo
Erlang
2
star
71

pineapple

Not quite sure yet
JavaScript
2
star
72

mach_o_sys

Bindings to the OSX mach-o system library
Rust
2
star
73

dateformat

A port of Steven Levithan's dateFormat to CommonJS.
JavaScript
2
star
74

mcmc-maze-solver

Rust
2
star
75

protolith

Just for exploratory fun, I decided to see what it takes to write a prototypical object system in Lisp.
Common Lisp
2
star
76

strace.js

Trace JS native calls
JavaScript
2
star
77

mini-meta-git

Very simple, lightweight git repository authentication and management (because gitosis just gets in my way).
2
star
78

tron

An online implementation of Tron, but you play with code instead of keys. Built with Wu.js, WebSockets, and Node.
JavaScript
2
star
79

aossoa

A crate providing a macro to abstract and automate SoA vs AoS
Rust
1
star
80

powereddit

Make reddit better.
JavaScript
1
star
81

servo-trace-dump

JS and CSS for Servo's HTML timelines
HTML
1
star
82

reharm

Prolog
1
star
83

pybeasttree

Library for parsing/consuming BEAST tree files
Python
1
star
84

django-query-analyzer

Analyzer of django query
Python
1
star
85

rust-words

Learning Rust. Read words from stdin and then print each unique word out in order and how many times it was found.
Rust
1
star
86

breakpoint-rs

Set breakpoints with the `breakpoint!()` macro.
Rust
1
star
87

ocean-noise

Makes soothing ocean noises.
JavaScript
1
star
88

bender

Create robust user interfaces with finite state machines.
JavaScript
1
star
89

hippocampus

A Lisp dialect targetting JavaScript
JavaScript
1
star
90

magritte

My just-for-fun Lisp in progress
Common Lisp
1
star
91

loader

A smart, parallel client-side Javascript loader written in ParenScript
Common Lisp
1
star
92

learn-your-scales

Flashcard-style webapp for learning musical scales!
JavaScript
1
star
93

music-thang

JavaScript
1
star
94

what-the-ffi-python-example

Rust
1
star
95

bang-bang-con-west-2020

Writing Programs! That Write Other Programs!!
HTML
1
star
96

pancakes

Still a WIP
Rust
1
star
97

reader-submit-to-hn

Greasemonkey script to add a link for submitting articles to Hacker News from Google Reader.
JavaScript
1
star