@@ -106,49 +106,40 @@ function __spreadArray(to, from, pack) {
106
106
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
107
107
}
108
108
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 ) {
110
120
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
+ }
112
125
}
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 ;
116
130
}
117
- obj . __cache [ fnName ] = {
131
+ var cache = {
118
132
id : Symbol ( "id" ) ,
119
133
args : args ,
120
- isInProgress : true ,
121
134
time : Date . now ( ) ,
122
135
} ;
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 = { } ;
150
138
}
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 ;
152
143
}
153
144
function memoized ( equals ) {
154
145
return function ( target , fnName , descriptor ) {
@@ -1436,6 +1427,7 @@ var DefaultParser = /** @class */ (function () {
1436
1427
function evalJson ( unevaledValue , context ) {
1437
1428
return new RelaxedJsonParser ( unevaledValue , context ) . parse ( ) ;
1438
1429
}
1430
+ // this will also be used in node-service
1439
1431
var RelaxedJsonParser = /** @class */ ( function ( _super ) {
1440
1432
__extends ( RelaxedJsonParser , _super ) ;
1441
1433
function RelaxedJsonParser ( unevaledValue , context ) {
@@ -7547,6 +7539,7 @@ exports.FetchCheckNode = FetchCheckNode;
7547
7539
exports . FunctionNode = FunctionNode ;
7548
7540
exports . MultiBaseComp = MultiBaseComp ;
7549
7541
exports . RecordNode = RecordNode ;
7542
+ exports . RelaxedJsonParser = RelaxedJsonParser ;
7550
7543
exports . SimpleAbstractComp = SimpleAbstractComp ;
7551
7544
exports . SimpleComp = SimpleComp ;
7552
7545
exports . SimpleNode = SimpleNode ;
0 commit comments