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§
source§impl<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) -> &'static Dependencies
source§impl<T: Clone + PartialEq + 'static> Value<T>
impl<T: Clone + PartialEq + 'static> Value<T>
pub fn set_value_and_compare(&self, value: T)
Trait Implementations§
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§
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
Mutably borrows from an owned value. Read more