Skip to main content

ViewLifetime class

Namespace: Arlecchino.Navigation · Assembly: Arlecchino

How long the screen is on. Take it in a view's constructor to tie background work and subscriptions to the screen, and navigating away cancels the token and releases everything registered here.

public sealed class ViewLifetime : IDisposable

Implements IDisposable

Constructors

MemberSummary
ViewLifetime()Creates the lifetime. Resolved once per screen.

Properties

MemberSummary
ClosingCanceled when the screen goes away, to be passed into work started by the view. It stays readable afterward, so work coming back late can see the screen has gone.

Methods

MemberSummary
Dispose()Cancels the token and releases everything tracked. Called by the container when the screen's scope ends; there is no need to call it from a view.
Loading<T>(T)Creates background state that stops when the screen does — the usual way to load something for one screen.
OnClose(Action)Runs something when the screen goes away, before the scope is released.
Track<T>(T)Hands something over to the screen's lifetime — a subscription, a timer, a file handle. It is disposed when the screen goes away, in the order it was handed over.

Constructors in detail

ViewLifetime()

public ViewLifetime();

Creates the lifetime. Resolved once per screen.

Properties in detail

Closing

public CancellationToken Closing { get; }

Canceled when the screen goes away, to be passed into work started by the view. It stays readable afterward, so work coming back late can see the screen has gone.

Type CancellationToken

Methods in detail

Dispose()

public void Dispose();

Cancels the token and releases everything tracked. Called by the container when the screen's scope ends; there is no need to call it from a view.

Loading<T>(T)

public AsyncAtom<T> Loading<T>(T initial);

Creates background state that stops when the screen does — the usual way to load something for one screen.

Parameters

NameTypeDescription
initialTWhat to hold until the first load finishes.

Returns AsyncAtom<T> — The state, already tied to this screen.

OnClose(Action)

public void OnClose(Action action);

Runs something when the screen goes away, before the scope is released.

Parameters

NameTypeDescription
actionActionWhat to run.

Track<T>(T)

public T Track<T>(T resource);

Hands something over to the screen's lifetime — a subscription, a timer, a file handle. It is disposed when the screen goes away, in the order it was handed over.

Parameters

NameTypeDescription
resourceTWhat to look after.

Returns T — The same object, so it can be assigned in one line.