import type { EventNotifierSubscriptionCallback, Id, InferIOOutput, IOEventMessage, IOLike, } from "@pluv/types"; import type { Subject } from "wonka"; import { makeSubject, subscribe } from "wonka"; export class EventNotifier { public subjects = new Map< keyof InferIOOutput, Subject>>> >(); public subject>( name: TEvent, ): Subject>> { const subject = this.subjects.get(name); if (subject) return subject; const newSubject = makeSubject>>(); this.subjects.set(name, newSubject); return newSubject; } public subscribe>( name: TEvent, callback: EventNotifierSubscriptionCallback, ): () => void { const subject = this.subject(name); return subscribe(callback)(subject.source).unsubscribe; } }