[][src]Crate dodrio

The dodrio virtual DOM.

Example

use dodrio::{bumpalo::Bump, Attribute, Node, Render};
use wasm_bindgen::UnwrapThrowExt;

/// A component that greets someone.
pub struct Hello<'who> {
    who: &'who str,
}

impl<'who> Hello<'who> {
    /// Construct a new `Hello` component that greets the given `who`.
    pub fn new(who: &str) -> Hello {
        Hello { who }
    }
}

impl<'who> Render for Hello<'who> {
    fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
    where
        'a: 'bump,
    {
        use dodrio::builder::*;

        let id = bumpalo::format!(in bump, "hello-{}", self.who);

        div(bump)
           .attr("id", id.into_bump_str())
           .on("click", |root, _vdom, _event| {
                let hello = root.unwrap_mut::<Hello>();
                web_sys::window()
                    .expect_throw("should have a `Window` on the Web")
                    .alert_with_message(hello.who);
            })
            .children([
                text("Hello, "),
                strong(bump)
                    .children([
                        text(self.who),
                        text("!"),
                    ])
                    .finish(),
            ])
            .finish()
    }
}

Re-exports

pub use bumpalo;

Modules

builder

Helpers for building virtual DOM nodes.

Structs

Attribute

An attribute on a DOM node, such as id="my-thing" or href="https://example.com".

Cached

A renderable that supports caching for when rendering is expensive but can generate the same DOM tree.

ElementNode

Elements have a tag name, zero or more attributes, and zero or more children.

Listener

An event listener.

TextNode

Text nodes are just a string of text. They cannot have attributes or children.

Vdom

A strong handle to a mounted virtual DOM.

VdomWeak

A weak handle to a virtual DOM.

Enums

Node

A node is either a text node or an element.

Traits

Render

A trait for any component that can be rendered to HTML.

RootRender

A RootRender is a render component that can be the root rendering component mounted to a virtual DOM.

Type Definitions

ListenerCallback

An event listener callback function.