1
0
Эх сурвалжийг харах

Adjust impl for signal syntax to allow cloned values

Jonathan Kelley 1 жил өмнө
parent
commit
d88561f973

+ 1 - 1
examples/signals.rs

@@ -14,7 +14,7 @@ fn app() -> Element {
     // Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps
     // Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps
     use_future(|| async move {
     use_future(|| async move {
         loop {
         loop {
-            if running.cloned() {
+            if running() {
                 count += 1;
                 count += 1;
             }
             }
             tokio::time::sleep(Duration::from_millis(400)).await;
             tokio::time::sleep(Duration::from_millis(400)).await;

+ 5 - 2
packages/signals/src/signal.rs

@@ -348,7 +348,10 @@ impl<T: 'static> PartialEq for Signal<T> {
     }
     }
 }
 }
 
 
-impl<T: Copy> Deref for Signal<T> {
+/// Allow calling a signal with signal() syntax
+///
+/// Currently only limited to copy types, though could probably specialize for string/arc/rc
+impl<T: Copy + Clone> Deref for Signal<T> {
     type Target = dyn Fn() -> T;
     type Target = dyn Fn() -> T;
 
 
     fn deref(&self) -> &Self::Target {
     fn deref(&self) -> &Self::Target {
@@ -486,7 +489,7 @@ impl<T: 'static> PartialEq for ReadOnlySignal<T> {
     }
     }
 }
 }
 
 
-impl<T: Copy> Deref for ReadOnlySignal<T> {
+impl<T: Copy + Clone> Deref for ReadOnlySignal<T> {
     type Target = dyn Fn() -> T;
     type Target = dyn Fn() -> T;
 
 
     fn deref(&self) -> &Self::Target {
     fn deref(&self) -> &Self::Target {