ReactiveNavigationSelectionExtensions class

Namespace Runic.Navigation.ReactiveUI.Reactive in Runic.Navigation.ReactiveUI.Reactive 0.23.0

public static class ReactiveNavigationSelectionExtensions

Observes a NavigationSelection, such as a page's tabs that each keep their own stack, and changes it with a ReactiveUI command.

Remarks

Each subscription receives its initial value on the subscribing thread, inside Subscribe. Later values arrive on the model turn in which the selection raises the change; a selection change arrives on its commit turn. Use ObserveOn to move to another scheduler.

Methods

CreateCloseCommand

public static ReactiveCommand<NavigationRegion, NavigationOutcome> CreateCloseCommand(this NavigationSelection selection, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null)

Creates a command that closes the region of its parameter through NavigationSelection.RemoveAsync, such as a document tab's close button, and outputs the NavigationResult.Outcome. Every entry of the region is asked to retire first, so a guard's veto keeps the tab and is the output NavigationOutcomeKind.Rejected. For a selection that admits requests with NavigationAdmission.RejectWhileBusy, it can't execute while NavigationSelection.IsBusy is true.

Parameters

selection

The selection.

canExecute

An additional condition for the command, combined with the selection's condition, as in ReactiveNavigationSelectionExtensions.CreateSelectCommand.

outputScheduler

The scheduler of the command's output and IsExecuting, or null for ReactiveUI's main-thread scheduler.

Remarks

A rejected, superseded or failed removal is an outcome, not an exception, so ThrownExceptions reports only defects and cancellation. A region that is not in NavigationSelection.Regions when the command executes is such a defect: the execution fails with ArgumentException. The command observes the selection through a PropertyChanged handler until the command is disposed.

CreateSelectCommand

public static ReactiveCommand<int, NavigationOutcome> CreateSelectCommand(this NavigationSelection selection, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null)

Creates a command that selects the region at the command's parameter, an index in NavigationSelection.Regions, through NavigationSelection.SelectAsync, and outputs the NavigationResult.Outcome, a NavigationOutcome that a Runic View can receive. A veto keeps the selected region and is the output NavigationOutcomeKind.Rejected. For a selection that admits requests with NavigationAdmission.RejectWhileBusy, it can't execute while NavigationSelection.IsBusy is true; otherwise a later execution supersedes an earlier one that hasn't started committing, so the last tab chosen wins.

Parameters

selection

The selection.

canExecute

An additional condition for the command, combined with the selection's condition: the command can execute while both are true. null uses the selection's condition alone. Until it emits its first value, the command can't execute.

outputScheduler

The scheduler of the command's output and IsExecuting, or null for ReactiveUI's main-thread scheduler, as in ReactiveNavigationRegionExtensions.CreateBackCommand.

Remarks

A rejected, superseded or failed selection change is an outcome, not an exception, so ThrownExceptions reports only defects and cancellation. An index outside NavigationSelection.Regions is such a defect: the execution fails with ArgumentOutOfRangeException and selects nothing. The index is read against NavigationSelection.Regions when the command executes. The command observes the selection through a PropertyChanged handler until the command is disposed. A command whose owner lives as long as the selection, such as a page ViewModel's command on its own tabs, needs no disposal.

WhenIsBusyChanged

public static IObservable<bool> WhenIsBusyChanged(this NavigationSelection selection)

Observes whether a request of the selection has not completed (NavigationSelection.IsBusy), including one started by another caller. Each subscription receives the current value and then each different value observed when the selection raises a change. Unlike ReactiveNavigationSelectionExtensions.WhenIsTransitioningChanged, it stays true after the commit until the request's task completes.

Remarks

The sequence never completes; dispose the subscription to stop observing.

WhenIsTransitioningChanged

public static IObservable<bool> WhenIsTransitioningChanged(this NavigationSelection selection)

Observes whether a selection change is in flight (NavigationSelection.IsTransitioning), including one started by another caller. Each subscription receives the current value and then each different value observed when the selection raises a change. The transitions of its regions are not included.

Remarks

The sequence never completes; dispose the subscription to stop observing.

WhenRegionsChanged

public static IObservable<IReadOnlyList<NavigationRegion>> WhenRegionsChanged(this NavigationSelection selection)

Observes the selection's NavigationSelection.Regions, such as document tabs that are opened with NavigationSelection.Add and closed with NavigationSelection.RemoveAsync. Each subscription receives the current regions and then each new list: NavigationSelection.Regions is an immutable snapshot that an add or a committed removal replaces.

Remarks

The sequence never completes; dispose the subscription to stop observing.

WhenSelectedChanged

public static IObservable<NavigationRegion?> WhenSelectedChanged(this NavigationSelection selection)

Observes the selection's NavigationSelection.Selected region. Each subscription receives the selected region, or null when the selection has no regions, and then each different region.

Remarks

The sequence never completes; dispose the subscription to stop observing.

WhenSelectedIndexChanged

public static IObservable<int> WhenSelectedIndexChanged(this NavigationSelection selection)

Observes the selection's NavigationSelection.SelectedIndex. Each subscription receives the index of the selected region, or -1 when the selection has no regions, and then each different index, also when removing an earlier region moves the selected one.

Remarks

The sequence never completes; dispose the subscription to stop observing.