AutoPersistChangeSetMixins
trait · ferroui-reactiveui · v0.5.0
trait AutoPersistChangeSetMixins<T: IReactiveObject>
ActOnEveryObject of a stream of change sets (the extension members of
IObservable<IReactiveChangeSet<TItem>> in AutoPersistHelperMixins).
use ferroui_reactive::subjects::Subject;
use ferroui_reactiveui::{reactive_object, AutoPersistChangeSetMixins, ReactiveChange, ReactiveChangeReason, ReactiveChangeSet, ReactiveObject};
use ferroui_system::IObserver;
use std::cell::Cell;
use std::rc::Rc;
#[derive(Default)]
pub struct Item {
reactive: ReactiveObject,
}
reactive_object!(Item);
let change_sets = Subject::<ReactiveChangeSet<Rc<Item>>>::new();
let adds = Rc::new(Cell::new(0));
let added = adds.clone();
let subscription = change_sets.as_observable().act_on_every_object(move |_| added.set(added.get() + 1), |_| {});
let item = Rc::new(Item::default());
change_sets.on_next(ReactiveChangeSet::new(vec![ReactiveChange::new(ReactiveChangeReason::Add, item, None, 0, -1)]));
assert_eq!(adds.get(), 1);
subscription.dispose();
Members
act_on_every_object
fn act_on_every_object(self: &Self, on_add: impl Fn(Rc<T>) -> () + 'static, on_remove: impl Fn(Rc<T>) -> () + 'static) -> Rc<dyn IDisposable>
Calls on_add for each item added and on_remove for each item removed by the change sets
of the stream: a replacement removes the replaced item and adds the new one, a refresh
removes the item and adds it again, and a move does nothing. The errors and the end of the
stream are ignored. Disposing the result stops watching (ActOnEveryObject(Action<TItem>, Action<TItem>)).
Trait implementations
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.