on master help sign in
Move documentation examples over to using element builders for rendering
commit682b8b44d33ea68ef5d9100de9153e41667bdc8b authorNick Fitzgerald <fitzgen@gmail.com> dateWed 13 Feb 2019, 15:09 (8 years ago) parent4be691b
3 files changed+33−32
src/cached.rs+4−5 src/lib.rs+20−26 src/render.rs+9−1
src/cached.rs+4−5
@@ -89,11 +89,10 @@ impl<R> Cached<R> {
8989 /// where
9090 /// 'a: 'bump,
9191 /// {
92− /// Node::element(bump, "p", [], [], [
93− /// Node::text("Hello, "),
94− /// Node::text(&self.who),
95− /// Node::text("!"),
96− /// ])
92+ /// use dodrio::builder::*;
93+ /// p(bump)
94+ /// .children([text("Hello, "), text(&self.who), text("!")])
95+ /// .finish()
9796 /// }
9897 /// }
9998 ///
src/lib.rs+20−26
@@ -23,34 +23,28 @@
2323//! where
2424//! 'a: 'bump,
2525//! {
26+//! use dodrio::builder::*;
27+//!
2628//! let id = bumpalo::format!(in bump, "hello-{}", self.who);
27−//! Node::element(
28−//! bump,
29−//! // The element's tag name. In this case a `<p>` element.
30−//! "p",
31−//! // Listeners.
32−//! [on(bump, "click", |root, _vdom, _event| {
29+//!
30+//! div(bump)
31+//! .attr("id", id.into_bump_str())
32+//! .on("click", |root, _vdom, _event| {
3333//! let hello = root.unwrap_mut::<Hello>();
34−//! let window = web_sys::window().expect_throw("should have a `Window` on the Web");
35−//! window.alert_with_message(hello.who);
36−//! })],
37−//! // Attributes.
38−//! [Attribute { name: "id", value: id.into_bump_str() }],
39−//! // Child nodes.
40−//! [
41−//! Node::text("Hello, "),
42−//! Node::element(
43−//! bump,
44−//! "strong",
45−//! [],
46−//! [],
47−//! [
48−//! Node::text(self.who),
49−//! Node::text("!"),
50−//! ],
51−//! ),
52−//! ],
53−//! )
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()
5448//! }
5549//! }
5650//! ```
src/render.rs+9−1
@@ -36,7 +36,15 @@ use wasm_bindgen::UnwrapThrowExt;
3636/// where
3737/// 'a: 'bump
3838/// {
39−/// Node::text("This is my component rendered!")
39+/// use dodrio::builder::*;
40+///
41+/// p(bump)
42+/// .children([
43+/// text("This is "),
44+/// strong(bump).children([text("my component")]).finish(),
45+/// text(" rendered!"),
46+/// ])
47+/// .finish()
4048/// }
4149/// }
4250/// ```