import { DisplayObject } from "pixi.js" ; import { injectable , inject , IClass , IContext , ILogger , ITypeMatcher , TypeMatcher } from "@robotlegsjs/core" ; import { IMediatorMap } from "../api/IMediatorMap" ; import { IMediatorMapper } from "../dsl/IMediatorMapper" ; import { IMediatorUnmapper } from "../dsl/IMediatorUnmapper" ; import { IViewHandler } from "../../viewManager/api/IViewHandler" ; import { MediatorFactory } from "./MediatorFactory" ; import { MediatorViewHandler } from "./MediatorViewHandler" ; import { NullMediatorUnmapper } from "./NullMediatorUnmapper" ; import { MediatorMapper } from "./MediatorMapper" ; private @ injectable ( ) export class MediatorMap implements IMediatorMap , IViewHandler { private _mappers : Map < string , MediatorMapper > = new Map < string , MediatorMapper > ( ) ; private _logger : ILogger ; private _factory : MediatorFactory ; private _viewHandler : MediatorViewHandler ; private NULL_UNMAPPER : IMediatorUnmapper = new NullMediatorUnmapper ( ) ; private constructor ( @ inject ( IContext ) context ) { this . _logger = context . getLogger ( this ) ; this . _factory = new MediatorFactory ( context . injector ) ; this . _viewHandler = new MediatorViewHandler ( this . _factory ) ; } inheritDoc public mapMatcher ( matcher ) { const desc = matcher . createTypeFilter ( ) . descriptor ; let mapper = this . _mappers . get ( desc ) ; if ( mapper ) { return mapper ; } mapper = this . createMapper ( matcher ) ; this . _mappers . set ( desc , mapper ) ; return mapper ; } inheritDoc public map ( type ) { return this . mapMatcher ( new TypeMatcher ( ) . allOf ( type ) ) ; } inheritDoc public unmapMatcher ( matcher ) { return this . _mappers . get ( matcher . createTypeFilter ( ) . descriptor ) || this . NULL_UNMAPPER ; } inheritDoc public unmap ( type ) { return this . unmapMatcher ( new TypeMatcher ( ) . allOf ( type ) ) ; } inheritDoc public handleView ( view , type ) { this . _viewHandler . handleView ( view , type ) ; } inheritDoc public mediate ( item ) { this . _viewHandler . handleItem ( item , < IClass < any > > item . constructor ) ; } inheritDoc public unmediate ( item ) { this . _factory . removeMediators ( item ) ; } inheritDoc public unmediateAll ( ) { this . _factory . removeAllMediators ( ) ; } private createMapper ( matcher ) { return new MediatorMapper ( matcher . createTypeFilter ( ) , this . _viewHandler , this . _logger ) ; } }