pub struct Value<T> { /* private fields */ }
Expand description
A reactive value. Basic building block of app state.
Can be read or written.
use vertigo::{Computed, Value, transaction};
let value = Value::new(5);
transaction(|context| {
assert_eq!(value.get(context), 5);
});
value.set(10);
transaction(|context| {
assert_eq!(value.get(context), 10);
});
Implementations
sourceimpl<T: Clone + 'static> Value<T>
impl<T: Clone + 'static> Value<T>
pub fn new(value: T) -> Value<T>
sourcepub fn with_connect<F>(value: T, create: F) -> Computed<T>where
F: Fn(&Value<T>) -> DropResource + 'static,
pub fn with_connect<F>(value: T, create: F) -> Computed<T>where
F: Fn(&Value<T>) -> DropResource + 'static,
Create a value that is connected to a generator, where value
parameter is a starting value,
and create
function takes care of updating it.
See game of life example.
pub fn set(&self, value: T)
pub fn get(&self, context: &Context) -> T
pub fn change(&self, change_fn: impl FnOnce(&mut T))
pub fn map<K: Clone + 'static, F: 'static + Fn(T) -> K>(
&self,
fun: F
) -> Computed<K>
pub fn to_computed(&self) -> Computed<T>
pub fn id(&self) -> GraphId
pub fn deps(&self) -> Dependencies
sourceimpl<T: Clone + PartialEq + 'static> Value<T>
impl<T: Clone + PartialEq + 'static> Value<T>
pub fn set_value_and_compare(&self, value: T)
sourceimpl<T: Clone + PartialEq + 'static> Value<T>
impl<T: Clone + PartialEq + 'static> Value<T>
pub fn render_value<R: Into<DomNodeFragment>>(
&self,
render: impl Fn(T) -> R + 'static
) -> DomCommentCreate
pub fn render_value_option<R: Into<DomNodeFragment>>(
&self,
render: impl Fn(T) -> Option<R> + 'static
) -> DomCommentCreate
sourceimpl<T: PartialEq + Clone + 'static, L: IntoIterator<Item = T> + Clone + PartialEq + 'static> Value<L>
impl<T: PartialEq + Clone + 'static, L: IntoIterator<Item = T> + Clone + PartialEq + 'static> Value<L>
pub fn render_list<K: Eq + Hash>(
&self,
get_key: impl Fn(&T) -> K + 'static,
render: impl Fn(&T) -> DomElement + 'static
) -> ListRendered<T>
Trait Implementations
sourceimpl<T: ToString + Clone + PartialEq + 'static> EmbedDom for &Value<T>
impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for &Value<T>
fn embed(self) -> DomNodeFragment
sourceimpl<T: ToString + Clone + PartialEq + 'static> EmbedDom for Value<T>
impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for Value<T>
fn embed(self) -> DomNodeFragment
Auto Trait Implementations
impl<T> !RefUnwindSafe for Value<T>
impl<T> !Send for Value<T>
impl<T> !Sync for Value<T>
impl<T> Unpin for Value<T>
impl<T> !UnwindSafe for Value<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more