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.
createListener
dispatchEvent
EventRelay
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"); Copy
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 cookieDone notifying listeners Copy
Something happened: eat a cookieDone notifying listeners
A simple event relay. Create a listener with
createListener
and dispatch events withdispatchEvent
. For each supported event type, create a new instance ofEventRelay
and expose it as a property.For example, this code:
Will print this: