26 lines
529 B
JavaScript
26 lines
529 B
JavaScript
export class EventBus
|
|
{
|
|
static listeners = []
|
|
|
|
static addEventListener(eventName, callback)
|
|
{
|
|
EventBus.listeners.push({eventName, callback});
|
|
|
|
window.addEventListener(eventName, callback, false);
|
|
}
|
|
|
|
static dispatchEvent(event)
|
|
{
|
|
window.dispatchEvent(event);
|
|
}
|
|
|
|
static clear()
|
|
{
|
|
for (const listener of EventBus.listeners) {
|
|
window.removeEventListener(listener.eventName, listener.callback, false);
|
|
}
|
|
|
|
EventBus.listeners = [];
|
|
}
|
|
}
|