Class EventRelay<T>

A simple event relay. Create a listener with createListener and dispatch events with dispatchEvent. For each supported event type, create a new instance of EventRelay and expose it as a property.

For example, this code:

class MyClass {
public readonly onSomethingHappened = new EventRelay<string>();

public doSomething(whatToDo: string) {
this.onSomethingHappened.dispatchEvent(whatToDo);
console.log("Done notifying listeners");
}
}

const myClass = new MyClass();
myClass.onSomethingHappened.createListener((whatHappened) => {
console.log(`Something happened: ${whatHappened}`);
});
myClass.doSomething("eat a cookie");

Will print this:

Something happened: eat a cookie
Done notifying listeners

Type Parameters

  • T

Hierarchy

  • EventRelay

Constructors

Accessors

Methods

  • Parameters

    • data: T

    Returns void