@kephas/ngx-core
Version:
Provides integration capabilities with Angular 13+.
64 lines (63 loc) • 2.51 kB
TypeScript
import { Observable, BehaviorSubject } from 'rxjs';
import { CommandProcessorClient } from '@kephas/commands';
import { Expando } from '@kephas/core';
export interface CommandState<TArgs> extends Expando {
command?: string;
args?: TArgs;
}
/**
* Observable based on a command query.
*
* @export
* @abstract
* @class CommandQuery
* @extends {BehaviorSubject<TValue>}
* @template TArgs
* @template TResponseMessage
* @template TValue
*/
export declare abstract class CommandQuery<TArgs, TResponseMessage, TValue> extends BehaviorSubject<TValue> {
#private;
protected readonly processor: CommandProcessorClient;
protected command: string;
protected resultMap?: ((r: TResponseMessage, state?: CommandState<TArgs> | undefined) => TValue) | undefined;
protected argsMap?: ((args?: TArgs | undefined, state?: CommandState<TArgs> | undefined) => TArgs) | undefined;
protected emptyResult: TValue;
args?: TArgs;
/**
* Creates an instance of CommandQuery.
* @param {CommandProcessorClient} processor
* @param {string} command
* @param {(r: TResponseMessage, state?: CommandState<TArgs>) => TValue} [resultMap]
* @param {(args?: TArgs, state?: CommandState<TArgs>) => TArgs} [argsMap]
* @param {TValue} [emptyResult={} as TValue]
* @memberof CommandQuery
*/
constructor(processor: CommandProcessorClient, command: string, resultMap?: ((r: TResponseMessage, state?: CommandState<TArgs> | undefined) => TValue) | undefined, argsMap?: ((args?: TArgs | undefined, state?: CommandState<TArgs> | undefined) => TArgs) | undefined, emptyResult?: TValue);
/**
* Gets a value indicating whether the query is executing.
*
* @readonly
* @type {boolean}
* @memberof CommandQuery
*/
get loading(): boolean;
/**
* Gets the last error executing this query.
*
* @readonly
* @type {*}
* @memberof CommandQuery
*/
get lastError(): any;
/**
* Executes the command asynchronously.
*
* @param {CommandState<TArgs>} [state]
* @memberof CommandQuery
*/
execute(state?: CommandState<TArgs>): void;
protected fetch(command: string, args?: TArgs, state?: CommandState<TArgs>): Observable<TValue>;
protected mapResponse(response: TResponseMessage, state?: CommandState<TArgs>): TValue;
protected mapArgs(args?: TArgs, state?: CommandState<TArgs>): TArgs | undefined;
}