import type { EventHandler, IEventSource, IEventSubscription } from '@/infrastructure/Events/IEventSource'; import { EventSubscriptionStub } from './EventSubscriptionStub'; export class EventSourceStub implements IEventSource { private readonly handlers = new Array>(); public on(handler: EventHandler): IEventSubscription { this.handlers.push(handler); return new EventSubscriptionStub(() => { const index = this.handlers.indexOf(handler); if (index !== -1) { this.handlers.splice(index, 1); } }); } public notify(data: T) { for (const handler of this.handlers) { handler(data); } } }