@nxtedition/lib 14.0.0 → 14.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/javascript.js +47 -19
package/package.json
CHANGED
|
@@ -141,6 +141,8 @@ function proxyify(value, expression) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
const MAP_POOL = []
|
|
145
|
+
|
|
144
146
|
module.exports = ({ ds, ...options }) => {
|
|
145
147
|
class Expression {
|
|
146
148
|
constructor(context, script, expression, args, observer) {
|
|
@@ -151,7 +153,7 @@ module.exports = ({ ds, ...options }) => {
|
|
|
151
153
|
|
|
152
154
|
// TODO (perf): This could be faster by using an array + indices.
|
|
153
155
|
// A bit similar to how react-hooks works.
|
|
154
|
-
this._entries =
|
|
156
|
+
this._entries = null
|
|
155
157
|
this._refreshing = false
|
|
156
158
|
this._counter = 0
|
|
157
159
|
this._value = kEmpty
|
|
@@ -159,26 +161,31 @@ module.exports = ({ ds, ...options }) => {
|
|
|
159
161
|
this._destroyed = false
|
|
160
162
|
this._subscription = null
|
|
161
163
|
this._args = null
|
|
162
|
-
this.
|
|
163
|
-
this._handler =
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
this._ready = false
|
|
165
|
+
this._handler = options.proxyify
|
|
166
|
+
? {
|
|
167
|
+
get: (target, prop) => proxyify(target[prop], this),
|
|
168
|
+
}
|
|
169
|
+
: null
|
|
167
170
|
|
|
168
171
|
if (rxjs.isObservable(args)) {
|
|
169
172
|
this._subscription = args.subscribe({
|
|
170
173
|
next: (args) => {
|
|
171
|
-
this._args = this.
|
|
172
|
-
this.
|
|
174
|
+
this._args = this._handler ? proxyify(args, this) : args
|
|
175
|
+
this._ready = true
|
|
173
176
|
this._refresh()
|
|
174
177
|
},
|
|
175
178
|
error: (err) => {
|
|
176
179
|
this._observer.error(err)
|
|
180
|
+
this._subscription = null
|
|
181
|
+
},
|
|
182
|
+
complete: () => {
|
|
183
|
+
this._subscription = null
|
|
177
184
|
},
|
|
178
185
|
})
|
|
179
186
|
} else {
|
|
180
|
-
this._args = this.
|
|
181
|
-
this.
|
|
187
|
+
this._args = this._handler ? proxyify(args, this) : args
|
|
188
|
+
this._ready = true
|
|
182
189
|
}
|
|
183
190
|
|
|
184
191
|
this._refreshNT(this)
|
|
@@ -231,16 +238,25 @@ module.exports = ({ ds, ...options }) => {
|
|
|
231
238
|
_destroy() {
|
|
232
239
|
this._destroyed = true
|
|
233
240
|
this._subscription?.unsubscribe()
|
|
234
|
-
|
|
235
|
-
|
|
241
|
+
|
|
242
|
+
if (this._entries) {
|
|
243
|
+
for (const entry of this._entries.values()) {
|
|
244
|
+
entry.dispose()
|
|
245
|
+
}
|
|
246
|
+
this._entries.clear()
|
|
247
|
+
|
|
248
|
+
if (MAP_POOL.length < 1024) {
|
|
249
|
+
MAP_POOL.push(this._entries)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
this._entries = null
|
|
236
253
|
}
|
|
237
|
-
this._entries.clear()
|
|
238
254
|
}
|
|
239
255
|
|
|
240
256
|
_refreshNT(self) {
|
|
241
257
|
self._refreshing = false
|
|
242
258
|
|
|
243
|
-
if (self._destroyed || self._disposing || !self.
|
|
259
|
+
if (self._destroyed || self._disposing || !self._ready) {
|
|
244
260
|
return
|
|
245
261
|
}
|
|
246
262
|
|
|
@@ -271,18 +287,29 @@ module.exports = ({ ds, ...options }) => {
|
|
|
271
287
|
self._context.nxt = null
|
|
272
288
|
|
|
273
289
|
self._disposing = true
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
290
|
+
|
|
291
|
+
if (self._entries) {
|
|
292
|
+
for (const entry of self._entries.values()) {
|
|
293
|
+
if (entry.counter !== self._counter) {
|
|
294
|
+
entry.dispose()
|
|
295
|
+
self._entries.delete(entry.key)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (self._entries.size === 0) {
|
|
299
|
+
self._entries = null
|
|
278
300
|
}
|
|
279
301
|
}
|
|
302
|
+
|
|
303
|
+
if (!self._entries) {
|
|
304
|
+
self._args = null
|
|
305
|
+
}
|
|
306
|
+
|
|
280
307
|
self._disposing = false
|
|
281
308
|
}
|
|
282
309
|
}
|
|
283
310
|
|
|
284
311
|
_refresh = () => {
|
|
285
|
-
if (this._refreshing || this._destroyed || this._disposing || !this.
|
|
312
|
+
if (this._refreshing || this._destroyed || this._disposing || !this._ready) {
|
|
286
313
|
return
|
|
287
314
|
}
|
|
288
315
|
|
|
@@ -291,6 +318,7 @@ module.exports = ({ ds, ...options }) => {
|
|
|
291
318
|
}
|
|
292
319
|
|
|
293
320
|
_getEntry(key, Entry, opaque) {
|
|
321
|
+
this._entries ??= MAP_POOL.pop() ?? new Map()
|
|
294
322
|
let entry = this._entries.get(key)
|
|
295
323
|
if (!entry) {
|
|
296
324
|
entry = new Entry(key, this._refresh, opaque)
|