Interface IInteraction<TInput, TOutput>
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
Represents an interaction between collaborating application components.
public interface IInteraction<TInput, TOutput>
Type Parameters
TInput
The interaction's input type.
TOutput
The interaction's output type.
- Extension Methods
Remarks
Interactions allow collaborating components in an application to ask each other questions. Typically, interactions allow a view model to get the user's confirmation from the view before proceeding with some operation. The view provides the interaction's confirmation interface in a handler registered for the interaction.
Interactions have both an input and an output. Interaction inputs and outputs use generic type parameters. The interaction's input provides handlers the information they require to ask a question. The handler then provides the interaction with an output as the answer to the question.
Methods
Handle(TInput)
Handles an interaction and asynchronously returns the result.
IObservable<TOutput> Handle(TInput input)
Parameters
input
TInputThe input for the interaction.
Returns
- IObservable<TOutput>
An observable that ticks when the interaction completes.
Remarks
This method passes the interaction in turn to its registered handlers in reverse order of registration until one of them handles the interaction. If the interaction remains unhandled after all its registered handlers have executed, an UnhandledInteractionException<TInput, TOutput> is thrown.
RegisterHandler(Action<IInteractionContext<TInput, TOutput>>)
Registers a synchronous interaction handler.
IDisposable RegisterHandler(Action<IInteractionContext<TInput, TOutput>> handler)
Parameters
handler
Action<IInteractionContext<TInput, TOutput>>The handler.
Returns
- IDisposable
A disposable which, when disposed, will unregister the handler.
Remarks
This overload of RegisterHandler
is only useful if the handler can handle the interaction
immediately. That is, it does not need to wait for the user or some other collaborating component.
RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task>)
Registers a task-based asynchronous interaction handler.
IDisposable RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task> handler)
Parameters
handler
Func<IInteractionContext<TInput, TOutput>, Task>The handler.
Returns
- IDisposable
A disposable which, when disposed, will unregister the handler.
Remarks
This overload of RegisterHandler
is useful if the handler needs to perform some asynchronous
operation, such as displaying a dialog and waiting for the user's response.
RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>)
Registers an observable-based asynchronous interaction handler.
IDisposable RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>> handler)
Parameters
handler
Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>The handler.
Returns
- IDisposable
A disposable which, when disposed, will unregister the handler.
Type Parameters
TDontCare
The signal type.
Remarks
This overload of RegisterHandler
is useful if the handler needs to perform some asynchronous
operation, such as displaying a dialog and waiting for the user's response.