@nxtedition/lib 14.0.0-alpha.2 → 14.0.0
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.js +43 -50
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports = (options) => {
|
|
|
22
22
|
try {
|
|
23
23
|
return compileObjectTemplate(obj)(...args)
|
|
24
24
|
} catch (err) {
|
|
25
|
-
return rxjs.throwError(err)
|
|
25
|
+
return rxjs.throwError(() => err)
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -37,27 +37,25 @@ module.exports = (options) => {
|
|
|
37
37
|
for (let i = 0; i < arr.length; i++) {
|
|
38
38
|
const resolver = compileTemplateLazy(arr[i])
|
|
39
39
|
if (resolver) {
|
|
40
|
-
resolvers ??= []
|
|
40
|
+
resolvers ??= [() => rxjs.of({ indices, arr })]
|
|
41
41
|
resolvers.push(resolver)
|
|
42
42
|
indices ??= []
|
|
43
43
|
indices.push(i)
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
)
|
|
47
|
+
return resolvers
|
|
48
|
+
? (...args) =>
|
|
49
|
+
rxjs.combineLatest(resolvers.map((resolver) => resolver(...args))).pipe(
|
|
50
|
+
rx.map((values) => {
|
|
51
|
+
const ret = [...arr]
|
|
52
|
+
for (let n = 0; n < values.length; n++) {
|
|
53
|
+
ret[indices[n]] = values[n]
|
|
54
|
+
}
|
|
55
|
+
return ret
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
: null
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
const compileArrayTemplate = weakCache(function compileArrayTemplate(arr) {
|
|
@@ -84,20 +82,18 @@ module.exports = (options) => {
|
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
)
|
|
85
|
+
return resolvers
|
|
86
|
+
? (...args) =>
|
|
87
|
+
rxjs.combineLatest(resolvers.map((resolver) => resolver(...args))).pipe(
|
|
88
|
+
rx.map((values) => {
|
|
89
|
+
const ret = { ...obj }
|
|
90
|
+
for (let n = 0; n < values.length; n++) {
|
|
91
|
+
ret[indices[n]] = values[n]
|
|
92
|
+
}
|
|
93
|
+
return ret
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
: null
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
const compileObjectTemplate = weakCache(function compileObjectTemplate(obj) {
|
|
@@ -133,30 +129,27 @@ module.exports = (options) => {
|
|
|
133
129
|
}
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
const _compileStringTemplate = weakCache(
|
|
137
|
-
|
|
138
|
-
const { pre, type, body, post } = match
|
|
132
|
+
const _compileStringTemplate = weakCache(function _compileStringTemplate(str, match) {
|
|
133
|
+
const { pre, type, body, post } = match
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
const compileExpression = compilers[type]
|
|
136
|
+
if (!compileExpression) {
|
|
137
|
+
throw new Error('unknown expression type: ' + type)
|
|
138
|
+
}
|
|
144
139
|
|
|
145
|
-
|
|
140
|
+
const expr = compileExpression(body)
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
if (!pre && !post) {
|
|
143
|
+
return expr
|
|
144
|
+
}
|
|
150
145
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)
|
|
146
|
+
return (...args) =>
|
|
147
|
+
expr(...args).pipe(
|
|
148
|
+
rx.switchMap((body) =>
|
|
149
|
+
compileStringTemplate(`${pre}${stringify(body, type !== 'js')}${post}`)(...args)
|
|
156
150
|
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
151
|
+
)
|
|
152
|
+
})
|
|
160
153
|
|
|
161
154
|
function compileStringTemplateLazy(str) {
|
|
162
155
|
if (!fp.isString(str)) {
|
|
@@ -224,7 +217,7 @@ module.exports = (options) => {
|
|
|
224
217
|
try {
|
|
225
218
|
return compileTemplate(str)(...args)
|
|
226
219
|
} catch (err) {
|
|
227
|
-
return rxjs.throwError(err)
|
|
220
|
+
return rxjs.throwError(() => err)
|
|
228
221
|
}
|
|
229
222
|
}
|
|
230
223
|
|