pub struct ReactiveObject { /* private fields */ }Expand description
The part of a view model that makes it a reactive object (ReactiveObject): its
PropertyChanging and PropertyChanged events, and the state of its change notifications
(suppression, delay, the Changing, Changed and ThrownExceptions observables), created
when first needed.
Deviation (DEVIATIONS.md, ReactiveUI): upstream’s base class is a part that a view model holds
as a field, named reactive by convention. The macro reactive_object!
writes the traits of a reactive object for the type, and
reactive_properties! its notifying properties. The view model is
shared as an Rc, whose handle gives the observables with the sender
(IReactiveNotifyPropertyChanged).
use ferroui_reactiveui::{reactive_object, IReactiveNotifyPropertyChanged, IReactiveObjectExt, ReactiveObject};
use ferroui_reactive::ObservableExt;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Default)]
struct Person {
reactive: ReactiveObject,
name: RefCell<String>,
}
reactive_object!(Person);
impl Person {
fn name(&self) -> String {
self.name.borrow().clone()
}
fn set_name(&self, value: String) {
self.raise_and_set_if_changed(&self.name, value, "Name");
}
}
let person = Rc::new(Person::default());
let names = Rc::new(RefCell::new(Vec::new()));
let seen = names.clone();
let _subscription = person.changed().subscribe_next(move |change| seen.borrow_mut().push(change.property_name));
person.set_name("Ada".into());
person.set_name("Ada".into());
assert_eq!(person.name(), "Ada");
assert_eq!(*names.borrow(), vec!["Name".to_owned()]);Implementations§
Source§impl ReactiveObject
impl ReactiveObject
Sourcepub fn property_changing(&self) -> &Event<str>
pub fn property_changing(&self) -> &Event<str>
The event raised when a property is about to change (PropertyChanging). It is raised
once it has a handler, and follows the suppression and the delay of the notifications.
Sourcepub fn property_changed(&self) -> &Event<str>
pub fn property_changed(&self) -> &Event<str>
The event raised when a property has changed (PropertyChanged).
Sourcepub fn extension_state(&self) -> Rc<dyn IExtensionState>
pub fn extension_state(&self) -> Rc<dyn IExtensionState>
The state of the change notifications, created at the first call (GetState).
Sourcepub fn subscribe_property_changing_events(&self)
pub fn subscribe_property_changing_events(&self)
Makes changes raise the PropertyChanging event (SubscribePropertyChangingEvents). A
change does it by itself when the event has a handler.
Sourcepub fn subscribe_property_changed_events(&self)
pub fn subscribe_property_changed_events(&self)
Makes changes raise the PropertyChanged event (SubscribePropertyChangedEvents). A
change does it by itself when the event has a handler.
Sourcepub fn suppress_change_notifications(&self) -> Rc<dyn IDisposable>
pub fn suppress_change_notifications(&self) -> Rc<dyn IDisposable>
Stops all change notifications, the events and the observables, until the result is
disposed (SuppressChangeNotifications). The calls nest: the notifications resume when
every result is disposed.
Sourcepub fn are_change_notifications_enabled(&self) -> bool
pub fn are_change_notifications_enabled(&self) -> bool
Whether change notifications are sent (AreChangeNotificationsEnabled).
Sourcepub fn delay_change_notifications(&self) -> Rc<dyn IDisposable>
pub fn delay_change_notifications(&self) -> Rc<dyn IDisposable>
Keeps the change notifications until the result is disposed, then sends the last one of
each property, in the order of those last notifications (DelayChangeNotifications). The
calls nest.
Sourcepub fn are_change_notifications_delayed(&self) -> bool
pub fn are_change_notifications_delayed(&self) -> bool
Whether change notifications are delayed (AreChangeNotificationsDelayed).
Sourcepub fn thrown_exceptions(&self) -> Rc<dyn IObservable<ObservableError>>
pub fn thrown_exceptions(&self) -> Rc<dyn IObservable<ObservableError>>
The errors of the subscribers of the change observables (ThrownExceptions); the same
observable at every call.