import { isQueryBuilder , isQueryPredicate , Query , QueryBuilder , QueryPredicate } from './Query' ; import { Engine } from './Engine' ; import { Entity , EntitySnapshot } from './Entity' ; import { System } from './System' ; example export abstract class ReactionSystem extends System { protected readonly query : Query ; protected constructor ( query ) { super ( ) ; if ( isQueryBuilder ( query ) ) { this . query = query . build ( ) ; } else if ( isQueryPredicate ( query ) ) { this . query = new Query ( query ) ; } else { this . query = query ; } } protected get entities ( ) : ReadonlyArray < Entity > { return this . query . entities ; } public onAddedToEngine ( ) { this . engine . addQuery ( this . query ) ; this . prepare ( ) ; this . query . onEntityAdded . connect ( this . entityAdded ) ; this . query . onEntityRemoved . connect ( this . entityRemoved ) ; } public onRemovedFromEngine ( ) { this . engine . removeQuery ( this . query ) ; this . query . onEntityAdded . disconnect ( this . entityAdded ) ; this . query . onEntityRemoved . disconnect ( this . entityRemoved ) ; this . query . clear ( ) ; } protected prepare ( ) { } param entity protected entityAdded = ( entity ) => { } ; param entity protected entityRemoved = ( entity ) => { } ; }