UNPKG

1.86 kBTypeScriptView Raw
1import type { Actor, IAction, IActorOutput, IActorTest } from './Actor';
2import type { Bus } from './Bus';
3/**
4 * An ActionObserver can passively listen to {@link Actor#run} inputs and outputs for all actors on a certain bus.
5 *
6 * ActionObserver should not edit inputs and outputs,
7 * they should be considered immutable.
8 *
9 * @see Actor
10 * @see Bus
11 *
12 * @template I The input type of an actor.
13 * @template O The output type of an actor.
14 * @template TS The test side data type.
15 */
16export declare abstract class ActionObserver<I extends IAction, O extends IActorOutput, TS = undefined> {
17 readonly name: string;
18 readonly bus: Bus<Actor<I, IActorTest, O, TS>, I, IActorTest, O, TS>;
19 /**
20 * All enumerable properties from the `args` object are inherited to this observer.
21 *
22 * The observer will NOT automatically subscribe to the given bus when this constructor is called.
23 *
24 * @param {IActionObserverArgs<I extends IAction, O extends IActorOutput>} args Arguments object
25 * @throws When required arguments are missing.
26 */
27 protected constructor(args: IActionObserverArgs<I, O>);
28 /**
29 * Invoked when an action was run by an actor.
30 *
31 * @param actor The action on which the {@link Actor#run} method was invoked.
32 * @param {I} action The original action input.
33 * @param {Promise<O>} output A promise resolving to the final action output.
34 */
35 abstract onRun(actor: Actor<I, IActorTest, O, TS>, action: I, output: Promise<O>): void;
36}
37export interface IActionObserverArgs<I extends IAction, O extends IActorOutput, TS = undefined> {
38 /**
39 * The name for this observer.
40 * @default {<rdf:subject>}
41 */
42 name: string;
43 /**
44 * The bus this observer can subscribe to.
45 */
46 bus: Bus<Actor<I, IActorTest, O, TS>, I, IActorTest, O, TS>;
47}