ViewQuestion<TInput, TOutput> class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public sealed class ViewQuestion<TInput, TOutput>

A question a ViewModel asks its web View and waits for, such as a confirmation, in either MVVM flavor. It is the flavor-neutral counterpart of a ReactiveUI Interaction<TInput, TOutput>: on the page it is the generated client.interactions.<name>.handle((input, { signal }) => answer).

Type parameters

TInput

The question, a bridge value.

TOutput

The answer, a bridge value.

Remarks

Expose it as a get-only property. ViewQuestion.AskAsync asks the page in the same scopes as an interaction: inside a command that a page invoked, that page's presentation; in the window scope (a close decision, a menu-bar command, RunicInteractionInvocation.EnterWindow), the one presentation of the window that handles it. When no page can answer, it runs the fallback, or fails with RunicInteractionUnhandledException.

public ViewQuestion<DiscardRequest, bool> ConfirmDiscard { get; } = new((_, _) => ValueTask.FromResult(false));

[RelayCommand]
private async Task DiscardAsync(CancellationToken token)
{
    if (await ConfirmDiscard.AskAsync(new DiscardRequest(Title), token)) Reset();
}

Constructors

ViewQuestion

public ViewQuestion(Func<TInput, CancellationToken, ValueTask<TOutput>>? fallback = null, TimeSpan? timeout = null)

Creates a view question.

Parameters

fallback

Answers when no page can; without one, an unanswered question fails.

timeout

How long a page may take to answer: at most 24 hours, by default two minutes, or Timeout.InfiniteTimeSpan for no deadline, as for a question a person answers. Without a deadline the question still ends when ViewQuestion.AskAsync's token or the asking command is cancelled, when the page unmounts or disconnects and when the Window closes. A page of @runic-artifex/views before 0.23 aborts its handler after ten minutes regardless.

Exceptions

ArgumentOutOfRangeException

timeout is not positive or exceeds 24 hours, and is not Timeout.InfiniteTimeSpan.

Properties

Timeout

public TimeSpan? Timeout { get; }

How long a page may take to answer, Timeout.InfiniteTimeSpan for no deadline, or null for the default of two minutes.

Methods

AskAsync

public Task<TOutput> AskAsync(TInput input, CancellationToken cancellationToken = default)

Asks the page and returns its answer, or the fallback's when no page can answer.

Parameters

input

The question.

cancellationToken

Cancels the question; the page's handler is aborted.

Returns

The answer.

Exceptions

RunicInteractionUnhandledException

No page can answer and there is no fallback.

RunicInteractionCancelledException

The page cancelled, or its presentation closed.

RunicInteractionTimeoutException

The page did not answer within ViewQuestion.Timeout.

RunicInteractionOutputException

The page's answer does not match the contract.

OperationCanceledException

cancellationToken was cancelled.