Table of Contents

Class Loadable<T>

Namespace
MiniTui
Assembly
MiniTui.dll

The state of an async load, for rendering loading, loaded and failed states (§6.4). State only changes on the app's UI thread, and every change requests a redraw.

public sealed class Loadable<T>

Type Parameters

T
Inheritance
Loadable<T>
Inherited Members

Properties

Error

The exception from the last load, while Status is Failed.

public Exception? Error { get; }

Property Value

Exception

LoadedAt

When the value was loaded, from the app's TimeProvider.

public DateTimeOffset? LoadedAt { get; }

Property Value

DateTimeOffset?

Status

Where the load cycle is.

public LoadStatus Status { get; }

Property Value

LoadStatus

Value

The last successfully loaded value. Kept while reloading and after a failure.

public T? Value { get; }

Property Value

T

Methods

Cancel()

Cancel the load in flight, if any. The status goes back to what it was before the load started.

public void Cancel()

Load(App, Func<CancellationToken, Task<T>>, CancellationToken)

Start loading, cancelling any load in flight. The fetch token is cancelled when the app stops, when lifetime is cancelled, or when this load is replaced or cancelled. A fetch exception sets Failed; it doesn't go to OnError(Func<Exception, ErrorAction>).

public void Load(App app, Func<CancellationToken, Task<T>> fetch, CancellationToken lifetime = default)

Parameters

app App
fetch Func<CancellationToken, Task<T>>
lifetime CancellationToken

Match<TResult>(Func<TResult>, Func<T?, TResult>, Func<T, TResult>, Func<Exception, TResult>)

Map the current state to a result.

public TResult Match<TResult>(Func<TResult> idle, Func<T?, TResult> loading, Func<T, TResult> loaded, Func<Exception, TResult> failed)

Parameters

idle Func<TResult>
loading Func<T, TResult>
loaded Func<T, TResult>
failed Func<Exception, TResult>

Returns

TResult

Type Parameters

TResult

Switch(Action, Action<T?>, Action<T>, Action<Exception>)

Run the action for the current state.

public void Switch(Action idle, Action<T?> loading, Action<T> loaded, Action<Exception> failed)

Parameters

idle Action
loading Action<T>
loaded Action<T>
failed Action<Exception>