import { Container , DisplayObject } from "pixi.js" ; import { IClass } from "@robotlegsjs/core" ; import { ContainerRegistryEvent } from "./ContainerRegistryEvent" ; import { ContainerRegistry } from "./ContainerRegistry" ; import { ContainerBinding } from "./ContainerBinding" ; import { ConfigureViewEvent } from "./ConfigureViewEvent" ; private export class ManualStageObserver { private _registry : ContainerRegistry ; private constructor ( containerRegistry ) { this . _registry = containerRegistry ; this . _registry . addEventListener ( ContainerRegistryEvent . CONTAINER_ADD , this . onContainerAdd , this ) ; this . _registry . addEventListener ( ContainerRegistryEvent . CONTAINER_REMOVE , this . onContainerRemove , this ) ; this . _registry . bindings . forEach ( ( binding ) => { this . addContainerListener ( binding . container ) ; } ) ; } private public destroy ( ) { this . _registry . removeEventListener ( ContainerRegistryEvent . CONTAINER_ADD , this . onContainerAdd , this ) ; this . _registry . removeEventListener ( ContainerRegistryEvent . CONTAINER_REMOVE , this . onContainerRemove , this ) ; this . _registry . rootBindings . forEach ( ( binding ) => { this . removeContainerListener ( binding . container ) ; } ) ; } private onContainerAdd ( event ) { this . addContainerListener ( event . container ) ; } private onContainerRemove ( event ) { this . removeContainerListener ( event . container ) ; } private addContainerListener ( container ) { container . addEventListener ( ConfigureViewEvent . CONFIGURE_VIEW , this . onConfigureView , this ) ; } private removeContainerListener ( container ) { container . removeEventListener ( ConfigureViewEvent . CONFIGURE_VIEW , this . onConfigureView , this ) ; } private onConfigureView ( event ) { event . stopPropagation ( ) ; let container = < Container > event . currentTarget ; let view = < DisplayObject > event . target ; let type = < IClass < any > > view . constructor ; this . _registry . getBinding ( container ) . handleView ( view , type ) ; } }