ReactiveObject
struct · ferroui-reactiveui · v0.5.0
struct ReactiveObject
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()]);
Members
newproperty_changingproperty_changedextension_statesubscribe_property_changing_eventssubscribe_property_changed_eventssuppress_change_notificationsare_change_notifications_enableddelay_change_notificationsare_change_notifications_delayedthrown_exceptions
new
fn new() -> Self
The part of a reactive object without handlers or state.
property_changing
fn property_changing(self: &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.
property_changed
fn property_changed(self: &Self) -> &Event<str>
The event raised when a property has changed (PropertyChanged).
extension_state
fn extension_state(self: &Self) -> Rc<dyn IExtensionState>
The state of the change notifications, created at the first call (GetState).
subscribe_property_changing_events
fn subscribe_property_changing_events(self: &Self)
Makes changes raise the PropertyChanging event (SubscribePropertyChangingEvents). A
change does it by itself when the event has a handler.
subscribe_property_changed_events
fn subscribe_property_changed_events(self: &Self)
Makes changes raise the PropertyChanged event (SubscribePropertyChangedEvents). A
change does it by itself when the event has a handler.
suppress_change_notifications
fn suppress_change_notifications(self: &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.
are_change_notifications_enabled
fn are_change_notifications_enabled(self: &Self) -> bool
Whether change notifications are sent (AreChangeNotificationsEnabled).
delay_change_notifications
fn delay_change_notifications(self: &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.
are_change_notifications_delayed
fn are_change_notifications_delayed(self: &Self) -> bool
Whether change notifications are delayed (AreChangeNotificationsDelayed).
thrown_exceptions
fn thrown_exceptions(self: &Self) -> Rc<dyn IObservable<ObservableError>>
The errors of the subscribers of the change observables (ThrownExceptions); the same
observable at every call.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyDefaultDebugAsRef<ReactiveObject>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.