import { Injectable , OpaqueToken } from '@angular/core' ; @ Injectable ( ) export class EventEmitter { private handlers = { } ; on ( type , callback ) { this . handlers [ type ] = this . handlers [ type ] || [ ] ; this . handlers [ type ] . push ( callback ) ; } off ( type , callback ) { if ( ( this . handlers [ type ] || [ ] ) . includes ( callback ) ) { const index = this . handlers [ type ] . indexOf ( callback ) ; this . handlers [ type ] . splice ( index , 1 ) ; } } emit ( type , data ? ) { ( this . handlers [ type ] || [ ] ) . forEach ( ( callback ) => { callback ( data ) ; } ) ; } } export const PRIMARY_EVENT_EMITTER = new OpaqueToken ( 'primaryEventEmitter' ) ;