Struct medea_reactive::ObservableField
source · pub struct ObservableField<D, S> { /* private fields */ }
Expand description
Reactive cell which emits all modifications to its subscribers.
Subscribing to this field modifications is done with
ObservableField::subscribe
method.
If you want to get Future
which will resolved only when an underlying
data of this field will become equal to some value, you can use
ObservableField::when
or ObservableField::when_eq
methods.
Implementations§
source§impl<D> ObservableField<D, RefCell<Vec<UniversalSubscriber<D>>>>where
D: 'static,
impl<D> ObservableField<D, RefCell<Vec<UniversalSubscriber<D>>>>where D: 'static,
sourcepub const fn new(data: D) -> Self
pub const fn new(data: D) -> Self
Returns new ObservableField
with subscribable mutations.
Also you can subscribe to concrete mutations with
ObservableField::when
and ObservableField::when_eq
methods.
source§impl<D, S> ObservableField<D, S>where
D: 'static,
S: Whenable<D>,
impl<D, S> ObservableField<D, S>where D: 'static, S: Whenable<D>,
source§impl<D: 'static> ObservableField<D, SubStore<D>>
impl<D: 'static> ObservableField<D, SubStore<D>>
sourcepub fn new(data: D) -> Self
pub fn new(data: D) -> Self
Returns new ObservableField
with subscribable mutations.
Also, you can wait for all updates processing by awaiting on
ObservableField::when_all_processed()
.
source§impl<D> ObservableField<D, SubStore<D>>where
D: Clone + 'static,
impl<D> ObservableField<D, SubStore<D>>where D: Clone + 'static,
sourcepub fn subscribe(&self) -> LocalBoxStream<'static, Guarded<D>>
pub fn subscribe(&self) -> LocalBoxStream<'static, Guarded<D>>
Returns Stream
into which underlying data updates (wrapped in the
progressable::Guarded
) will be emitted.
sourcepub fn when_all_processed(&self) -> Processed<'static> ⓘ
pub fn when_all_processed(&self) -> Processed<'static> ⓘ
Returns Future
resolving when all data updates will be processed by
subscribers.
source§impl<D> ObservableField<D, RefCell<Vec<UniversalSubscriber<D>, Global>>>where
D: Clone + 'static,
impl<D> ObservableField<D, RefCell<Vec<UniversalSubscriber<D>, Global>>>where D: Clone + 'static,
source§impl<D, S> ObservableField<D, S>where
D: PartialEq + 'static,
S: Whenable<D>,
impl<D, S> ObservableField<D, S>where D: PartialEq + 'static, S: Whenable<D>,
sourcepub fn when_eq(
&self,
should_be: D
) -> LocalBoxFuture<'static, Result<(), DroppedError>>
pub fn when_eq( &self, should_be: D ) -> LocalBoxFuture<'static, Result<(), DroppedError>>
Returns Future
which will resolve only when an underlying data of
this ObservableField
will become equal to the provided should_be
value.
source§impl<D, S> ObservableField<D, S>where
S: OnObservableFieldModification<D>,
D: Clone + PartialEq,
impl<D, S> ObservableField<D, S>where S: OnObservableFieldModification<D>, D: Clone + PartialEq,
sourcepub fn borrow_mut(&mut self) -> MutObservableFieldGuard<'_, D, S>
pub fn borrow_mut(&mut self) -> MutObservableFieldGuard<'_, D, S>
Returns MutObservableFieldGuard
which can be mutably dereferenced to
an underlying data.
If some mutation of data happens between calling
ObservableField::borrow_mut
and dropping of
MutObservableFieldGuard
, then all subscribers of this
ObservableField
will be notified about this.
Notification about mutation will be sent only if this field really
changed. This will be checked with PartialEq
implementation of
underlying data.