# ViewModelActivator

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/activation/struct-viewmodelactivator/

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

```rust
struct ViewModelActivator
```

The helper a view model holds to take part in activation (`ViewModelActivator`).

The view calls it when it comes on screen: the view model then sets up what should only live
while it is shown, such as subscriptions to global objects, and tears it down when the view
leaves. Register what to do with
`when_activated`.

Activation is not loading: a view is activated when it enters the visual tree and deactivated
when it leaves it, which matters for views that are recycled. Activations are counted: the
view model is deactivated when every activation has been matched by a deactivation.

Create the activator once, in the most basic view model of a hierarchy, and let the others use
it. The view that shows the view model must set up its own activation
(`ViewForMixins`).

The activator is a shared handle: a clone is the same activator.

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

## Members

- [`new`](#function-new)
- [`activated`](#function-activated)
- [`deactivated`](#function-deactivated)
- [`activate`](#function-activate)
- [`deactivate`](#function-deactivate)
- [`deactivate_with`](#function-deactivate_with)

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

### new

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

An activator without blocks, not activated (`ViewModelActivator()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L74)

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

### activated

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

Ticks each time the activator is activated (`Activated`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L87)

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

### deactivated

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

Ticks each time the activator is deactivated (`Deactivated`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L92)

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

### activate

```rust
fn activate(self: &Self) -> Rc<dyn IDisposable>
```

Activates the view model: on the first activation, runs the registered blocks and ticks
`activated` (`Activate()`). The view calls it when it is activated; a
unit test calls it to simulate that.

Returns a disposable that calls `deactivate`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L101)

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

### deactivate

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

Deactivates the view model, following the count of activations: the blocks' disposables
are disposed and `deactivated` ticks when the last activation is
matched (`Deactivate()`). The view calls it when it is deactivated.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L127)

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

### deactivate_with

```rust
fn deactivate_with(self: &Self, ignore_ref_count: bool)
```

`deactivate`; with `ignore_ref_count`, the view model is deactivated
even when it was activated more than once (`Deactivate(bool)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/activation/view_model_activator.rs#L133)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `Clone`
- `Default`
- `Debug`
- `PartialEq`
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)

## Availability

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