/** Minimal event bus. */
export class EventBus {
  constructor() { this._m = new Map(); }
  on(evt, fn) {
    if (!this._m.has(evt)) this._m.set(evt, []);
    this._m.get(evt).push(fn);
    return () => this.off(evt, fn);
  }
  off(evt, fn) {
    const arr = this._m.get(evt);
    if (!arr) return;
    const i = arr.indexOf(fn);
    if (i >= 0) arr.splice(i, 1);
  }
  emit(evt, payload) {
    const arr = this._m.get(evt);
    if (!arr) return;
    for (let i = 0; i < arr.length; i++) arr[i](payload);
  }
}
