import { injectable , inject , IClass , IEvent , IEventMap , IEventDispatcher , Event } from "@robotlegsjs/core" ; import { IMediator } from "../api/IMediator" ; /**
 * Classic Robotlegs mediator implementation
 *
 * <p>Override initialize and destroy to hook into the mediator lifecycle.</p>
 */ @ injectable ( ) export abstract class Mediator < T extends IEventDispatcher > implements IMediator { @ inject ( IEventMap ) protected eventMap : IEventMap ; @ inject ( IEventDispatcher ) protected eventDispatcher : IEventDispatcher ; protected _viewComponent : T ; public set view ( view ) { this . _viewComponent = view ; } public get view ( ) : T { return this . _viewComponent ; } inheritDoc public abstract initialize ( ) ; inheritDoc public abstract destroy ( ) ; /**
     * Runs after the mediator has been destroyed.
     * Cleans up listeners mapped through the local EventMap.
     */ public postDestroy ( ) { this . eventMap . unmapAllListeners ( ) ; } protected addViewListener ( eventString , listener , thisObject ? , eventClass ? , useCapture ? , priority ? ) { this . eventMap . mapListener ( this . _viewComponent , eventString , listener , thisObject , eventClass , useCapture , priority ) ; } protected addContextListener ( eventString , listener , thisObject ? , eventClass ? , useCapture ? , priority ? ) { this . eventMap . mapListener ( this . eventDispatcher , eventString , listener , thisObject , eventClass , useCapture , priority ) ; } protected addDomListener ( eventTarget , eventString , listener , options ? ) { this . eventMap . mapDomListener ( eventTarget , eventString , listener , options ) ; } protected removeViewListener ( eventString , listener , thisObject ? , eventClass ? , useCapture ? ) { this . eventMap . unmapListener ( this . _viewComponent , eventString , listener , thisObject , eventClass , useCapture ) ; } protected removeContextListener ( eventString , listener , thisObject ? , eventClass ? , useCapture ? ) { this . eventMap . unmapListener ( this . eventDispatcher , eventString , listener , thisObject , eventClass , useCapture ) ; } protected removeDomListener ( eventTarget , eventString , listener ) { this . eventMap . unmapDomListener ( eventTarget , eventString , listener ) ; } protected dispatch ( event ) { if ( this . eventDispatcher . hasEventListener ( event . type ) ) { this . eventDispatcher . dispatchEvent ( event ) ; } } }