From c5e647e97d0567e8362662a80ce474b95aa638ac Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 30 Oct 2023 08:39:37 -0500 Subject: [PATCH 1/4] 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) From 2bab4eb6c3748ca8803a1332ff57502979da7e55 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 7 Dec 2023 07:06:43 -0600 Subject: [PATCH 2/4] rename read_untracked to peak --- packages/signals/src/signal.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index 0ad96349d..88853c473 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -171,7 +171,8 @@ impl Signal { self.inner.origin_scope() } - /// Get the current value of the signal. This will subscribe the current scope to the signal. + /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peak`] instead. + /// /// If the signal has been dropped, this will panic. pub fn read(&self) -> Ref { let inner = self.inner.read(); @@ -201,13 +202,15 @@ impl Signal { } /// 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 { + pub fn peak(&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> { let inner = self.inner.write(); @@ -387,15 +390,18 @@ impl ReadOnlySignal { self.inner.origin_scope() } - /// Get the current value of the signal. This will subscribe the current scope to the signal. + /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peak`] instead. + /// + /// If the signal has been dropped, this will panic. pub fn read(&self) -> Ref { 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() + pub fn peak(&self) -> Ref { + self.inner.peak() } /// Run a closure with a reference to the signal's value. From 1c2a6fa010fb8c7f209a229b59750951123670a7 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 7 Dec 2023 07:19:41 -0600 Subject: [PATCH 3/4] fix signals with debug information --- packages/signals/src/signal.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index a5ee6b198..6c4052b98 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -237,9 +237,9 @@ impl Signal { /// 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 peak(&self) -> Ref { + pub fn peak(&self) -> GenerationalRef { let inner = self.inner.read(); - Ref::map(inner, |v| &v.value) + GenerationalRef::map(inner, |v| &v.value) } /// Get a mutable reference to the signal's value. @@ -439,7 +439,7 @@ impl ReadOnlySignal { /// 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 peak(&self) -> Ref { + pub fn peak(&self) -> GenerationalRef { self.inner.peak() } From a1550460ce8cda98998d074243c995955cf6557a Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 7 Dec 2023 11:37:59 -0600 Subject: [PATCH 4/4] Fix peek spelling --- packages/signals/src/signal.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index 6c4052b98..1dc4bd36e 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -203,7 +203,7 @@ impl Signal { self.inner.origin_scope() } - /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peak`] instead. + /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peek`] instead. /// /// If the signal has been dropped, this will panic. #[track_caller] @@ -237,7 +237,7 @@ impl Signal { /// 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 peak(&self) -> GenerationalRef { + pub fn peek(&self) -> GenerationalRef { let inner = self.inner.read(); GenerationalRef::map(inner, |v| &v.value) } @@ -428,7 +428,7 @@ impl ReadOnlySignal { self.inner.origin_scope() } - /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peak`] instead. + /// Get the current value of the signal. This will subscribe the current scope to the signal. If you would like to read the signal without subscribing to it, you can use [`Self::peek`] instead. /// /// If the signal has been dropped, this will panic. #[track_caller] @@ -439,8 +439,8 @@ impl ReadOnlySignal { /// 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 peak(&self) -> GenerationalRef { - self.inner.peak() + pub fn peek(&self) -> GenerationalRef { + self.inner.peek() } /// Run a closure with a reference to the signal's value.