Add toggle
This commit is contained in:
2 files changed
+8
-1
No files matched your search
+1
-1
@@ -23,7 +23,7 @@ fn app(cx: Scope) -> Element {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
button { onclick: move |_| running.set(!running.value()), "Toggle counter" }
|
||||
button { onclick: move |_| running.toggle(), "Toggle counter" }
|
||||
button { onclick: move |_| saved_values.push(count.value()), "Save this value" }
|
||||
|
||||
// We can do boolean operations on the current signal value
|
||||
|
||||
@@ -262,6 +262,13 @@ impl<T: Clone + 'static> Signal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Signal<bool> {
|
||||
/// Invert the boolean value of the signal. This will trigger an update on all subscribers.
|
||||
pub fn toggle(&self) {
|
||||
self.set(!self.value());
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> PartialEq for Signal<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.inner == other.inner
|
||||
|
||||
Reference in new issue
Block a user