Tree render and navigation with note rendering

This commit is contained in:
Magnus Åhall 2025-06-25 14:59:21 +02:00
parent dd27be67b9
commit 1ce8e29e37
7 changed files with 515 additions and 62 deletions

View file

@ -1,17 +1,48 @@
export class MessageBus {
constructor() {
this.log = false
this.bus = new EventTarget()
}
subscribe(eventName, fn) {
this.bus.addEventListener(eventName, fn)
if (this.log) {
console.groupCollapsed('MBUS subscribe - ', eventName);
console.trace(); // hidden in collapsed group
console.groupEnd();
}
this.bus.addEventListener(eventName, event=>{
fn(event)
if (event.detail.callback !== undefined)
event.detail.callback(event)
})
}
unsubscribe(eventName, fn) {
if (this.log) {
console.groupCollapsed('MBUS unsubscribe - ', eventName);
console.trace(); // hidden in collapsed group
console.groupEnd();
}
this.bus.removeEventListener(eventName, fn)
}
dispatch(eventName, data) {
this.bus.dispatchEvent(new CustomEvent(eventName, { detail: data }))
dispatch(eventName, data, callback) {
if (this.log) {
console.groupCollapsed('MBUS dispatch - ', eventName);
console.log('data', data);
console.trace(); // hidden in collapsed group
console.groupEnd();
}
const event = new CustomEvent(eventName, {
detail: {
data,
callback,
}
})
this.bus.dispatchEvent(event)
}
}