# reactive_object

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/macro-reactive_object/

**macro** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
macro_rules! reactive_object
```

Makes a type that holds a [`ReactiveObject`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/struct-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`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/struct-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());
```

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L250)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
