Interaction
struct · ferroui-reactiveui · v0.5.0
struct Interaction<I, O>
An interaction between collaborating parts of an application (Interaction<TInput, TOutput>).
It is a shared handle: clones are the same interaction.
The handlers run in the reverse order of their registration: the handler registered last has
the first chance to handle a question. A handler need not handle it, and leaves it to the next
one; handle fails with an UnhandledInteractionError when no handler
set an output.
Deviation (DEVIATIONS.md, ReactiveUI): upstream's virtual members (Handle, GenerateContext)
and protected GetHandlers serve subclasses; Rust has none, so handle and
get_handlers are public and the context is always an
InteractionContext. A handler that throws upstream faults the question; here a handler that
panics does, its panic caught as a PanicError.
Members
newwith_schedulerregister_handlerregister_handler_taskregister_handler_observablehandlewhen_handledget_handlers
new
fn new() -> Self
An interaction that invokes its handlers on the thread that asks (Interaction()).
with_scheduler
fn with_scheduler(handler_scheduler: Option<Rc<dyn IScheduler>>) -> Self
An interaction that invokes each handler on handler_scheduler, such as the main thread's;
None invokes them on the thread that asks (Interaction(IScheduler?)).
register_handler
fn register_handler(self: &Self, handler: impl Fn(Rc<dyn IInteractionContext<I, O>>) -> () + 'static) -> Rc<dyn IDisposable>
Registers a synchronous handler; disposing the result unregisters it
(RegisterHandler(Action<IInteractionContext<TInput, TOutput>>)).
register_handler_task
fn register_handler_task<Fut: Future<Output = Result<(), ObservableError>> + 'static>(self: &Self, handler: impl Fn(Rc<dyn IInteractionContext<I, O>>) -> Fut + 'static) -> Rc<dyn IDisposable>
Registers an asynchronous handler: the future it gives runs as a task of the thread, and
the next handler runs when it has ended (RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task>)). The flatten() of a Shared or of a oneshot receiver is such a
future.
register_handler_observable
fn register_handler_observable<D: 'static>(self: &Self, handler: impl Fn(Rc<dyn IInteractionContext<I, O>>) -> Rc<dyn IObservable<D>> + 'static) -> Rc<dyn IDisposable>
Registers a handler that finishes when the observable it gives ends; its values are ignored,
and its error faults the question (RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>)).
handle
fn handle(self: &Self, input: I) -> Shared<Result<O, ObservableError>>
Runs the handlers, latest registered first, until one sets an output, and gives a task of
that output, the Shared of its result (flatten() is a future of it); the task fails
with an UnhandledInteractionError when no handler set one (Handle(TInput)).
when_handled
fn when_handled(self: &Self, input: I) -> Rc<dyn IObservable<O>>
Asks the question as an observable: each subscription runs handle once,
then notifies the output and ends, or fails with an UnhandledInteractionError
(WhenHandled(TInput)). Disposing the subscription drops the output; a handler that is
running still finishes.
get_handlers
fn get_handlers(self: &Self) -> Vec<InteractionHandler<I, O>>
A copy of the registered handlers, earliest first (GetHandlers()).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedClonePartialEqDebugDefaultIInteraction<I, O>InteractionValue
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.