Added settings, proper record renaming
This commit is contained in:
parent
2ae93b6fd4
commit
7d7c0c9570
10 changed files with 444 additions and 85 deletions
29
static/js/mbus.mjs
Normal file
29
static/js/mbus.mjs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export class MessageBus {
|
||||
constructor() {
|
||||
this.bus = new EventTarget()
|
||||
this.counter = 0
|
||||
this.fnmap = new Map()
|
||||
}
|
||||
|
||||
subscribe(eventName, fn) {
|
||||
this.counter++
|
||||
this.bus.addEventListener(eventName, fn)
|
||||
this.fnmap.set(this.counter, { eventName, fn })
|
||||
return this.counter
|
||||
}
|
||||
|
||||
unsubscribe(mappedID) {
|
||||
const mapped = this.fnmap.get(mappedID)
|
||||
if (mapped === undefined) {
|
||||
console.warn('unsubscribe, no such mapped ID', mappedID)
|
||||
return
|
||||
}
|
||||
this.fnmap.delete(mappedID)
|
||||
this.bus.removeEventListener(mapped.eventName, mapped.fn)
|
||||
}
|
||||
|
||||
dispatch(eventName, data) {
|
||||
console.debug('mbus', eventName, data)
|
||||
this.bus.dispatchEvent(new CustomEvent(eventName, { detail: data }))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue