@comunica/core
Version:
Lightweight, semantic and modular actor framework
1 lines • 2.21 kB
Source Map (JSON)
{"version":3,"file":"ActionObserver.js","sourceRoot":"","sources":["ActionObserver.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;GAYG;AACH,MAAsB,cAAc;IAIlC;;;;;;;OAOG;IACH,YAAsB,IAA+B;QACnD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CAUF;AAxBD,wCAwBC","sourcesContent":["import type { Actor, IAction, IActorOutput, IActorTest } from './Actor';\nimport type { Bus } from './Bus';\n\n/**\n * An ActionObserver can passively listen to {@link Actor#run} inputs and outputs for all actors on a certain bus.\n *\n * ActionObserver should not edit inputs and outputs,\n * they should be considered immutable.\n *\n * @see Actor\n * @see Bus\n *\n * @template I The input type of an actor.\n * @template O The output type of an actor.\n * @template TS The test side data type.\n */\nexport abstract class ActionObserver<I extends IAction, O extends IActorOutput, TS = undefined> {\n public readonly name: string;\n public readonly bus: Bus<Actor<I, IActorTest, O, TS>, I, IActorTest, O, TS>;\n\n /**\n * All enumerable properties from the `args` object are inherited to this observer.\n *\n * The observer will NOT automatically subscribe to the given bus when this constructor is called.\n *\n * @param {IActionObserverArgs<I extends IAction, O extends IActorOutput>} args Arguments object\n * @throws When required arguments are missing.\n */\n protected constructor(args: IActionObserverArgs<I, O>) {\n Object.assign(this, args);\n }\n\n /**\n * Invoked when an action was run by an actor.\n *\n * @param actor The action on which the {@link Actor#run} method was invoked.\n * @param {I} action The original action input.\n * @param {Promise<O>} output A promise resolving to the final action output.\n */\n public abstract onRun(actor: Actor<I, IActorTest, O, TS>, action: I, output: Promise<O>): void;\n}\n\nexport interface IActionObserverArgs<I extends IAction, O extends IActorOutput, TS = undefined> {\n\n /**\n * The name for this observer.\n * @default {<rdf:subject>}\n */\n name: string;\n\n /**\n * The bus this observer can subscribe to.\n */\n bus: Bus<Actor<I, IActorTest, O, TS>, I, IActorTest, O, TS>;\n}\n"]}