import { ICommandTrigger } from "../api/ICommandTrigger" ; private export class CommandTriggerMap { private _triggers : Map < any , any > = new Map < any , any > ( ) ; private _keyFactory : Function ; private _triggerFactory : Function ; param keyFactory param triggerFactory constructor ( keyFactory , triggerFactory ) { this . _keyFactory = keyFactory ; this . _triggerFactory = triggerFactory ; } private public getTrigger ( ... params ) { let key = this . getKey ( params ) ; let trigger = this . _triggers . get ( key ) ; if ( ! trigger ) { trigger = this . createTrigger ( params ) ; this . _triggers . set ( key , trigger ) ; } return trigger ; } private public removeTrigger ( ... params ) { return this . destroyTrigger ( this . getKey ( params ) ) ; } private getKey ( mapperArgs ) { return this . _keyFactory . apply ( null , mapperArgs ) ; } private createTrigger ( mapperArgs ) { return this . _triggerFactory . apply ( null , mapperArgs ) ; } private destroyTrigger ( key ) { let trigger = this . _triggers . get ( key ) ; if ( trigger ) { trigger . deactivate ( ) ; this . _triggers . delete ( key ) ; } return trigger ; } }