Skip to content

Commit 78fe61f

Browse files
MartinKavikDavid-OConnor
authored andcommitted
128-updateEl-for-iter-Map
1 parent e38f7b5 commit 78fe61f

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ members = [
8282
"examples/animation_frame",
8383
"examples/counter",
8484
# "examples/homepage", # isn't Rust project
85-
# "examples/mathjax", # isn't Rust project
8685
"examples/mathjax",
8786
"examples/orders",
8887
# "examples/server_integration", # has own workspace

examples/websocket/src/client.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ fn update(msg: Msg, mut model: &mut Model, orders: &mut Orders<Msg>) {
5454
}
5555
}
5656

57-
fn render_messages(msgs: &[String]) -> El<Msg> {
58-
let msgs: Vec<_> = msgs.iter().map(|m| p![m]).collect();
59-
div![msgs]
60-
}
61-
6257
fn view(model: &Model) -> Vec<El<Msg>> {
6358
vec![
6459
h1!["seed websocket example"],
@@ -86,7 +81,7 @@ fn view(model: &Model) -> Vec<El<Msg>> {
8681
} else {
8782
div![p![em!["Connecting..."]]]
8883
},
89-
render_messages(&model.messages),
84+
div![model.messages.iter().map(|m| p![m])],
9085
footer![
9186
if model.connected {
9287
p!["Connected"]

src/dom_types.rs

+11
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ impl<Ms> UpdateEl<El<Ms>> for Optimize {
489489
}
490490
}
491491

492+
impl<Ms, I, U, F> UpdateEl<El<Ms>> for std::iter::Map<I, F>
493+
where
494+
I: Iterator,
495+
U: UpdateEl<El<Ms>>,
496+
F: FnMut(I::Item) -> U,
497+
{
498+
fn update(self, el: &mut El<Ms>) {
499+
self.for_each(|item| item.update(el));
500+
}
501+
}
502+
492503
/// Similar to tag population.
493504
macro_rules! make_attrs {
494505
// Create shortcut macros for any element; populate these functions in this module.

0 commit comments

Comments
 (0)