@nxtedition/lib 24.0.0 → 24.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/util/template/index-common.js +29 -14
- package/yield.js +7 -2
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@ import getNxtpressionsCompiler from './nextpressions.js'
|
|
|
4
4
|
import getJavascriptCompiler from './javascript.js'
|
|
5
5
|
import JSON5 from 'json5'
|
|
6
6
|
import objectHash from 'object-hash'
|
|
7
|
-
import { makeWeakCache } from '../../weakCache.js'
|
|
8
7
|
import firstValueFrom from '../../rxjs/firstValueFrom.js'
|
|
8
|
+
import { LRUCache } from 'lru-cache'
|
|
9
9
|
|
|
10
10
|
export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
11
11
|
const compiler = {
|
|
@@ -210,20 +210,35 @@ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
|
210
210
|
return typeof val === 'string' && val.indexOf('{{') !== -1
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
213
|
+
const objCache = new WeakMap()
|
|
214
|
+
const strCache = new LRUCache({ max: 8192 })
|
|
215
|
+
|
|
216
|
+
const _compileTemplateCache = (template) => {
|
|
217
|
+
if (fp.isPlainObject(template)) {
|
|
218
|
+
let resolver = objCache.get(template)
|
|
219
|
+
if (resolver == null) {
|
|
220
|
+
resolver = compileObjectTemplate(template)
|
|
221
|
+
objCache.set(template, resolver)
|
|
222
|
+
}
|
|
223
|
+
return resolver
|
|
224
|
+
} else if (Array.isArray(template)) {
|
|
225
|
+
let resolver = objCache.get(template)
|
|
226
|
+
if (resolver == null) {
|
|
227
|
+
resolver = compileArrayTemplate(template)
|
|
228
|
+
objCache.set(template, resolver)
|
|
223
229
|
}
|
|
224
|
-
|
|
225
|
-
(template
|
|
226
|
-
|
|
230
|
+
return resolver
|
|
231
|
+
} else if (isTemplate(template)) {
|
|
232
|
+
let resolver = strCache.get(template)
|
|
233
|
+
if (resolver == null) {
|
|
234
|
+
resolver = compileStringTemplate(template)
|
|
235
|
+
strCache.set(template, resolver)
|
|
236
|
+
}
|
|
237
|
+
return resolver
|
|
238
|
+
} else {
|
|
239
|
+
return null
|
|
240
|
+
}
|
|
241
|
+
}
|
|
227
242
|
|
|
228
243
|
function _compileTemplate(template) {
|
|
229
244
|
const hash = hashTemplate(template)
|
package/yield.js
CHANGED
|
@@ -14,10 +14,15 @@ export function setYieldTimeout(timeout) {
|
|
|
14
14
|
yieldTimeout = timeout
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function shouldYield() {
|
|
18
|
-
if (
|
|
17
|
+
export function shouldYield(timeout) {
|
|
18
|
+
if (timeout === undefined) {
|
|
19
|
+
timeout = yieldTimeout
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!yieldActive && performance.now() - yieldTime >= timeout) {
|
|
19
23
|
yieldActive = true
|
|
20
24
|
}
|
|
25
|
+
|
|
21
26
|
return yieldActive
|
|
22
27
|
}
|
|
23
28
|
|