UNPKG

1.97 kBTypeScriptView Raw
1/** @module commands */
2import { IEvent } from './IEvent';
3import { IEventListener } from './IEventListener';
4import { Parameters } from '../run/Parameters';
5/**
6 * Concrete implementation of [[IEvent IEvent]] interface.
7 * It allows to send asynchronous notifications to multiple subscribed listeners.
8 *
9 * @see [[IEvent]]
10 * @see [[IEventListener]]
11 *
12 * ### Example ###
13 *
14 * let event = new Event("my_event");
15 *
16 * event.addListener(myListener);
17 *
18 * event.notify("123", Parameters.fromTuples(
19 * "param1", "ABC",
20 * "param2", 123
21 * ));
22 */
23export declare class Event implements IEvent {
24 private _name;
25 private _listeners;
26 /**
27 * Creates a new event and assigns its name.
28 *
29 * @param name the name of the event that is to be created.
30 * @throws an Error if the name is null.
31 */
32 constructor(name: string);
33 /**
34 * Gets the name of the event.
35 *
36 * @returns the name of this event.
37 */
38 getName(): string;
39 /**
40 * Gets all listeners registred in this event.
41 *
42 * @returns a list of listeners.
43 */
44 getListeners(): IEventListener[];
45 /**
46 * Adds a listener to receive notifications when this event is fired.
47 *
48 * @param listener the listener reference to add.
49 */
50 addListener(listener: IEventListener): void;
51 /**
52 * Removes a listener, so that it no longer receives notifications for this event.
53 *
54 * @param listener the listener reference to remove.
55 */
56 removeListener(listener: IEventListener): void;
57 /**
58 * Fires this event and notifies all registred listeners.
59 *
60 * @param correlationId (optional) transaction id to trace execution through call chain.
61 * @param args the parameters to raise this event with.
62 * @throws an [[InvocationException]] if the event fails to be raised.
63 */
64 notify(correlationId: string, args: Parameters): void;
65}