mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
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 = [];
|
|
}
|
|
}
|