@orbit/coordinator
Version:
A coordinator and set of coordination strategies for managing data flow and keeping @orbit/data sources in sync.
66 lines (65 loc) • 2.51 kB
TypeScript
import { Coordinator, ActivationOptions } from '../coordinator';
import { Strategy, StrategyOptions } from '../strategy';
import { Listener } from '@orbit/core';
import { Source } from '@orbit/data';
export interface ConnectionStrategyOptions extends StrategyOptions {
/**
* The name of the source to be observed.
*/
source: string;
/**
* The name of the event to observe.
*/
on: string;
/**
* The name of the source which will be acted upon.
*/
target?: string;
/**
* The action to perform on the target.
*
* Can be specified as a string (e.g. `pull`) or a function which will be
* invoked in the context of this strategy (and thus will have access to
* both `this.source` and `this.target`).
*/
action: string | ((...args: unknown[]) => unknown);
/**
* A handler for any errors thrown as a result of performing the action.
*/
catch?: (error: Error, ...args: unknown[]) => void;
/**
* A filter function that returns `true` if the `action` should be performed.
*
* `filter` will be invoked in the context of this strategy (and thus will
* have access to both `this.source` and `this.target`).
*/
filter?: (...args: unknown[]) => boolean;
/**
* Should resolution of `action` on the the target block the completion
* of the source's event?
*
* By default, `blocking` is false.
*/
blocking?: boolean | ((...args: unknown[]) => boolean);
}
declare type CatchFn = (error: Error, ...args: unknown[]) => void;
declare type FilterFn = (...args: unknown[]) => boolean;
export declare class ConnectionStrategy extends Strategy {
protected _blocking: boolean | ((...args: unknown[]) => boolean);
protected _event: string;
protected _action: string | ((...args: unknown[]) => unknown);
protected _catch?: CatchFn;
protected _listener?: Listener;
protected _filter?: FilterFn;
constructor(options: ConnectionStrategyOptions);
get source(): Source;
get target(): Source;
get blocking(): boolean | ((...args: any[]) => boolean);
activate(coordinator: Coordinator, options?: ActivationOptions): Promise<void>;
deactivate(): Promise<void>;
protected generateListener(): Listener;
protected defaultListener(...args: any[]): Promise<any>;
protected invokeAction(...args: any[]): unknown;
protected handleBlockingResponse(result: Promise<any>, ...args: any[]): Promise<any>;
}
export {};