on 00a42e3 help sign in
dodrio/src/lib.rs
75 lines 2.0 kB history raw
1//! The `dodrio` virtual DOM.
2//!
3//! ## Example
4//!
5//! ```no_run
6//! use dodrio::{bumpalo::Bump, Attribute, Node, Render};
7//! use wasm_bindgen::UnwrapThrowExt;
8//!
9//! /// A component that greets someone.
10//! pub struct Hello<'who> {
11//! who: &'who str,
12//! }
13//!
14//! impl<'who> Hello<'who> {
15//! /// Construct a new `Hello` component that greets the given `who`.
16//! pub fn new(who: &str) -> Hello {
17//! Hello { who }
18//! }
19//! }
20//!
21//! impl<'who> Render for Hello<'who> {
22//! fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
23//! where
24//! 'a: 'bump,
25//! {
26//! use dodrio::builder::*;
27//!
28//! let id = bumpalo::format!(in bump, "hello-{}", self.who);
29//!
30//! div(bump)
31//! .attr("id", id.into_bump_str())
32//! .on("click", |root, _vdom, _event| {
33//! let hello = root.unwrap_mut::<Hello>();
34//! web_sys::window()
35//! .expect_throw("should have a `Window` on the Web")
36//! .alert_with_message(hello.who);
37//! })
38//! .children([
39//! text("Hello, "),
40//! strong(bump)
41//! .children([
42//! text(self.who),
43//! text("!"),
44//! ])
45//! .finish(),
46//! ])
47//! .finish()
48//! }
49//! }
50//! ```
51#![deny(missing_docs, missing_debug_implementations)]
53// Re-export the `bumpalo` crate.
54pub use bumpalo;
56#[macro_use]
57mod logging;
59// Only `pub` so that the wasm-bindgen bindings work.
60#[doc(hidden)]
61pub mod change_list;
63mod cached;
64mod events;
65mod node;
66mod render;
67mod vdom;
69pub mod builder;
71// Re-export items at the top level.
72pub use self::cached::Cached;
73pub use self::node::{Attribute, ElementNode, Listener, ListenerCallback, Node, TextNode};
74pub use self::render::{Render, RootRender};
75pub use self::vdom::{Vdom, VdomWeak};