import { EventEmitter } from 'events' ; import { DomainEvent } from '../../domain/DomainEvent' ; import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber' ; export class EventEmitterBus extends EventEmitter { constructor ( subscribers ) { super ( ) ; this . registerSubscribers ( subscribers ) ; } registerSubscribers ( subscribers ? ) { subscribers ?. map ( subscriber => { this . registerSubscriber ( subscriber ) ; } ) ; } private registerSubscriber ( subscriber ) { subscriber . subscribedTo ( ) . map ( event => { this . on ( event . EVENT_NAME , subscriber . on . bind ( subscriber ) ) ; } ) ; } publish ( events ) { events . map ( event => this . emit ( event . eventName , event ) ) ; } }