Initial use of simple message bus

This commit is contained in:
Magnus Åhall 2025-06-15 12:13:00 +02:00
parent b36ca0d635
commit 23307d7967
7 changed files with 189 additions and 6 deletions

17
static/js/mbus.mjs Normal file
View file

@ -0,0 +1,17 @@
export class MessageBus {
constructor() {
this.bus = new EventTarget()
}
subscribe(eventName, fn) {
this.bus.addEventListener(eventName, fn)
}
unsubscribe(eventName, fn) {
this.bus.removeEventListener(eventName, fn)
}
dispatch(eventName, data) {
this.bus.dispatchEvent(new CustomEvent(eventName, { detail: data }))
}
}