import { IEventDispatcher } from "../../../events/api/IEventDispatcher" ; /**
 * Relays events from a source to a destination
 */ export class EventRelay { private _source : IEventDispatcher ; private _destination : IEventDispatcher ; private _types : string [ ] ; private _active : boolean ; param source param destination param types constructor ( source , destination , types ? ) { this . _source = source ; this . _destination = destination ; this . _types = types || [ ] ; } return public start ( ) { if ( ! this . _active ) { this . _active = true ; this . addListeners ( ) ; } return this ; } return public stop ( ) { if ( this . _active ) { this . _active = false ; this . removeListeners ( ) ; } return this ; } param eventType public addType ( eventType ) { this . _types . push ( eventType ) ; if ( this . _active ) { this . addListener ( eventType ) ; } } param eventType public removeType ( eventType ) { let index = this . _types . indexOf ( eventType ) ; if ( index > - 1 ) { this . _types . splice ( index , 1 ) ; this . removeListener ( eventType ) ; } } private addListener ( type ) { this . _source . addEventListener ( type , this . _destination . dispatchEvent , this . _destination ) ; } private removeListener ( type ) { this . _source . removeEventListener ( type , this . _destination . dispatchEvent , this . _destination ) ; } private addListeners ( ) { this . _types . forEach ( ( type ) => { this . addListener ( type ) ; } ) ; } private removeListeners ( ) { this . _types . forEach ( ( type ) => { this . removeListener ( type ) ; } ) ; } }