add read untracked to signals

This commit is contained in:
Evan Almloff committed 2023-10-30 08:39:37 -05:00
1 parent d4e6876ff6
commit c5e647e97d
1 file changed
+13
+13
View File
@@ -200,6 +200,13 @@ impl<T: 'static> Signal<T> {
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<T> {
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<T: 'static> ReadOnlySignal<T> {
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<T> {
self.inner.read_untracked()
}
/// Run a closure with a reference to the signal's value.
pub fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O {
self.inner.with(f)