pub struct LocalProperty<T> { /* private fields */ }Expand description
An owner-thread value or computation in Pax’s reactive graph.
Unlike Property, this handle may contain local values and evaluator
captures. It cannot cross threads, even when T itself is transferable.
use pax_runtime_api::LocalProperty;
let value = LocalProperty::new(1_u32);
std::thread::spawn(move || value.get());Implementations§
Source§impl<T> LocalProperty<T>where
T: PropertyValue,
impl<T> LocalProperty<T>where
T: PropertyValue,
Sourcepub fn local(&self) -> LocalProperty<T>
pub fn local(&self) -> LocalProperty<T>
Clones this owner-thread view without changing its property identity.
Sourcepub fn new(val: T) -> LocalProperty<T>
pub fn new(val: T) -> LocalProperty<T>
Creates a literal property with an initial value.
pub fn new_from_untyped(untyped: UntypedProperty) -> LocalProperty<T>
Sourcepub fn computed(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
) -> LocalProperty<T>
pub fn computed( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], ) -> LocalProperty<T>
Creates a computed property from an evaluator and dependency list.
Sourcepub fn computed_with_cutoff(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
cutoff: impl Fn(&T, &T) -> bool + 'static,
) -> LocalProperty<T>
pub fn computed_with_cutoff( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, ) -> LocalProperty<T>
Creates a computed property with a propagation cutoff.
The predicate receives the last accepted value and the newly evaluated
candidate. Returning true discards the candidate and stops outbound
invalidation at this property; returning false accepts and propagates
it. The first evaluation is always accepted.
Sourcepub fn new_with_name(val: T, name: &str) -> LocalProperty<T>
pub fn new_with_name(val: T, name: &str) -> LocalProperty<T>
Creates a named literal property, useful for diagnostics.
Sourcepub fn computed_with_name(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
name: &str,
) -> LocalProperty<T>
pub fn computed_with_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], name: &str, ) -> LocalProperty<T>
Creates a named computed property, useful for diagnostics.
Sourcepub fn computed_with_cutoff_and_name(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
cutoff: impl Fn(&T, &T) -> bool + 'static,
name: &str,
) -> LocalProperty<T>
pub fn computed_with_cutoff_and_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, name: &str, ) -> LocalProperty<T>
Creates a named cutoff computed property, useful for diagnostics.
Sourcepub fn ease_to<D>(&self, end_val: T, duration: D, curve: EasingCurve)
pub fn ease_to<D>(&self, end_val: T, duration: D, curve: EasingCurve)
Immediately starts an ease transition from the current value to end_val, over a duration, following curve.
Numeric arguments preserve the historical frame-based behavior. Use
Duration::Milliseconds, Duration::Seconds, or Duration::Frames to
select an explicit unit.
Sourcepub fn ease_to_later<D>(&self, end_val: T, duration: D, curve: EasingCurve)
pub fn ease_to_later<D>(&self, end_val: T, duration: D, curve: EasingCurve)
Enqueues an ease transition from the current value to end_val, over a duration, following curve, which will start after all currently enqueued transitions finish.
Sourcepub fn cancel_transitions(&self)
pub fn cancel_transitions(&self)
Stops the active transition and clears every queued transition segment.
The property is left at its current eased value. A subsequent LocalProperty::set
can therefore take immediate ownership without the cancelled transition
overwriting it on the next runtime tick.
Sourcepub fn get(&self) -> T
pub fn get(&self) -> T
Gets the currently stored value. Might be computationally expensive in a large reactivity network since this triggers re-evaluation of dirty property chains
Sourcepub fn set(&self, val: T)
pub fn set(&self, val: T)
Sets this properties value and sets the dirty bit recursively of all of its dependencies if not already set
Sourcepub fn set_if_neq(&self, val: T) -> boolwhere
T: PartialEq,
pub fn set_if_neq(&self, val: T) -> boolwhere
T: PartialEq,
Sets the value only when it differs from the current one.
Returns true when the write changed the property and dirtied dependents.
Sourcepub fn update(&self, f: impl FnOnce(&mut T))
pub fn update(&self, f: impl FnOnce(&mut T))
Get access to a mutable reference to the inner value T. Will trigger updates for dependents of this property, regardless of if the value actually changed
Sourcepub fn read<V>(&self, f: impl FnOnce(&T) -> V) -> V
pub fn read<V>(&self, f: impl FnOnce(&T) -> V) -> V
Reads the inner value by reference.
Panics if this property is already borrowed, which can happen if read
is called inside a read of the same property.
Sourcepub fn replace_with(&self, target: LocalProperty<T>)
pub fn replace_with(&self, target: LocalProperty<T>)
Replaces this property’s evaluator, dependencies, and value with target, while keeping dependents.
This can introduce circular dependencies if used carelessly. It is intended for changing a property from literal to computed (or vice versa) without severing existing outbound links.
Sourcepub fn untyped(&self) -> UntypedProperty
pub fn untyped(&self) -> UntypedProperty
Casts this property to its untyped version.
Trait Implementations§
Source§impl<T> Clone for LocalProperty<T>where
T: Clone,
impl<T> Clone for LocalProperty<T>where
T: Clone,
Source§fn clone(&self) -> LocalProperty<T>
fn clone(&self) -> LocalProperty<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for LocalProperty<T>where
T: PropertyValue + Debug,
impl<T> Debug for LocalProperty<T>where
T: PropertyValue + Debug,
Source§impl<T> Default for LocalProperty<T>where
T: PropertyValue,
impl<T> Default for LocalProperty<T>where
T: PropertyValue,
Source§fn default() -> LocalProperty<T>
fn default() -> LocalProperty<T>
Source§impl<'de, T> Deserialize<'de> for LocalProperty<T>where
T: PropertyValue + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for LocalProperty<T>where
T: PropertyValue + Deserialize<'de>,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<LocalProperty<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<LocalProperty<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> Interpolatable for LocalProperty<T>where
T: PropertyValue,
impl<T> Interpolatable for LocalProperty<T>where
T: PropertyValue,
Source§fn interpolate(&self, other: &LocalProperty<T>, t: f64) -> LocalProperty<T>
fn interpolate(&self, other: &LocalProperty<T>, t: f64) -> LocalProperty<T>
Source§impl<T> PropertyBinding<T> for LocalProperty<T>where
T: PropertyValue,
impl<T> PropertyBinding<T> for LocalProperty<T>where
T: PropertyValue,
Source§fn from_value(value: T) -> LocalProperty<T>
fn from_value(value: T) -> LocalProperty<T>
Source§fn local(&self) -> LocalProperty<T>
fn local(&self) -> LocalProperty<T>
Source§fn from_local(source: LocalProperty<T>) -> LocalProperty<T>
fn from_local(source: LocalProperty<T>) -> LocalProperty<T>
Source§impl<T> Serialize for LocalProperty<T>where
T: PropertyValue + Serialize,
impl<T> Serialize for LocalProperty<T>where
T: PropertyValue + Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> ToPaxValue for LocalProperty<T>where
T: ToPaxValue + PropertyValue,
impl<T> ToPaxValue for LocalProperty<T>where
T: ToPaxValue + PropertyValue,
Source§fn nested_properties(&self) -> Vec<UntypedProperty>
fn nested_properties(&self) -> Vec<UntypedProperty>
Source§fn to_pax_value(self) -> PaxValue
fn to_pax_value(self) -> PaxValue
PaxValue.Source§fn to_pax_value_in_graph(self) -> PaxValuewhere
Self: Sized,
fn to_pax_value_in_graph(self) -> PaxValuewhere
Self: Sized,
Self::to_pax_value reads published value snapshots.