From c5e647e97d0567e8362662a80ce474b95aa638ac Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 30 Oct 2023 08:39:37 -0500 Subject: [PATCH] add read untracked to signals --- packages/signals/src/signal.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index 9213307ff..0ad96349d 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -200,6 +200,13 @@ impl Signal { Ref::map(inner, |v| &v.value) } + /// Get the current value of the signal. **Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update.** + /// If the signal has been dropped, this will panic. + pub fn read_untracked(&self) -> Ref { + let inner = self.inner.read(); + Ref::map(inner, |v| &v.value) + } + /// Get a mutable reference to the signal's value. /// If the signal has been dropped, this will panic. pub fn write(&self) -> Write<'_, T> { @@ -385,6 +392,12 @@ impl ReadOnlySignal { self.inner.read() } + /// Get the current value of the signal. **Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update.** + /// If the signal has been dropped, this will panic. + pub fn read_untracked(&self) -> Ref { + self.inner.read_untracked() + } + /// Run a closure with a reference to the signal's value. pub fn with(&self, f: impl FnOnce(&T) -> O) -> O { self.inner.with(f)