import { instanceOfType , IContext , IExtension , IInjector , ILogger } from "@robotlegsjs/core" ; import { IContextView } from "./api/IContextView" ; import { ContextView } from "./impl/ContextView" ; import { applyPixiPatch } from "./pixiPatch/pixi-patch" ; /**
 * <p>This Extension waits for a ContextView to be added as a configuration
 * and maps it into the context's injector.</p>
 *
 * <p>It should be installed before context initialization.</p>
 */ export class ContextViewExtension implements IExtension { private _injector : IInjector ; private _logger : ILogger ; inheritDoc public extend ( context ) { this . _injector = context . injector ; this . _logger = context . getLogger ( this ) ; context . beforeInitializing ( this . beforeInitializing . bind ( this ) ) ; context . addConfigHandler ( instanceOfType ( ContextView ) , this . handleContextView . bind ( this ) ) ; } private handleContextView ( contextView ) { if ( this . _injector . isBound ( IContextView ) ) { this . _logger . warn ( "A contextView has already been installed, ignoring {0}" , [ contextView . view ] ) ; } else { this . _logger . debug ( "Mapping {0} as contextView" , [ contextView . view ] ) ; applyPixiPatch ( contextView . view ) ; this . _injector . bind ( IContextView ) . toConstantValue ( contextView ) ; } } private beforeInitializing ( ) { if ( ! this . _injector . isBound ( IContextView ) ) { this . _logger . error ( "A ContextView must be installed if you install the ContextViewExtension." ) ; } } }