Struct vertigo::Value

source ·
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>

source

pub fn new(value: T) -> Value<T>

source

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.

source

pub fn set(&self, value: T)

source

pub fn get(&self, context: &Context) -> T

source

pub fn change(&self, change_fn: impl FnOnce(&mut T))

source

pub fn map<K: Clone + 'static, F: 'static + Fn(T) -> K>( &self, fun: F ) -> Computed<K>

source

pub fn to_computed(&self) -> Computed<T>

source

pub fn id(&self) -> GraphId

source

pub fn deps(&self) -> &'static Dependencies

source§

impl<T: Clone + PartialEq + 'static> Value<T>

source

pub fn set_value_and_compare(&self, value: T)

source§

impl<T: Clone + PartialEq + 'static> Value<T>

source

pub fn render_value(&self, render: impl Fn(T) -> DomNode + 'static) -> DomNode

source

pub fn render_value_option( &self, render: impl Fn(T) -> Option<DomNode> + 'static ) -> DomNode

source§

impl<T: PartialEq + Clone + 'static, L: IntoIterator<Item = T> + Clone + PartialEq + 'static> Value<L>

source

pub fn render_list<K: Eq + Hash>( &self, get_key: impl Fn(&T) -> K + 'static, render: impl Fn(&T) -> DomNode + 'static ) -> DomNode

Trait Implementations§

source§

impl<T> Clone for Value<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Clone + Default + 'static> Default for Value<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for &Value<T>

source§

impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for Value<T>

source§

impl<T: Clone + 'static> From<Value<T>> for Computed<T>

source§

fn from(val: Value<T>) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq<Value<T>> for Value<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.