Interface IEventHandler<T>
Methods
subscribe
- subscribe(handler: (data?: T) => void): void
-
Parameters
-
handler: (data?: T) => void
Returns void
unsubscribe
- unsubscribe(handler: (data?: T) => void): void
-
Parameters
-
handler: (data?: T) => void
Returns void
An EventHandler is a generic class that enables subscription, unsubscription to an event
Declare an event as a property in your class like this
public class MyCLass { public EventHandler<string> someEvent = new EventHandler<string>(); }
Subscribe to the event like this
const myClass = new MyClass(); myClass.subscribe((event) => { console.log(event); });
Publish an event like this
const myClass = new MyClass(); myClass.raiseEvent("Hi there!");