mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 08:13:27 +01:00
20 lines
388 B
TypeScript
20 lines
388 B
TypeScript
import type { InternalEvent } from '@yaakapp/api';
|
|
|
|
export class EventChannel {
|
|
#listeners = new Set<(event: InternalEvent) => void>();
|
|
|
|
emit(e: InternalEvent) {
|
|
for (const l of this.#listeners) {
|
|
l(e);
|
|
}
|
|
}
|
|
|
|
listen(cb: (e: InternalEvent) => void) {
|
|
this.#listeners.add(cb);
|
|
}
|
|
|
|
unlisten(cb: (e: InternalEvent) => void) {
|
|
this.#listeners.delete(cb);
|
|
}
|
|
}
|