import { IContext } from "../../framework/api/IContext" ; import { IExtension } from "../../framework/api/IExtension" ; import { IEventDispatcher } from "../../events/api/IEventDispatcher" ; import { EventDispatcher } from "../../events/impl/EventDispatcher" ; import { LifecycleEventRelay } from "./impl/LifecycleEventRelay" ; /**
 * This extension maps an IEventDispatcher into a context's injector.
 */ export class EventDispatcherExtension implements IExtension { private _context : IContext ; private _eventDispatcher : IEventDispatcher ; private _lifecycleRelay : LifecycleEventRelay ; param eventDispatcher constructor ( eventDispatcher = null ) { this . _eventDispatcher = eventDispatcher || new EventDispatcher ( ) ; } inheritDoc public extend ( context ) { this . _context = context ; this . _context . injector . bind ( IEventDispatcher ) . toConstantValue ( this . _eventDispatcher ) ; this . _context . beforeInitializing ( this . configureLifecycleEventRelay . bind ( this ) ) ; this . _context . afterDestroying ( this . destroyLifecycleEventRelay . bind ( this ) ) ; } private configureLifecycleEventRelay ( ) { this . _lifecycleRelay = new LifecycleEventRelay ( this . _context , this . _eventDispatcher ) ; } private destroyLifecycleEventRelay ( ) { this . _lifecycleRelay . destroy ( ) ; } }