chore: clean up example a bit more
This commit is contained in:
1 parent
41872a075f
commit
fcbd260f1a
1 file changed
+10
-9
+10
-9
@@ -41,9 +41,16 @@ const RECT_STYLE: &str = r#"
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let events = use_ref(&cx, Vec::new);
|
let events = use_ref(&cx, std::collections::VecDeque::new);
|
||||||
|
|
||||||
let log_event = move |event: Event| events.write().push(event);
|
let log_event = move |event: Event| {
|
||||||
|
let mut events = events.write();
|
||||||
|
|
||||||
|
if events.len() >= MAX_EVENTS {
|
||||||
|
events.pop_front();
|
||||||
|
}
|
||||||
|
events.push_back(event);
|
||||||
|
};
|
||||||
|
|
||||||
cx.render(rsx! (
|
cx.render(rsx! (
|
||||||
div {
|
div {
|
||||||
@@ -71,13 +78,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
"Hover, click, type or scroll to see the info down below"
|
"Hover, click, type or scroll to see the info down below"
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
events
|
events.read().iter().map(|event| rsx!( div { "{event:?}" } ))
|
||||||
.read()
|
|
||||||
.iter()
|
|
||||||
.rev()
|
|
||||||
.take(MAX_EVENTS)
|
|
||||||
.rev()
|
|
||||||
.map(|event| cx.render(rsx!(div {"{event:?}"})))
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in new issue
Block a user