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: PropertyValue> LocalProperty<T>
impl<T: PropertyValue> LocalProperty<T>
Sourcepub fn local(&self) -> Self
pub fn local(&self) -> Self
Clones this owner-thread view without changing its property identity.
pub fn new_from_untyped(untyped: UntypedProperty) -> Self
Sourcepub fn computed(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
) -> Self
pub fn computed( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], ) -> Self
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,
) -> Self
pub fn computed_with_cutoff( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, ) -> Self
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) -> Self
pub fn new_with_name(val: T, name: &str) -> Self
Creates a named literal property, useful for diagnostics.
Sourcepub fn computed_with_name(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
name: &str,
) -> Self
pub fn computed_with_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], name: &str, ) -> Self
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,
) -> Self
pub fn computed_with_cutoff_and_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, name: &str, ) -> Self
Creates a named cutoff computed property, useful for diagnostics.
Sourcepub fn ease_to<D: Into<Duration>>(
&self,
end_val: T,
duration: D,
curve: EasingCurve,
)
pub fn ease_to<D: Into<Duration>>( &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: Into<Duration>>(
&self,
end_val: T,
duration: D,
curve: EasingCurve,
)
pub fn ease_to_later<D: Into<Duration>>( &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> Clone for LocalProperty<T>
impl<T: Clone> Clone for LocalProperty<T>
Source§impl<T: PropertyValue + Debug> Debug for LocalProperty<T>
impl<T: PropertyValue + Debug> Debug for LocalProperty<T>
Source§impl<T: PropertyValue> Default for LocalProperty<T>
impl<T: PropertyValue> Default for LocalProperty<T>
Source§impl<'de, T: PropertyValue + Deserialize<'de>> Deserialize<'de> for LocalProperty<T>
impl<'de, T: PropertyValue + Deserialize<'de>> Deserialize<'de> for LocalProperty<T>
Source§fn deserialize<D>(deserializer: D) -> Result<LocalProperty<T>, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<LocalProperty<T>, D::Error>where
D: Deserializer<'de>,
Source§impl<T: PropertyValue> Interpolatable for LocalProperty<T>
impl<T: PropertyValue> Interpolatable for LocalProperty<T>
Source§fn interpolate(&self, other: &Self, t: f64) -> Self
fn interpolate(&self, other: &Self, t: f64) -> Self
Source§impl<T: PropertyValue> PropertyBinding<T> for LocalProperty<T>
impl<T: PropertyValue> PropertyBinding<T> for LocalProperty<T>
Source§fn from_value(value: T) -> Self
fn from_value(value: T) -> Self
Source§fn from_local(source: Self) -> Self
fn from_local(source: Self) -> Self
Source§impl<T: PropertyValue + Serialize> Serialize for LocalProperty<T>
impl<T: PropertyValue + Serialize> Serialize for LocalProperty<T>
Source§impl<T: ToPaxValue + PropertyValue> ToPaxValue for LocalProperty<T>
impl<T: ToPaxValue + PropertyValue> ToPaxValue for LocalProperty<T>
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.