import _ from 'underscore' ; export default class EventListenerCollection { listenerCollection : Array < Function > = [ ] ; public emitEvent ( valueToEmit ) { if ( this . listenerCollection && this . listenerCollection . length > 0 ) { for ( const aListener of this . listenerCollection ) { if ( aListener ) { aListener ( valueToEmit ) ; } } } } public addListener ( callback ) { if ( ! _ . contains ( this . listenerCollection , callback ) ) { this . listenerCollection . push ( callback ) ; } } public removeListener ( callback ) { if ( _ . contains ( this . listenerCollection , callback ) ) { this . listenerCollection = _ . reject ( this . listenerCollection , ( item ) => item === callback ) ; } } public hasListeners ( ) { return this . listenerCollection . length > 0 ; } }