[][src]Crate dodrio

The dodrio virtual DOM.

Example

use dodrio::{bumpalo, Attribute, Node, Render, RenderContext};
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<'a, 'who> Render<'a> for Hello<'who> {
    fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
        use dodrio::builder::*;

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

        div(&cx)
           .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(&cx)
                    .children([
                        text(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.

Listener

An event listener.

Node

A virtual DOM node.

NodeKey

The key for keyed children.

RenderContext

Common context available to all Render implementations.

Vdom

A strong handle to a mounted virtual DOM.

VdomWeak

A weak handle to a virtual DOM.

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

Element

An element node in the physical DOM.