import { EventCallback , TemplateManager } from "./templateManager" ; /**
 * The EventManager is in charge of registering user interctions with the viewer.
 * It is used in the TemplateManager
 */ export class EventManager { private _callbacksContainer : { [ key ] : Array < { eventType ? : string ; selector ? : string ; callback : ( eventData : EventCallback ) => void ; } > ; } ; constructor ( private _templateManager ) { this . _callbacksContainer = { } ; this . _templateManager . onEventTriggered . add ( ( eventData ) => { this . _eventTriggered ( eventData ) ; } ) ; } param templateName param callback param eventType param selector public registerCallback ( templateName , callback , eventType ? , selector ? ) { if ( ! this . _callbacksContainer [ templateName ] ) { this . _callbacksContainer [ templateName ] = [ ] ; } this . _callbacksContainer [ templateName ] . push ( { eventType , callback , selector } ) ; } param templateName param callback param eventType param selector public unregisterCallback ( templateName , callback , eventType ? , selector ? ) { let callbackDefs = this . _callbacksContainer [ templateName ] || [ ] ; this . _callbacksContainer [ templateName ] = callbackDefs . filter ( ( callbackDef ) => ( ! callbackDef . eventType || callbackDef . eventType === eventType ) && ( ! callbackDef . selector || callbackDef . selector === selector ) ) ; } private _eventTriggered ( data ) { let templateName = data . template . name ; let eventType = data . event . type ; let selector = data . selector ; let callbackDefs = this . _callbacksContainer [ templateName ] || [ ] ; callbackDefs . filter ( ( callbackDef ) => ( ! callbackDef . eventType || callbackDef . eventType === eventType ) && ( ! callbackDef . selector || callbackDef . selector === selector ) ) . forEach ( ( callbackDef ) => { callbackDef . callback ( data ) ; } ) ; } /**
     * Dispose the event manager
     */ public dispose ( ) { this . _callbacksContainer = { } ; } }