mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
- Add plugin system bootstrap in renderer.js after sidebar/commands init - Wire status bar DOM insertion, editor API, and IPC adapters - Add plugin-settings:get/set IPC channels to preload allowlist - Add IPC handlers in main process using existing settings store - Fix eqeqeq warning in EventBus.hasHandler Amit Haridas
44 lines
976 B
JavaScript
44 lines
976 B
JavaScript
class EventBus {
|
|
constructor() {
|
|
this.listeners = new Map();
|
|
}
|
|
|
|
on(event, handler) {
|
|
if (!this.listeners.has(event)) {
|
|
this.listeners.set(event, []);
|
|
}
|
|
this.listeners.get(event).push(handler);
|
|
}
|
|
|
|
off(event, handler) {
|
|
if (!handler) {
|
|
this.listeners.delete(event);
|
|
return;
|
|
}
|
|
const handlers = this.listeners.get(event);
|
|
if (handlers) {
|
|
const idx = handlers.indexOf(handler);
|
|
if (idx !== -1) handlers.splice(idx, 1);
|
|
}
|
|
}
|
|
|
|
emit(event, payload) {
|
|
const handlers = this.listeners.get(event);
|
|
if (!handlers) return;
|
|
for (const handler of handlers) {
|
|
try {
|
|
handler(payload);
|
|
} catch (err) {
|
|
console.error(`[EventBus] Error in handler for "${event}":`, err);
|
|
}
|
|
}
|
|
}
|
|
|
|
hasHandler(event) {
|
|
const handlers = this.listeners.get(event);
|
|
return handlers !== undefined && handlers !== null && handlers.length > 0;
|
|
}
|
|
}
|
|
|
|
module.exports = { EventBus };
|