pub struct SnapshotStateObserver { /* private fields */ }Expand description
Observer that records state object reads performed inside a given scope and notifies the caller when any of the observed objects change.
This is a pragmatic Rust translation of Jetpack Compose’s
SnapshotStateObserver. The implementation focuses on the core behaviour
needed by the Cranpose runtime:
- Tracking state object reads per logical scope.
- Reacting to snapshot apply notifications.
- Scheduling invalidation callbacks via the supplied executor.
Advanced features from the Kotlin version (derived state tracking, change coalescing, queue minimisation) are deferred
Implementations§
Source§impl SnapshotStateObserver
impl SnapshotStateObserver
Sourcepub fn new(
on_changed_executor: impl Fn(Box<dyn FnOnce() + 'static>) + 'static,
) -> Self
pub fn new( on_changed_executor: impl Fn(Box<dyn FnOnce() + 'static>) + 'static, ) -> Self
Create a new observer that schedules callbacks using on_changed_executor.
Sourcepub fn observe_reads<T, R>(
&self,
scope: T,
on_value_changed_for_scope: impl Fn(&T) + 'static,
block: impl FnOnce() -> R,
) -> R
pub fn observe_reads<T, R>( &self, scope: T, on_value_changed_for_scope: impl Fn(&T) + 'static, block: impl FnOnce() -> R, ) -> R
Observe state object reads performed while executing block.
Subsequent calls to observe_reads replace any previously recorded
observations for the provided scope. When one of the observed objects
mutates, on_value_changed_for_scope will be invoked on the executor.
Sourcepub fn begin_frame(&self)
pub fn begin_frame(&self)
Notify the observer that a new composition frame is starting.
Sourcepub fn with_no_observations<R>(&self, block: impl FnOnce() -> R) -> R
pub fn with_no_observations<R>(&self, block: impl FnOnce() -> R) -> R
Temporarily pause read observation while executing block.
Trait Implementations§
Source§impl Clone for SnapshotStateObserver
impl Clone for SnapshotStateObserver
Source§fn clone(&self) -> SnapshotStateObserver
fn clone(&self) -> SnapshotStateObserver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more