export type EventHub = { on ( evtName , cb ) : void ; off ( evtName , cb ) : void ; emit ( evtName , ... data ) : void ; clear ( ) : void ; } ; export const LIFE_CYCLES = { BEFORE_INIT : 'before-init' , AFTER_INIT : 'after-init' , BEFORE_SLIDE : 'before-slide' , SCROLL : 'scroll' , AFTER_SLIDE : 'after-slide' , BEFORE_DESTROY : 'before-destroy' , AFTER_DESTROY : 'after-destroy' } ; export function EventHub ( ) { let hub = { } ; function on ( evtName , cb ) { if ( ! hub [ evtName ] ) { hub [ evtName ] = [ cb ] ; } else { hub [ evtName ] . push ( cb ) ; } } function off ( evtName , cb ) { if ( hub [ evtName ] ) { const index = hub [ evtName ] . indexOf ( cb ) ; index > - 1 && hub [ evtName ] . splice ( index , 1 ) ; } } function emit ( evtName , ... data ) { if ( hub [ evtName ] ) { hub [ evtName ] . forEach ( cb => cb ( ... data ) ) ; } } function clear ( ) { hub = { } ; } return { on , off , emit , clear } ; }