public static class ReactiveLeaveConfirmation Creates a LeaveConfirmation that asks through a ReactiveUI interaction.
Methods
WithInteraction
public static LeaveConfirmation WithInteraction<TPrompt>(IInteraction<TPrompt, bool> interaction, Func<TPrompt> prompt, Func<bool> hasUnsavedChanges, Action? discard = null, bool askOnRetain = false) Creates a LeaveConfirmation whose question is interaction.Handle(prompt()): a handler that sets true lets the entry depart, false keeps it. The presentation answers it natively: a WPF View with RegisterHandler in WhenActivated, a Runic web View with the generated client's interactions.<name>.handle, a test with RegisterHandler(context => context.SetOutput(true)).
Type parameters
TPromptThe interaction's input, which a web View receives as typed data.
Parameters
interactionThe interaction, typically a get-only property of the ViewModel.
promptCreates the question's input. It is called inside a model turn, once per question.
hasUnsavedChangesReturns whether leaving would lose changes. It is called inside a model turn.
discardDiscards the changes. It runs in the commit turn of a confirmed departure, at most once per yes.
askOnRetainWhether to ask when the entry is only retained, as in
LeaveConfirmation.
Remarks
Every LeaveConfirmation rule applies: a retaining departure is allowed without asking unless askOnRetain is set; a yes stands while the departure it allowed is unsettled; nothing is asked without unsaved changes; discard runs at most once per yes, in the commit turn.
When the departure is superseded, cancelled or its navigator closes, the guard's token disposes the Handle subscription and the guard returns at once. ReactiveUI lets a running .NET handler finish; a Runic web View's handler receives an aborted signal, because a browser request made by a navigation hook ends with the hook's token (RunicNavigator.HookCancellationToken).
The departure fails closed: when no handler answers, ReactiveUI's UnhandledInteractionException fails the navigation with NavigationPhase.Guarding, and the navigator logs NavigationGuardFailed (event 1060) with that exception type as ErrorType. A handler that throws, or a browser that disconnects while asked, fails it the same way. The entry stays current.
The question is asked in the guard, outside commit turns, where the guard runs: on the dispatcher for a WPF navigator, in a turn of its own under RunicModelContext, which schedules hooks too.
A Runic web View's handler answers a departure that its own window starts: a bridged command of any View in that window, such as the page's Close or the shell's Back, asks the presentation mounted by the same browser connection; a guarded window close asks the window's one presentation with a mounted handler. A departure that .NET code starts outside both, such as a timer's navigation, reaches only .NET handlers. Handlers run latest first, as in ReactiveUI: one registered after the View attached, such as a WPF View's WhenActivated handler, answers before the web View, and a fallback registered in the ViewModel's constructor answers only when no View does.