author Joel Hernandez <lifenautjoe@gmail.com>
  import { NoelEventListener } from './types' ; import { NoelEvent } from './event' ; import { NoelEventReplayNotEnabled } from './errors' ; import NoelImp from './noel' ; export class NoelEventListenerManager { constructor ( private listener , private event , private noel ) { } remove ( ) { this . noel . removeEventListener ( this . event , this . listener ) ; } replay ( bufferSize ? ) { const event = this . event ; if ( ! event . getReplayIsEnabled ( ) ) throw new NoelEventReplayNotEnabled ( event ) ; if ( typeof bufferSize === 'undefined' ) bufferSize = 1 ; const actualBufferSize = event . getReplayBufferSize ( ) ; if ( bufferSize > actualBufferSize ) { const logger = event . getLogger ( ) ; logger . warn ( `Attempted to replay ${ bufferSize } emits from the event "${ event . getName ( ) }" but the replay buffer size is set to ${ actualBufferSize }.` ) ; } const eventReplayBuffer = this . event . getReplayBufferAmount ( bufferSize ) ; eventReplayBuffer . forEach ( eventReplayBufferItem => { this . listener ( ... eventReplayBufferItem ) ; } ) ; return this ; } }