Struct leptos_reactive::StoredValue
source · pub struct StoredValue<T>where
T: 'static,{ /* private fields */ }
Expand description
A non-reactive wrapper for any value, which can be created with store_value.
If you want a reactive wrapper, use create_signal.
This allows you to create a stable reference for any value by storing it within
the reactive system. Like the signal types (e.g., ReadSignal
and RwSignal), it is Copy
and 'static
. Unlike the signal
types, it is not reactive; accessing it does not cause effects to subscribe, and
updating it does not notify anything else.
Implementations§
source§impl<T> StoredValue<T>
impl<T> StoredValue<T>
sourcepub fn get(&self) -> Twhere
T: Clone,
👎Deprecated: Please use get_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn get(&self) -> Twhere T: Clone,
get_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Returns a clone of the signals current value, subscribing the effect to this signal.
Panics
Panics if you try to access a value stored in a Scope that has been disposed.
Examples
#[derive(Clone)]
pub struct MyCloneableData {
pub value: String,
}
let data = store_value(cx, MyCloneableData { value: "a".into() });
// calling .get() clones and returns the value
assert_eq!(data.get().value, "a");
// there's a short-hand getter form
assert_eq!(data().value, "a");
sourcepub fn get_value(&self) -> Twhere
T: Clone,
pub fn get_value(&self) -> Twhere T: Clone,
Returns a clone of the signals current value, subscribing the effect to this signal.
Panics
Panics if you try to access a value stored in a Scope that has been disposed.
Examples
#[derive(Clone)]
pub struct MyCloneableData {
pub value: String,
}
let data = store_value(cx, MyCloneableData { value: "a".into() });
// calling .get() clones and returns the value
assert_eq!(data.get().value, "a");
// there's a short-hand getter form
assert_eq!(data().value, "a");
sourcepub fn try_get(&self) -> Option<T>where
T: Clone,
👎Deprecated: Please use try_get_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn try_get(&self) -> Option<T>where T: Clone,
try_get_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Same as StoredValue::get
but will not panic by default.
sourcepub fn try_get_value(&self) -> Option<T>where
T: Clone,
pub fn try_get_value(&self) -> Option<T>where T: Clone,
Same as StoredValue::get
but will not panic by default.
sourcepub fn with<U>(&self, f: impl FnOnce(&T) -> U) -> U
👎Deprecated: Please use with_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn with<U>(&self, f: impl FnOnce(&T) -> U) -> U
with_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Applies a function to the current stored value.
Panics
Panics if you try to access a value stored in a Scope that has been disposed.
Examples
pub struct MyUncloneableData {
pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
// calling .with() to extract the value
assert_eq!(data.with(|data| data.value.clone()), "a");
});
sourcepub fn with_value<U>(&self, f: impl FnOnce(&T) -> U) -> U
pub fn with_value<U>(&self, f: impl FnOnce(&T) -> U) -> U
Applies a function to the current stored value.
Panics
Panics if you try to access a value stored in a Scope that has been disposed.
Examples
pub struct MyUncloneableData {
pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
// calling .with() to extract the value
assert_eq!(data.with(|data| data.value.clone()), "a");
sourcepub fn try_with<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>
👎Deprecated: Please use try_with_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn try_with<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>
try_with_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Same as StoredValue::with
but returns [Some(O)]
only if
the signal is still valid. None
otherwise.
sourcepub fn try_with_value<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>
pub fn try_with_value<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>
Same as StoredValue::with
but returns [Some(O)]
only if
the signal is still valid. None
otherwise.
sourcepub fn update(&self, f: impl FnOnce(&mut T))
👎Deprecated: Please use update_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn update(&self, f: impl FnOnce(&mut T))
update_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Updates the stored value.
Examples
pub struct MyUncloneableData {
pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.update(|data| data.value = "b".into());
assert_eq!(data.with(|data| data.value.clone()), "b");
});
use leptos_reactive::*;
pub struct MyUncloneableData {
pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
let updated = data.update_returning(|data| {
data.value = "b".into();
data.value.clone()
});
assert_eq!(data.with(|data| data.value.clone()), "b");
assert_eq!(updated, Some(String::from("b")));
sourcepub fn update_value(&self, f: impl FnOnce(&mut T))
pub fn update_value(&self, f: impl FnOnce(&mut T))
Updates the stored value.
Examples
pub struct MyUncloneableData {
pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.update(|data| data.value = "b".into());
assert_eq!(data.with(|data| data.value.clone()), "b");
});
use leptos_reactive::*;
pub struct MyUncloneableData {
pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
let updated = data.update_returning(|data| {
data.value = "b".into();
data.value.clone()
});
assert_eq!(data.with(|data| data.value.clone()), "b");
assert_eq!(updated, Some(String::from("b")));
sourcepub fn update_returning<U>(&self, f: impl FnOnce(&mut T) -> U) -> Option<U>
👎Deprecated: Please use try_update_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn update_returning<U>(&self, f: impl FnOnce(&mut T) -> U) -> Option<U>
try_update_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Updates the stored value.
sourcepub fn try_update_value<O>(self, f: impl FnOnce(&mut T) -> O) -> Option<O>
pub fn try_update_value<O>(self, f: impl FnOnce(&mut T) -> O) -> Option<O>
Same as Self::update
, but returns [Some(O)
] if the
signal is still valid, None
otherwise.
sourcepub fn set(&self, value: T)
👎Deprecated: Please use set_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
pub fn set(&self, value: T)
set_value
instead, as this method does not track the stored value. This method will also be removed in a future version of leptos
Sets the stored value.
Examples
pub struct MyUncloneableData {
pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.set(MyUncloneableData { value: "b".into() });
assert_eq!(data.with(|data| data.value.clone()), "b");
});
sourcepub fn set_value(&self, value: T)
pub fn set_value(&self, value: T)
Sets the stored value.
Examples
pub struct MyUncloneableData {
pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.set(MyUncloneableData { value: "b".into() });
assert_eq!(data.with(|data| data.value.clone()), "b");
sourcepub fn try_set_value(&self, value: T) -> Option<T>
pub fn try_set_value(&self, value: T) -> Option<T>
Trait Implementations§
source§impl<T> Clone for StoredValue<T>
impl<T> Clone for StoredValue<T>
source§impl<T> Debug for StoredValue<T>where
T: 'static + Debug,
impl<T> Debug for StoredValue<T>where T: 'static + Debug,
source§impl<T> Hash for StoredValue<T>where
T: 'static + Hash,
impl<T> Hash for StoredValue<T>where T: 'static + Hash,
source§impl<T> PartialEq<StoredValue<T>> for StoredValue<T>where
T: 'static + PartialEq,
impl<T> PartialEq<StoredValue<T>> for StoredValue<T>where T: 'static + PartialEq,
source§fn eq(&self, other: &StoredValue<T>) -> bool
fn eq(&self, other: &StoredValue<T>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<T> Copy for StoredValue<T>
impl<T> Eq for StoredValue<T>where T: 'static + Eq,
impl<T> StructuralEq for StoredValue<T>where T: 'static,
impl<T> StructuralPartialEq for StoredValue<T>where T: 'static,
Auto Trait Implementations§
impl<T> RefUnwindSafe for StoredValue<T>where T: RefUnwindSafe,
impl<T> Send for StoredValue<T>where T: Send,
impl<T> Sync for StoredValue<T>where T: Sync,
impl<T> Unpin for StoredValue<T>where T: Unpin,
impl<T> UnwindSafe for StoredValue<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CallHasher for Twhere
T: Hash + ?Sized,
impl<T> CallHasher for Twhere T: Hash + ?Sized,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.