import Cache from "../store/Cache" ; import { JsProxy } from "../references" ; /**
 * this class is a proxy that wraps java object of type JsProxy. The  proxy
 * put all calls into the cache.
 */ export default class ServiceProxy { constructor ( cache , locator , name ) { this . cache = cache ; this . locator = locator ; this . name = name ; } private cache : Cache ; private name : string ; private locator : ( ) => any ; param name param args returns { any } public invoke ( method , ... args ) { let cacheKey = this . cache . generateServiceCacheKey ( this . name , method , args ) ; return this . cache . wrapServiceCall ( cacheKey , ( ) : any => { let service = this . locator ( ) ; let result = service . invoke ( method , args ) ; if ( result == null ) { return null ; } return JSON . parse ( result ) ; } ) ; } }