on b159bbd help sign in
dodrio/src/lib.rs
82 lines 2.1 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;
56cfg_if::cfg_if! {
57 if #[cfg(feature = "log")] {
58 #[macro_use]
59 extern crate log;
60 } else {
61 #[macro_use]
62 mod logging;
63 }
66// Only `pub` so that the wasm-bindgen bindings work.
67#[doc(hidden)]
68pub mod change_list;
70mod cached;
71mod events;
72mod node;
73mod render;
74mod vdom;
76pub mod builder;
78// Re-export items at the top level.
79pub use self::cached::Cached;
80pub use self::node::{Attribute, ElementNode, Listener, ListenerCallback, Node, TextNode};
81pub use self::render::{Render, RootRender};
82pub use self::vdom::{Vdom, VdomWeak};