# ReactiveObject

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

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

```rust
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()]);
```

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

## Members

- [`new`](#function-new)
- [`property_changing`](#function-property_changing)
- [`property_changed`](#function-property_changed)
- [`extension_state`](#function-extension_state)
- [`subscribe_property_changing_events`](#function-subscribe_property_changing_events)
- [`subscribe_property_changed_events`](#function-subscribe_property_changed_events)
- [`suppress_change_notifications`](#function-suppress_change_notifications)
- [`are_change_notifications_enabled`](#function-are_change_notifications_enabled)
- [`delay_change_notifications`](#function-delay_change_notifications)
- [`are_change_notifications_delayed`](#function-are_change_notifications_delayed)
- [`thrown_exceptions`](#function-thrown_exceptions)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```

The part of a reactive object without handlers or state.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L93)

<a id="function-property_changing"></a>

### property_changing

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L105)

<a id="function-property_changed"></a>

### property_changed

```rust
fn property_changed(self: &Self) -> &Event<str>
```

The event raised when a property has changed (`PropertyChanged`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L110)

<a id="function-extension_state"></a>

### extension_state

```rust
fn extension_state(self: &Self) -> Rc<dyn IExtensionState>
```

The state of the change notifications, created at the first call (`GetState`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L121)

<a id="function-subscribe_property_changing_events"></a>

### subscribe_property_changing_events

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L143)

<a id="function-subscribe_property_changed_events"></a>

### subscribe_property_changed_events

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L149)

<a id="function-suppress_change_notifications"></a>

### suppress_change_notifications

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L156)

<a id="function-are_change_notifications_enabled"></a>

### are_change_notifications_enabled

```rust
fn are_change_notifications_enabled(self: &Self) -> bool
```

Whether change notifications are sent (`AreChangeNotificationsEnabled`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L161)

<a id="function-delay_change_notifications"></a>

### delay_change_notifications

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L171)

<a id="function-are_change_notifications_delayed"></a>

### are_change_notifications_delayed

```rust
fn are_change_notifications_delayed(self: &Self) -> bool
```

Whether change notifications are delayed (`AreChangeNotificationsDelayed`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L176)

<a id="function-thrown_exceptions"></a>

### thrown_exceptions

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/reactive_object/reactive_object.rs#L185)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `Default`
- `Debug`
- `AsRef<ReactiveObject>`

## Availability

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