import { buildServiceInfoIdentifier } from './service_info' ; import { IGBServiceInfo , } from '../proto' ; import { Service } from './service' ; export class ServiceStore { private services : { [ id ] : Service ; } = { } ; public constructor ( private protoTree , private grpc ) { } public getService ( clientId , info ) { let identifier = buildServiceInfoIdentifier ( info ) ; let serv = this . services [ identifier ] ; if ( ! serv ) { serv = new Service ( this . protoTree , clientId , info , this . grpc ) ; serv . disposed . subscribe ( ( ) => { if ( this . services ) { delete this . services [ identifier ] ; } } ) ; this . services [ identifier ] = serv ; } else { serv . clientAdd ( clientId ) ; } return serv ; } }