@@ -106,49 +106,40 @@ function __spreadArray(to, from, pack) {
106106 return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
107107}
108108
109- function getCache ( obj , fnName ) {
109+ function isEqualArgs ( args , cacheArgs , equals ) {
110+ if ( ! cacheArgs ) {
111+ return false ;
112+ }
113+ if ( args . length === 0 && cacheArgs . length === 0 ) {
114+ return true ;
115+ }
116+ return ( args . length === cacheArgs . length &&
117+ cacheArgs . every ( function ( arg , index ) { var _a , _b ; return ( _b = ( _a = equals === null || equals === void 0 ? void 0 : equals [ index ] ) === null || _a === void 0 ? void 0 : _a . call ( equals , arg , args [ index ] ) ) !== null && _b !== void 0 ? _b : arg === args [ index ] ; } ) ) ;
118+ }
119+ function getCacheResult ( thisObj , fnName , args , equals ) {
110120 var _a ;
111- return ( _a = obj === null || obj === void 0 ? void 0 : obj . __cache ) === null || _a === void 0 ? void 0 : _a [ fnName ] ;
121+ var cache = ( _a = thisObj === null || thisObj === void 0 ? void 0 : thisObj . __cache ) === null || _a === void 0 ? void 0 : _a [ fnName ] ;
122+ if ( cache && isEqualArgs ( args , cache . args , equals ) ) {
123+ return cache . result ;
124+ }
112125}
113- function createCache ( obj , fnName , args ) {
114- if ( ! obj . __cache ) {
115- obj . __cache = { } ;
126+ function cache ( fn , args , thisObj , fnName , equals ) {
127+ var result = getCacheResult ( thisObj , fnName , args , equals ) ;
128+ if ( result ) {
129+ return result . value ;
116130 }
117- obj . __cache [ fnName ] = {
131+ var cache = {
118132 id : Symbol ( "id" ) ,
119133 args : args ,
120- isInProgress : true ,
121134 time : Date . now ( ) ,
122135 } ;
123- return getCache ( obj , fnName ) ;
124- }
125- function genCache ( fn , args , thisObj , fnName ) {
126- var cache = createCache ( thisObj , fnName , args ) ;
127- var value = fn . apply ( thisObj , args ) ;
128- cache . isInProgress = false ;
129- cache . value = value ;
130- }
131- function read ( thisObj , fnName ) {
132- var cache = getCache ( thisObj , fnName ) ;
133- return cache && cache . value ;
134- }
135- function hitCache ( args , thisObj , fnName , equals ) {
136- var cache = getCache ( thisObj , fnName ) ;
137- if ( ! cache || ! cache . args )
138- return false ;
139- if ( args . length === 0 && cache . args . length === 0 )
140- return true ;
141- return cache . args . every ( function ( arg , index ) { var _a , _b ; return ( _b = ( _a = equals === null || equals === void 0 ? void 0 : equals [ index ] ) === null || _a === void 0 ? void 0 : _a . call ( equals , arg , args [ index ] ) ) !== null && _b !== void 0 ? _b : arg === args [ index ] ; } ) ;
142- }
143- function isCyclic ( thisObj , fnName ) {
144- var cache = getCache ( thisObj , fnName ) ;
145- return cache && cache . isInProgress ;
146- }
147- function cache ( fn , args , thisObj , fnName , equals ) {
148- if ( ! hitCache ( args , thisObj , fnName , equals ) && ! isCyclic ( thisObj , fnName ) ) {
149- genCache ( fn , args , thisObj , fnName ) ;
136+ if ( ! thisObj . __cache ) {
137+ thisObj . __cache = { } ;
150138 }
151- return read ( thisObj , fnName ) ;
139+ thisObj . __cache [ fnName ] = cache ;
140+ var value = fn . apply ( thisObj , args ) ;
141+ cache . result = { value : value } ;
142+ return value ;
152143}
153144function memoized ( equals ) {
154145 return function ( target , fnName , descriptor ) {
@@ -1436,6 +1427,7 @@ var DefaultParser = /** @class */ (function () {
14361427function evalJson ( unevaledValue , context ) {
14371428 return new RelaxedJsonParser ( unevaledValue , context ) . parse ( ) ;
14381429}
1430+ // this will also be used in node-service
14391431var RelaxedJsonParser = /** @class */ ( function ( _super ) {
14401432 __extends ( RelaxedJsonParser , _super ) ;
14411433 function RelaxedJsonParser ( unevaledValue , context ) {
@@ -7547,6 +7539,7 @@ exports.FetchCheckNode = FetchCheckNode;
75477539exports . FunctionNode = FunctionNode ;
75487540exports . MultiBaseComp = MultiBaseComp ;
75497541exports . RecordNode = RecordNode ;
7542+ exports . RelaxedJsonParser = RelaxedJsonParser ;
75507543exports . SimpleAbstractComp = SimpleAbstractComp ;
75517544exports . SimpleComp = SimpleComp ;
75527545exports . SimpleNode = SimpleNode ;
0 commit comments