reactive_object
macro · ferroui-reactiveui · v0.5.0
macro_rules! reactive_object
Makes a type that holds a ReactiveObject a reactive object: writes its
INotifyPropertyChanged (with as_notify_property_changing), INotifyPropertyChanging,
IEnableLogger, IReactiveObject and
IHandleObservableErrors.
reactive_object!(Type) uses the field reactive; reactive_object!(Type, field) names the
field. The field is a ReactiveObject or a ReactiveRecord. The type
is not generic.
The impls cannot be blanket impls over a trait: Rust's orphan rule forbids implementing the
traits of ferroui-system for every type that holds the part, so a macro writes them, as a
derived base class gets them upstream.
use ferroui_reactiveui::{reactive_object, IReactiveObject, ReactiveObject};
use ferroui_system::component_model::INotifyPropertyChanged;
use std::cell::RefCell;
use std::rc::Rc;
struct Model {
state: ReactiveObject,
}
reactive_object!(Model, state);
let model = Model { state: ReactiveObject::new() };
let raised = Rc::new(RefCell::new(Vec::<String>::new()));
let log = raised.clone();
model.property_changed().add(Rc::new(move |name: &str| log.borrow_mut().push(name.to_owned())));
model.raise_property_changed("Title");
assert_eq!(*raised.borrow(), vec!["Title".to_owned()]);
assert!(model.as_notify_property_changing().is_some());
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.