# ReactiveProperty

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/reactive_property/struct-reactiveproperty/

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

```rust
struct ReactiveProperty<T: Clone + PartialEq + 'static>
```

A property that holds a value, notifies its changes to its observers and through
`PropertyChanged`, and validates it (`ReactiveProperty<T>`).

The handle is shared: clones are the same property, as the object of .NET is a reference.
Subscribers receive the current value when they subscribe (unless the property skips it), then
each change, on the scheduler of the property. Validators turn the values into errors, which
the property aggregates and reports through `INotifyDataErrorInfo`, `HasErrors` and
`observe_error_changed`. Disposing the property ends its
subscriptions.

Deviation (DEVIATIONS.md, ReactiveUI): upstream derives the class from `ReactiveObject`. The
handle holds a [`ReactiveObject`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/struct-reactiveobject/) and implements [`IReactiveObject`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/trait-ireactiveobject/) itself, so it raises its
`PropertyChanged` and `PropertyChanging` events as a reactive object does.

Deviation (DEVIATIONS.md, ReactiveUI): upstream's constructors and its `Create` factories take
the same arguments; both are the constructors here. A value of a type with no "null" is held as
it is, and `ReactiveProperty<Option<T>>` holds an optional value.

```
use ferroui_reactive::concurrency::ImmediateScheduler;
use ferroui_reactive::ObservableExt;
use ferroui_reactiveui::ReactiveProperty;
use std::cell::RefCell;
use std::rc::Rc;

let name = ReactiveProperty::with_scheduler(String::new(), Some(ImmediateScheduler::instance()), false, false)
    .add_validation_error(|name: String| if name.is_empty() { Some("required") } else { None });
let seen = Rc::new(RefCell::new(Vec::new()));
let log = seen.clone();
let _subscription = name.subscribe_next(move |value| log.borrow_mut().push(value));
assert!(name.has_errors());
name.set_value("Ada".to_owned());
assert!(!name.has_errors());
assert_eq!(*seen.borrow(), vec![String::new(), "Ada".to_owned()]);
```

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

## Members

- [`new`](#function-new)
- [`with_value`](#function-with_value)
- [`with_options`](#function-with_options)
- [`with_scheduler`](#function-with_scheduler)
- [`is_disposed`](#function-is_disposed)
- [`value`](#function-value)
- [`set_value`](#function-set_value)
- [`has_errors`](#function-has_errors)
- [`observe_error_changed`](#function-observe_error_changed)
- [`observe_has_errors`](#function-observe_has_errors)
- [`add_validation_error_observable`](#function-add_validation_error_observable)
- [`add_validation_error_observable_with`](#function-add_validation_error_observable_with)
- [`add_validation_error`](#function-add_validation_error)
- [`add_validation_error_with`](#function-add_validation_error_with)
- [`add_validation_error_async`](#function-add_validation_error_async)
- [`add_validation_error_async_with`](#function-add_validation_error_async_with)
- [`dispose`](#function-dispose)
- [`check_validation`](#function-check_validation)
- [`refresh`](#function-refresh)
- [`get_errors`](#function-get_errors)
- [`errors_changed`](#function-errors_changed)

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

### new

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

A property of the default value, which notifies on the task pool scheduler, gives the
current value to subscribers and skips the values equal to the last one
(`ReactiveProperty()`, `Create()`).

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

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

### with_value

```rust
fn with_value(initial_value: T) -> Self
```

A property of `initial_value`, with the defaults of `new`
(`ReactiveProperty(T)`, `Create(T)`).

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

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

### with_options

```rust
fn with_options(initial_value: T, skip_current_value_on_subscribe: bool, allow_duplicate_values: bool) -> Self
```

A property of `initial_value` that notifies on the task pool scheduler
(`ReactiveProperty(T, bool, bool)`, `Create(T, bool, bool)`): with
`skip_current_value_on_subscribe`, a subscriber does not receive the current value when it
subscribes; with `allow_duplicate_values`, setting a value equal to the current one notifies
it again.

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

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

### with_scheduler

```rust
fn with_scheduler(initial_value: T, scheduler: Option<Rc<dyn IScheduler>>, skip_current_value_on_subscribe: bool, allow_duplicate_values: bool) -> Self
```

A property of `initial_value` that notifies on `scheduler`, or on the task pool scheduler
when it is `None` (`ReactiveProperty(T, ISequencer?, bool, bool)`,
`Create(T, ISequencer, bool, bool)`).

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

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

### is_disposed

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

Whether the property was disposed (`IsDisposed`).

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

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

### value

```rust
fn value(self: &Self) -> T
```

The value (`Value { get; }`).

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

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

### set_value

```rust
fn set_value(self: &Self, value: T)
```

Sets the value (`Value { set; }`): a value equal to the current one notifies it again only
when the property allows duplicate values; another one is stored, validated, notified to
the subscribers and raises `PropertyChanged` for `Value`.

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

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

### has_errors

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

Whether the property has validation errors (`HasErrors`).

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

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

### observe_error_changed

```rust
fn observe_error_changed(self: &Self) -> Rc<dyn IObservable<Option<DataErrors>>>
```

The errors of the property each time they change, starting with the current ones
(`ObserveErrorChanged`); `None` when it has none. It completes when the property is
disposed.

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

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

### observe_has_errors

```rust
fn observe_has_errors(self: &Self) -> Rc<dyn IObservable<bool>>
```

Whether the property has validation errors, each time its errors change, starting with
the current state (`ObserveHasErrors`).

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

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

### add_validation_error_observable

```rust
fn add_validation_error_observable<R: IntoValidationErrors + 'static>(self: &Self, validator: impl Fn(Rc<dyn IObservable<T>>) -> Rc<dyn IObservable<R>> + 'static) -> Self
```

Adds a validator that reads the values as a sequence and reports their errors as a
sequence (`AddValidationError(Func<IObservable<T>, IObservable<IEnumerable?>>)` and its
`string` form); the current value is validated at once. Returns the property, to chain the
calls.

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

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

### add_validation_error_observable_with

```rust
fn add_validation_error_observable_with<R: IntoValidationErrors + 'static>(self: &Self, validator: impl Fn(Rc<dyn IObservable<T>>) -> Rc<dyn IObservable<R>> + 'static, ignore_initial_error: bool) -> Self
```

Adds a validator that reads the values as a sequence and reports their errors as a
sequence; with `ignore_initial_error`, the current value is not validated
(`AddValidationError(Func<IObservable<T>, IObservable<IEnumerable?>>, bool)` and its
`string` form). The errors of all the validators are aggregated, and `ErrorsChanged` is
raised each time they are reported.

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

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

### add_validation_error

```rust
fn add_validation_error<R: IntoValidationErrors + 'static>(self: &Self, validator: impl Fn(T) -> R + 'static) -> Self
```

Adds a validator of each value (`AddValidationError(Func<T, IEnumerable?>)` and
`AddValidationError(Func<T, string?>)`); the current value is validated at once.

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

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

### add_validation_error_with

```rust
fn add_validation_error_with<R: IntoValidationErrors + 'static>(self: &Self, validator: impl Fn(T) -> R + 'static, ignore_initial_error: bool) -> Self
```

Adds a validator of each value; with `ignore_initial_error`, the current value is not
validated (`AddValidationError(Func<T, IEnumerable?>, bool)` and
`AddValidationError(Func<T, string?>, bool)`).

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

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

### add_validation_error_async

```rust
fn add_validation_error_async<R: IntoValidationErrors + Clone + 'static, Fut: Future<Output = Result<R, ObservableError>> + 'static>(self: &Self, validator: impl Fn(T) -> Fut + 'static) -> Self
```

Adds an asynchronous validator of each value (`AddValidationError(Func<T, Task<IEnumerable?>>)`
and `AddValidationError(Func<T, Task<string?>>)`); the current value is validated at once.
The validator gives a future of a `Result<R, ObservableError>`, which runs as a task of the
thread (`ferroui_system::task::spawn_local`).

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

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

### add_validation_error_async_with

```rust
fn add_validation_error_async_with<R: IntoValidationErrors + Clone + 'static, Fut: Future<Output = Result<R, ObservableError>> + 'static>(self: &Self, validator: impl Fn(T) -> Fut + 'static, ignore_initial_error: bool) -> Self
```

Adds an asynchronous validator of each value; with `ignore_initial_error`, the current
value is not validated (`AddValidationError(Func<T, Task<IEnumerable?>>, bool)` and
`AddValidationError(Func<T, Task<string?>>, bool)`). The results of the tasks are reported
as they come; a task that fails, or a validator that panics, ends the validation of the
property, as its error goes to the validation pipeline.

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

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

### dispose

```rust
fn dispose(self: &Self)
```

Ends the subscriptions of the property and completes its sequences (`Dispose`). A second
call does nothing.

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

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

### check_validation

```rust
fn check_validation(self: &Self)
```

Validates the current value again (`CheckValidation`).

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

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

### refresh

```rust
fn refresh(self: &Self)
```

Notifies the current value again, to the validators and to the subscribers, even when it
did not change, and raises `PropertyChanged` for `Value` (`Refresh`).

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

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

### get_errors

```rust
fn get_errors(self: &Self, _property_name: Option<&str>) -> Option<DataErrors>
```

The errors of the property, whatever `property_name` is (`GetErrors(string?)`); `None` when
it has none. `INotifyDataErrorInfo::get_errors` gives an empty list instead.

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

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

### errors_changed

```rust
fn errors_changed(self: &Self) -> &Event<DataErrorsChangedEventArgs>
```

The event raised each time the validators report errors (`ErrorsChanged`).

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

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`IReactiveObjectExt`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/trait-ireactiveobjectext/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- [`SubscribeGuard<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-subscribeguard/)
- `Clone`
- `PartialEq`
- `Debug`
- `Default`
- [`IObservable<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-iobservable/)
- [`ObservableExt<T>`](/docs/0.5.0/api/ferroui-base/reactive/trait-observableext/)
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)
- [`ICancelable`](/docs/0.5.0/api/ferroui-reactive/disposables/trait-icancelable/)
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)
- [`INotifyPropertyChanging`](/docs/0.5.0/api/ferroui-system/component_model/trait-inotifypropertychanging/)
- [`IEnableLogger`](/docs/0.5.0/api/ferroui-splat/logging/trait-ienablelogger/)
- [`IReactiveObject`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/trait-ireactiveobject/)
- [`IHandleObservableErrors`](/docs/0.5.0/api/ferroui-reactiveui/interfaces/trait-ihandleobservableerrors/)
- [`INotifyDataErrorInfo`](/docs/0.5.0/api/ferroui-base/data/model/trait-inotifydataerrorinfo/)
- [`IReactiveProperty<T>`](/docs/0.5.0/api/ferroui-reactiveui/reactive_property/trait-ireactiveproperty/)
- [`ReactivePropertyMixins`](/docs/0.5.0/api/ferroui-reactiveui/reactive_property/trait-reactivepropertymixins/)

## Availability

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