Change signals example a bit

This commit is contained in:
Jonathan Kelley 2023-10-17 15:52:13 -07:00
parent e819702fc5
commit 65e21d7874
No known key found for this signature in database
GPG Key ID: 1FBB50F7EB0A08BE
1 changed files with 2 additions and 1 deletions

View File

@ -27,6 +27,7 @@ fn app(cx: Scope) -> Element {
button { onclick: move |_| count -= 1, "Down low!" }
button { onclick: move |_| running.toggle(), "Toggle counter" }
button { onclick: move |_| saved_values.push(count.value().to_string()), "Save this value" }
button { onclick: move |_| saved_values.write().clear(), "Clear saved values" }
// We can do boolean operations on the current signal value
if count.value() > 5 {
@ -40,7 +41,7 @@ fn app(cx: Scope) -> Element {
// We can also use the signal value as a slice
if let &[ref first, .., ref last] = saved_values.read().as_slice() {
rsx! { li { "single element: {first}, {last}" } }
rsx! { li { "First and last: {first}, {last}" } }
} else {
rsx! { "No saved values" }
}