import Registry from './registry' ; const noop = ( ) => { } ; export enum CallbackType { enter = 'enter' , exit = 'exit' } export default abstract class Notifications { private registry : Registry ; constructor ( ) { this . registry = new Registry ( ) ; } param type param key param callback public addCallback ( type , element , callback ) { let entry ; if ( type === CallbackType . enter ) { entry = { [ CallbackType . enter ] : callback } ; } else { entry = { [ CallbackType . exit ] : callback } ; } this . registry . addElement ( element , Object . assign ( { } , this . registry . getElement ( element ) , entry ) ) ; } hidden param type param element param data public dispatchCallback ( type , element , data ? ) { if ( type === CallbackType . enter ) { const { enter = noop } = this . registry . getElement ( element ) ; enter ( data ) ; } else { const found = this . registry . getElement ( element ) ; if ( found && found . exit ) { found . exit ( data ) ; } } } }