@@ -106,18 +106,15 @@ function createCache(obj, fnName, args) {
106106 if ( ! obj . __cache ) {
107107 obj . __cache = { } ;
108108 }
109- if ( ! obj . __cache [ fnName ] ) {
110- obj . __cache [ fnName ] = {
111- id : Symbol ( "id" ) ,
112- args : args ,
113- isInProgress : true ,
114- time : Date . now ( ) ,
115- } ;
116- }
109+ obj . __cache [ fnName ] = {
110+ id : Symbol ( "id" ) ,
111+ args : args ,
112+ isInProgress : true ,
113+ time : Date . now ( ) ,
114+ } ;
117115 return getCache ( obj , fnName ) ;
118116}
119- function populate ( fn , args , thisObj , fnName ) {
120- if ( args === void 0 ) { args = [ ] ; }
117+ function genCache ( fn , args , thisObj , fnName ) {
121118 var cache = createCache ( thisObj , fnName , args ) ;
122119 var value = fn . apply ( thisObj , args ) ;
123120 cache . isInProgress = false ;
@@ -127,25 +124,21 @@ function read(thisObj, fnName) {
127124 var cache = getCache ( thisObj , fnName ) ;
128125 return cache && cache . value ;
129126}
130- function isValid ( args , thisObj , fnName , equals ) {
131- if ( args === void 0 ) { args = [ ] ; }
127+ function hitCache ( args , thisObj , fnName , equals ) {
132128 var cache = getCache ( thisObj , fnName ) ;
133129 if ( ! cache || ! cache . args )
134130 return false ;
135131 if ( args . length === 0 && cache . args . length === 0 )
136132 return true ;
137- return cache . args . reduce ( function ( result , arg , index ) {
138- return result && ( ( equals === null || equals === void 0 ? void 0 : equals [ index ] ) ? equals [ index ] ( arg , args [ index ] ) : arg === args [ index ] ) ;
139- } , true ) ;
133+ 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 ] ; } ) ;
140134}
141- function isInProgress ( thisObj , fnName ) {
135+ function isCyclic ( thisObj , fnName ) {
142136 var cache = getCache ( thisObj , fnName ) ;
143137 return cache && cache . isInProgress ;
144138}
145139function cache ( fn , args , thisObj , fnName , equals ) {
146- if ( args === void 0 ) { args = [ ] ; }
147- if ( ! isValid ( args , thisObj , fnName , equals ) && ! isInProgress ( thisObj , fnName ) ) {
148- populate ( fn , args , thisObj , fnName ) ;
140+ if ( ! hitCache ( args , thisObj , fnName , equals ) && ! isCyclic ( thisObj , fnName ) ) {
141+ genCache ( fn , args , thisObj , fnName ) ;
149142 }
150143 return read ( thisObj , fnName ) ;
151144}
@@ -163,13 +156,14 @@ function memoized(equals) {
163156 } ;
164157}
165158
159+ var COST_MS_PRINT_THR = 0 ;
166160var RecursivePerfUtil = /** @class */ ( function ( ) {
167- function RecursivePerfUtil ( params ) {
161+ function RecursivePerfUtil ( ) {
168162 var _this = this ;
169163 this . root = Symbol ( "root" ) ;
170164 this . stack = [ ] ;
171165 this . initRecord = function ( ) {
172- return { obj : _this . root , childrenPerfInfo : [ ] , costMs : 0 , depth : 0 } ;
166+ return { obj : _this . root , name : "@root" , childrenPerfInfo : [ ] , costMs : 0 , depth : 0 , info : { } } ;
173167 } ;
174168 this . getRecordByStack = function ( stack ) {
175169 var curRecord = _this . record ;
@@ -181,28 +175,29 @@ var RecursivePerfUtil = /** @class */ (function () {
181175 this . clear = function ( ) {
182176 _this . record = _this . initRecord ( ) ;
183177 } ;
184- this . print = function ( ) {
185- var stack = [ ] ;
186- for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
187- stack [ _i ] = arguments [ _i ] ;
188- }
178+ this . print = function ( stack , cost_ms_print_thr ) {
179+ if ( cost_ms_print_thr === void 0 ) { cost_ms_print_thr = COST_MS_PRINT_THR ; }
189180 var record = _this . getRecordByStack ( stack ) ;
190- console . info ( "PerfInfo. stack: " . concat ( stack , ", [info] " ) . concat ( record . info , ", obj: " ) , record . obj , ", costMs : " . concat ( record . costMs , ", depth: " ) . concat ( record . depth , ", size: " ) . concat ( _ . size ( record . childrenPerfInfo ) ) ) ;
181+ console . info ( "~~ PerfInfo. costMs: " . concat ( record . costMs . toFixed ( 3 ) , ", stack: ") . concat ( stack , ", [name] " ) . concat ( record . name , ", [info] " ) , record . info , ", obj : " , record . obj , ", depth: " . concat ( record . depth , ", size: " ) . concat ( _ . size ( record . childrenPerfInfo ) ) ) ;
191182 record . childrenPerfInfo . forEach ( function ( subRecord , idx ) {
192- console . info ( " [" . concat ( idx , "]" ) . concat ( subRecord . info , ". obj: " ) , subRecord . obj , " costMs: " , subRecord . costMs ) ;
183+ if ( subRecord . costMs >= cost_ms_print_thr ) {
184+ console . info ( " costMs: " . concat ( subRecord . costMs . toFixed ( 3 ) , " [" ) . concat ( idx , "]" ) . concat ( subRecord . name , " [info]" ) , subRecord . info , ". obj: " , subRecord . obj , "" ) ;
185+ }
193186 } ) ;
194187 } ;
195- this . name = params . name ;
196188 this . record = this . initRecord ( ) ;
197189 }
198- RecursivePerfUtil . prototype . perf = function ( obj , info , fn ) {
190+ RecursivePerfUtil . prototype . log = function ( info , key , log ) {
191+ info [ key ] = log ;
192+ } ;
193+ RecursivePerfUtil . prototype . perf = function ( obj , name , fn ) {
199194 {
200- return fn ( ) ;
195+ return fn ( _ . noop ) ;
201196 }
202197 } ;
203198 return RecursivePerfUtil ;
204199} ( ) ) ;
205- var evalPerfUtil = new RecursivePerfUtil ( { name : "evaluate" } ) ;
200+ var evalPerfUtil = new RecursivePerfUtil ( ) ;
206201// @ts -ignore
207202globalThis . evalPerfUtil = evalPerfUtil ;
208203
@@ -365,8 +360,9 @@ var RecordNode = /** @class */ (function (_super) {
365360 } ) ;
366361 } ;
367362 RecordNode . prototype . justEval = function ( exposingNodes , methods ) {
368- return _ . mapValues ( this . children , function ( v ) {
369- return v . evaluate ( exposingNodes , methods ) ;
363+ var _this = this ;
364+ return _ . mapValues ( this . children , function ( v , key ) {
365+ return evalPerfUtil . perf ( _this , "eval-" . concat ( key ) , function ( ) { return v . evaluate ( exposingNodes , methods ) ; } ) ;
370366 } ) ;
371367 } ;
372368 RecordNode . prototype . getChildren = function ( ) {
@@ -7396,8 +7392,15 @@ See the accompanying LICENSE file for terms.
73967392var IntlMessageFormat = IntlMessageFormat$1 ;
73977393
73987394var defaultLocale = "en" ;
7399- var locales = navigator . languages && navigator . languages . length > 0
7400- ? __spreadArray ( [ ] , navigator . languages , true ) : [ navigator . language || navigator . userLanguage || defaultLocale ] ;
7395+ var locales = [ defaultLocale ] ;
7396+ if ( globalThis . navigator ) {
7397+ if ( navigator . languages && navigator . languages . length > 0 ) {
7398+ locales = __spreadArray ( [ ] , navigator . languages , true ) ;
7399+ }
7400+ else {
7401+ locales = [ navigator . language || navigator . userLanguage || defaultLocale ] ;
7402+ }
7403+ }
74017404function parseLocale ( s ) {
74027405 var locale = s . trim ( ) ;
74037406 if ( ! locale ) {
@@ -7431,11 +7434,16 @@ function getValueByLocale(defaultValue, func) {
74317434 }
74327435 return defaultValue ;
74337436}
7434- function getDataByLocale ( fileData , suffix , filterLocales ) {
7437+ function getDataByLocale ( fileData , suffix , filterLocales , targetLocales ) {
7438+ var localeInfos = __spreadArray ( [ ] , fallbackLocaleInfos , true ) ;
7439+ var targetLocaleInfo = parseLocales ( targetLocales || [ ] ) ;
7440+ if ( targetLocaleInfo . length > 0 ) {
7441+ localeInfos = __spreadArray ( __spreadArray ( [ ] , targetLocaleInfo , true ) , localeInfos , true ) ;
7442+ }
74357443 var filterNames = parseLocales ( ( filterLocales !== null && filterLocales !== void 0 ? filterLocales : "" ) . split ( "," ) )
74367444 . map ( function ( l ) { var _a ; return l . language + ( ( _a = l . region ) !== null && _a !== void 0 ? _a : "" ) ; } )
74377445 . filter ( function ( s ) { return fileData [ s + suffix ] !== undefined ; } ) ;
7438- var names = __spreadArray ( __spreadArray ( [ ] , fallbackLocaleInfos
7446+ var names = __spreadArray ( __spreadArray ( [ ] , localeInfos
74397447 . flatMap ( function ( _a ) {
74407448 var language = _a . language , region = _a . region ;
74417449 return [
@@ -7463,8 +7471,8 @@ var globalMessages = Object.fromEntries(Object.entries(getDataByLocale(localeDat
74637471 ] ;
74647472} ) ) ;
74657473var Translator = /** @class */ ( function ( ) {
7466- function Translator ( fileData , filterLocales ) {
7467- var _a = getDataByLocale ( fileData , "" , filterLocales ) , data = _a . data , language = _a . language ;
7474+ function Translator ( fileData , filterLocales , locales ) {
7475+ var _a = getDataByLocale ( fileData , "" , filterLocales , locales ) , data = _a . data , language = _a . language ;
74687476 this . messages = Object . assign ( { } , data , globalMessages ) ;
74697477 this . language = language ;
74707478 this . trans = this . trans . bind ( this ) ;
0 commit comments