import { hasFunctionArgument } from './helpers/functionHelper' ; import { IEventEmitter , IEventListener , CallbackEvent , IEventsConfig , IEventManager , } from './types' ; param emitter param config const eventManagerProvider = ( emitter , config ) => ( { registerEvents : ( listeners ) => { listeners . forEach ( ( listener ) => { if ( listener . event === '' || listener . event === null ) { throw new Error ( 'eventName can not be empty' ) ; } emitter . on ( listener . event , listener . handler ) ; } ) ; } , emitEvent : ( eventName , callback ) => { if ( eventName === '' || eventName === null ) { throw new Error ( 'eventName can not be empty' ) ; } if ( callback === undefined || callback === null ) { callback = ( ) => null ; } return emitter . listeners ( eventName ) . reduce ( ( prevCallback , currentHandler ) => { if ( ! hasFunctionArgument ( currentHandler , 'callback' ) ) { return ( ... args ) => { currentHandler ( ... args ) ; return prevCallback ( ... args ) ; } ; } return ( ... args ) => currentHandler ( prevCallback , ... args ) ; } , callback ) ; } , } as IEventManager ) ; export default eventManagerProvider ;