UNPKG

@awesome-nodes/mvvm

Version:

Application development framework using the *model* *view* *view-model* design pattern.

90 lines (89 loc) 3.71 kB
import { EventArgs, IEvent } from '@awesome-nodes/object'; import { Disposable } from "./Disposable"; import { ObjectModel } from "./ObjectModel"; import { Observable } from 'rxjs'; import { Nullable } from 'simplytyped'; export interface IPartialActionObserver<T, TEventArgs extends EventArgs = EventArgs> { init?: () => TEventArgs; next?: (value: T) => TEventArgs; error?: (error: Error) => void; complete?: () => TEventArgs; } /** * A object model utility for watching observables using command pattern style handler functions * which are bound to the provided {@see ActionObserver.#_thisArg} argument. * @template T */ export declare class ActionObserver<T> extends Disposable { #private; private readonly _defaultResult?; /** * Returns the observable returned from the last observed action. * @description Subscribe to observe the latest observed action. */ get action(): Nullable<Observable<T>>; /** * Returns the last 'next' result from the last observed action. * @description Subscribe to receive the final 'next' result of any called action. */ get actionResult(): Observable<T>; /** * Returns the last 'next' result value from the last observed action. * @description Bind to receive the final 'next' result value of any called action. */ get actionResultValue(): T; /** * Returns a boolean value indicating weather this instance has ever received a result * other than the `ActionObserver._defaultResult` from an action. */ get actionResultAvailable(): boolean; /** * Returns the 'next' result from the currently observed action. * @description Subscribe to receive the 'next' result of any called action. */ get nextResult(): Observable<T>; /** * Returns the 'next' result value from the currently observed action. * @description Bind to receive the 'next' result value of any called action. */ get nextValue(): T; /** * Returns a boolean value indicating weather this instance has ever received a result * other than the `ActionObserver._defaultResult` from an action. */ get nextResultAvailable(): boolean; /** * Sets a command pattern style function used to observe {@link NextObserver.next} events. * @param {IEvent<ObjectModel>} value */ set onProgress(value: IEvent<ObjectModel>); /** * Sets an error handler function used to observe {@link ErrorObserver.error} events. * Note: The error handler function is not bound to this instance. * @param {IEvent<ObjectModel>} value */ set onError(value: (e: Error) => void); /** * Sets a command pattern style function used to observe {@link CompletionObserver.complete} events. * @param {IEvent<ObjectModel>} value */ set onComplete(value: IEvent<ObjectModel>); /** * * @param _thisArg If provided, all observer functions are invoked on except the error observer. * @param _defaultResult if provided, it will be used as default value for the */ constructor(_thisArg?: ObjectModel, _defaultResult?: T | undefined); /** * Observes actions by additionally using a provided next observer function or `PartialActionObserver` instance. * @param action * @param observer */ observe<TSender extends ObjectModel, TEventArgs extends EventArgs>(action: () => Observable<T>, observer?: IEvent<TSender, TEventArgs> | IPartialActionObserver<T, TEventArgs>): Observable<T>; cancel(): void; reset(): void; /** @inheritDoc */ equals(other: ActionObserver<T>): boolean; /** @inheritDoc */ dispose(disposing?: boolean): void; }