UNPKG

1.66 kBTypeScriptView Raw
1import type { Actor, IAction, IActorOutput, IActorTest } from './Actor';
2import type { IActorReply, IBusArgs } from './Bus';
3import { Bus } from './Bus';
4/**
5 * A bus that indexes identified actors,
6 * so that actions with a corresponding identifier can be published more efficiently.
7 *
8 * Multiple actors with the same identifier can be subscribed.
9 *
10 * If actors or actions do not have a valid identifier,
11 * then this will fallback to the normal bus behaviour.
12 *
13 * @see Bus
14 *
15 * @template A The actor type that can subscribe to the sub.
16 * @template I The input type of an actor.
17 * @template T The test type of an actor.
18 * @template O The output type of an actor.
19 */
20export declare class BusIndexed<A extends Actor<I, T, O>, I extends IAction, T extends IActorTest, O extends IActorOutput> extends Bus<A, I, T, O> {
21 protected readonly actorsIndex: Record<string, A[]>;
22 protected readonly actorIdentifierFields: string[];
23 protected readonly actionIdentifierFields: string[];
24 /**
25 * All enumerable properties from the `args` object are inherited to this bus.
26 *
27 * @param {IBusIndexedArgs} args Arguments object
28 * @param {string} args.name The name for the bus
29 * @throws When required arguments are missing.
30 */
31 constructor(args: IBusIndexedArgs);
32 subscribe(actor: A): void;
33 unsubscribe(actor: A): boolean;
34 publish(action: I): IActorReply<A, I, T, O>[];
35 protected getActorIdentifier(actor: A): string;
36 protected getActionIdentifier(action: I): string;
37}
38export interface IBusIndexedArgs extends IBusArgs {
39 actorIdentifierFields: string[];
40 actionIdentifierFields: string[];
41}