Summary
- Namespace
- ReactiveUI
- Interfaces
-
- IReactiveCommand
<TParam, TResult> - IObservable
<TResult> - IReactiveCommand
- IDisposable
- I
Handle Observable Errors - ICommand
- IReactiveCommand
- Base Types
-
- object
- Derived Types
Syntax
public abstract class ReactiveCommandBase<TParam, TResult> : IReactiveCommand<TParam, TResult>,
IObservable<TResult>, IReactiveCommand, IDisposable, IHandleObservableErrors, ICommand
Remarks
This class extends ReactiveCommand
and adds generic type parameters for the parameter values passed
into command execution, and the return values of command execution.
Because the result type is known by this class, it can implement IObservable<T>
. However, the implementation
is defined as abstract, so subclasses must provide it.
Reactive commands encapsulate the behavior of running some execution logic and then surfacing the results on the UI
thread. Importantly, no scheduling is performed against input observables (the canExecute
and execution pipelines).
To create an instance of ReactiveCommand
, call one of the static creation methods defined by this class.
ReactiveUI.ReactiveCommand.Create(Action,System.Nullable{IObservable{System.Boolean}},System.Nullable{IScheduler})
can be used when your execution logic is synchronous.
ReactiveCommand.CreateFromObservable and
ReactiveCommand.CreateFromTask (and overloads) can be used for asynchronous
execution logic. Optionally, you can provide an observable that governs the availability of the command for execution,
as well as a scheduler to which events will be delivered.
The CanExecute
property provides an observable that can be used to determine whether the command is
eligible for execution. The value of this observable is determined by both the canExecute
observable provided
during command creation, and the current execution status of the command. A command that is already executing will
yield false
from its CanExecute
observable regardless of the canExecute
observable provided
during command creation.
The IsExecuting
property provides an observable whose value indicates whether the command is currently
executing. This can be a useful means of triggering UI, such as displaying an activity indicator whilst a command is
executing.
As discussed above, you are under no obligation to somehow incorporate this into your canExecute
observable
because that is taken care of for you. That is, if the value of IsExecuting
is true
, the value of
CanExecute
will be false
. However, if the value of CanExecute
is false
, that does not imply
the value of IsExecuting
is true
.
Any errors in your command's execution logic (including any canExecute
observable you choose to provide) will be
surfaced via the ThrownExceptions
observable. This gives you the opportunity to handle the error before
it triggers a default handler that tears down the application. For example, you might use this as a means of alerting
the user that something has gone wrong executing the command.
For the sake of convenience, all ReactiveCommand
instances are also implementations of ICommand
.
This allows you to easily integrate instances of ReactiveCommand
into platforms that understands ICommand
natively (such as WPF and UWP).
Type Parameters
Name | Description |
---|---|
TParam | The type of parameter values passed in during command execution. |
TResult | The type of the values that are the result of command execution. |
Properties
Name | Value | Summary |
---|---|---|
CanExecute | IObservable |
Gets an observable whose value indicates whether the command can currently execute.
|
IsExecuting | IObservable |
Gets an observable whose value indicates whether the command is currently executing.
|
ThrownExceptions | IObservable |
Gets a observable which will fire whenever an exception would normally terminate ReactiveUI
internal state.
|
Methods
Name | Value | Summary |
---|---|---|
Dispose |
void | |
Dispose |
void |
Disposes of the managed resources.
|
Execute |
IObservable |
Gets an observable that, when subscribed, executes this command.
|
Execute |
IObservable |
Gets an observable that, when subscribed, executes this command.
|
ICommandCanExecute |
bool |
Will be called by the methods from the ICommand interface.
This method is called when the Command should evaluate if it can execute.
|
ICommandExecute |
void |
Will be called by the methods from the ICommand interface.
This method is called when the Command should execute.
|
OnCanExecuteChanged |
void |
Will trigger a event when the CanExecute condition has changed.
|
Subscribe |
IDisposable |
Subscribes to execution results from this command.
|