on master help sign in
Move documentation examples over to using element builders for rendering
682b8b4Nick Fitzgerald
src/cached.rs+4−5
@@ -89,11 +89,10 @@ impl<R> Cached<R> {
89 /// where
89 /// where
90 /// 'a: 'bump,
90 /// 'a: 'bump,
91 /// {
91 /// {
92− /// Node::element(bump, "p", [], [], [
92+ /// use dodrio::builder::*;
93− /// Node::text("Hello, "),
93+ /// p(bump)
94− /// Node::text(&self.who),
94+ /// .children([text("Hello, "), text(&self.who), text("!")])
95− /// Node::text("!"),
96− /// ])
95+ /// .finish()
97 /// }
96 /// }
98 /// }
97 /// }
99 ///
98 ///
src/lib.rs+20−26
@@ -23,34 +23,28 @@
23//! where
23//! where
24//! 'a: 'bump,
24//! 'a: 'bump,
25//! {
25//! {
26+//! use dodrio::builder::*;
27+//!
26//! let id = bumpalo::format!(in bump, "hello-{}", self.who);
28//! let id = bumpalo::format!(in bump, "hello-{}", self.who);
27−//! Node::element(
29+//!
28−//! bump,
30+//! div(bump)
29−//! // The element's tag name. In this case a `<p>` element.
31+//! .attr("id", id.into_bump_str())
30−//! "p",
31−//! // Listeners.
32−//! [on(bump, "click", |root, _vdom, _event| {
32+//! .on("click", |root, _vdom, _event| {
33//! let hello = root.unwrap_mut::<Hello>();
33//! let hello = root.unwrap_mut::<Hello>();
34+//! web_sys::window()
34−//! let window = web_sys::window().expect_throw("should have a `Window` on the Web");
35+//! .expect_throw("should have a `Window` on the Web")
35−//! window.alert_with_message(hello.who);
36+//! .alert_with_message(hello.who);
36−//! })],
37+//! })
37−//! // Attributes.
38+//! .children([
38−//! [Attribute { name: "id", value: id.into_bump_str() }],
39−//! // Child nodes.
40−//! [
41−//! Node::text("Hello, "),
39+//! text("Hello, "),
42−//! Node::element(
43−//! bump,
40+//! strong(bump)
44−//! "strong",
45−//! [],
41+//! .children([
46−//! [],
47−//! [
48−//! Node::text(self.who),
42+//! text(self.who),
49−//! Node::text("!"),
43+//! text("!"),
50−//! ],
44+//! ])
51−//! ),
45+//! .finish(),
52−//! ],
46+//! ])
53−//! )
47+//! .finish()
54//! }
48//! }
55//! }
49//! }
56//! ```
50//! ```
src/render.rs+9−1
@@ -36,7 +36,15 @@ use wasm_bindgen::UnwrapThrowExt;
36/// where
36/// where
37/// 'a: 'bump
37/// 'a: 'bump
38/// {
38/// {
39+/// use dodrio::builder::*;
40+///
41+/// p(bump)
42+/// .children([
39−/// Node::text("This is my component rendered!")
43+/// text("This is "),
44+/// strong(bump).children([text("my component")]).finish(),
45+/// text(" rendered!"),
46+/// ])
47+/// .finish()
40/// }
48/// }
41/// }
49/// }
42/// ```
50/// ```