@@ -1,8 +1,7 @@
11mod colors;
22
33use cfg_if::cfg_if;
4−use dodrio::bumpalo::{self, Bump};
5−use dodrio::{Node, Render, Vdom};
4+use dodrio::{bumpalo, Node, Render, RenderContext, Vdom};
65use std::cell::RefCell;
76use std::rc::Rc;
87use std::str;
@@ -107,7 +106,7 @@ impl Moire {
107106}
108107
109108impl Render for Moire {
110− fn render<'bump>(&self, bump: &'bump Bump) -> Node<'bump> {
109+ fn render<'bump>(&self, cx: &mut RenderContext<'bump>) -> Node<'bump> {
111110 use dodrio::builder::*;
112111
113112 let elapsed = web_sys::window()
@@ -117,18 +116,18 @@ impl Render for Moire {
117116 .now();
118117 let elapsed = elapsed / 1600.0;
119118
120− main(bump)
121− .attr("style", self.moire_style(bump, elapsed))
119+ main(cx.bump)
120+ .attr("style", self.moire_style(cx, elapsed))
122121 .children([
123122 // The `<input>` that lets users control how many circles to
124123 // render.
125− input(bump)
124+ input(cx.bump)
126125 .attr("id", "circle-count")
127126 .attr("type", "range")
128127 .attr("min", "30")
129128 .attr("max", "500")
130129 .attr("value", {
131− let count = bumpalo::format!(in bump, "{}", self.count);
130+ let count = bumpalo::format!(in cx.bump, "{}", self.count);
132131 count.into_bump_str()
133132 })
134133 .on("change", |root, _vdom, event| {
@@ -141,8 +140,8 @@ impl Render for Moire {
141140 })
142141 .finish(),
143142 // And the actual concentric circles that form the Moire patterns.
144− self.orbiting_objects(bump, elapsed),
145− self.lemniscate_objects(bump, elapsed),
143+ self.orbiting_objects(cx, elapsed),
144+ self.lemniscate_objects(cx, elapsed),
146145 ])
147146 .finish()
148147 }
@@ -151,11 +150,11 @@ impl Render for Moire {
151150/// Rendering helper methods.
152151impl Moire {
153152 /// Generate the main Moire element's inline CSS styles.
154− fn moire_style<'bump>(&self, bump: &'bump Bump, elapsed: f64) -> &'bump str {
153+ fn moire_style<'bump>(&self, cx: &mut RenderContext<'bump>, elapsed: f64) -> &'bump str {
155154 let elapsed = elapsed / 3.0;
156155 let color = colors::get_interpolated_color(|(_, bg)| bg, elapsed % 1.0);
157156 let style = bumpalo::format!(
158− in bump,
157+ in cx.bump,
159158 "background-color: rgb({}, {}, {})",
160159 color.r,
161160 color.g,
@@ -165,69 +164,84 @@ impl Moire {
165164 }
166165
167166 /// Generate the orbiting circle objects.
168− fn orbiting_objects<'bump>(&self, bump: &'bump Bump, elapsed: f64) -> Node<'bump> {
167+ fn orbiting_objects<'bump>(&self, cx: &mut RenderContext<'bump>, elapsed: f64) -> Node<'bump> {
169168 const D: f64 = 200.0;
170169 let x = elapsed.sin() * D;
171170 let y = elapsed.cos() * D;
172− self.moving_object(bump, elapsed, x, y)
171+ self.moving_object(cx, elapsed, x, y)
173172 }
174173
175174 /// Generate the lemniscate circle objects that interact with the orbiting
176175 /// circle objects to form Moire patterns.
177− fn lemniscate_objects<'bump>(&self, bump: &'bump Bump, elapsed: f64) -> Node<'bump> {
176+ fn lemniscate_objects<'bump>(
177+ &self,
178+ cx: &mut RenderContext<'bump>,
179+ elapsed: f64,
180+ ) -> Node<'bump> {
178181 const A: f64 = 150.0;
179182 let x = elapsed.sin() * A;
180183 let y = elapsed.sin() * elapsed.cos() * A;
181− self.moving_object(bump, elapsed, x, y)
184+ self.moving_object(cx, elapsed, x, y)
182185 }
183186
184187 fn moving_object<'a, 'bump>(
185188 &'a self,
186− bump: &'bump Bump,
189+ cx: &mut RenderContext<'bump>,
187190 elapsed: f64,
188191 x: f64,
189192 y: f64,
190193 ) -> Node<'bump> {
191194 use dodrio::builder::*;
192− div(bump)
195+ div(cx.bump)
193196 .attr("class", "object")
194− .attr("style", self.moving_object_style(bump, x, y))
195− .children([self.circle(bump, elapsed, self.count)])
197+ .attr("style", self.moving_object_style(cx, x, y))
198+ .children([self.circle(cx, elapsed, self.count)])
196199 .finish()
197200 }
198201
199202 /// Generate inline CSS styles for a moving object.
200− fn moving_object_style<'bump>(&self, bump: &'bump Bump, x: f64, y: f64) -> &'bump str {
201− bumpalo::format!(in bump, "left: {}px; top: {}px;", x, y).into_bump_str()
203+ fn moving_object_style<'bump>(
204+ &self,
205+ cx: &mut RenderContext<'bump>,
206+ x: f64,
207+ y: f64,
208+ ) -> &'bump str {
209+ bumpalo::format!(in cx.bump, "left: {}px; top: {}px;", x, y).into_bump_str()
202210 }
203211
204212 /// Recursively generate `self.count` concentric circles.
205− fn circle<'bump>(&self, bump: &'bump Bump, elapsed: f64, n: u32) -> Node<'bump> {
213+ fn circle<'bump>(&self, cx: &mut RenderContext<'bump>, elapsed: f64, n: u32) -> Node<'bump> {
206214 use dodrio::builder::*;
207215
208216 let r = n * 16;
209217
210− let mut circle = div(bump)
218+ let mut circle = div(cx.bump)
211219 .attr("class", "circle")
212220 .attr("data-radius", {
213− let r = bumpalo::format!(in bump, "{}", r);
221+ let r = bumpalo::format!(in cx.bump, "{}", r);
214222 r.into_bump_str()
215223 })
216− .attr("style", self.circle_style(bump, elapsed, n, r));
224+ .attr("style", self.circle_style(cx, elapsed, n, r));
217225
218226 if n > 0 {
219− circle = circle.child(self.circle(bump, elapsed, n - 1));
227+ circle = circle.child(self.circle(cx, elapsed, n - 1));
220228 }
221229
222230 circle.finish()
223231 }
224232
225233 /// Generate inline CSS styles for a circle.
226− fn circle_style<'bump>(&self, bump: &'bump Bump, elapsed: f64, n: u32, r: u32) -> &'bump str {
234+ fn circle_style<'bump>(
235+ &self,
236+ cx: &mut RenderContext<'bump>,
237+ elapsed: f64,
238+ n: u32,
239+ r: u32,
240+ ) -> &'bump str {
227241 let (border, alpha) = self.circle_color(elapsed, n);
228242 let margin = r / 2 + 3;
229243 let style = bumpalo::format!(
230− in bump,
244+ in cx.bump,
231245 "border-color: rgba({}, {}, {}, {});\
232246 margin-left: -{}px;\
233247 margin-top: -{}px;\