j-templates 7.0.72 → 7.0.73
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.
|
@@ -5,7 +5,6 @@ exports.CalcScope = CalcScope;
|
|
|
5
5
|
const array_1 = require("../../Utils/array");
|
|
6
6
|
const emitter_1 = require("../../Utils/emitter");
|
|
7
7
|
const functions_1 = require("../../Utils/functions");
|
|
8
|
-
const list_1 = require("../../Utils/list");
|
|
9
8
|
/**
|
|
10
9
|
* Creates a dynamic (reactive) observable scope.
|
|
11
10
|
* @template T The type of value stored in the scope.
|
|
@@ -210,38 +209,6 @@ const SORTED_STRATEGY = 3;
|
|
|
210
209
|
const DISTINCT_STRATEGY = 4;
|
|
211
210
|
const SHRINK_STRATEGY = 5;
|
|
212
211
|
let watchState = null;
|
|
213
|
-
const watchPool = list_1.List.Create();
|
|
214
|
-
/**
|
|
215
|
-
* Creates a new watch state object, reusing from pool if available.
|
|
216
|
-
* Object pooling reduces GC pressure during frequent watch operations.
|
|
217
|
-
* @returns A new or recycled watch state object.
|
|
218
|
-
*/
|
|
219
|
-
function CreateWatchState() {
|
|
220
|
-
return (list_1.List.Pop(watchPool) ?? {
|
|
221
|
-
emitterIndex: 0,
|
|
222
|
-
value: null,
|
|
223
|
-
emitters: null,
|
|
224
|
-
emitterIds: null,
|
|
225
|
-
currentCalc: null,
|
|
226
|
-
nextCalc: null,
|
|
227
|
-
strategy: PUSH_STRATEGY,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Returns a watch state object to the pool for reuse.
|
|
232
|
-
* Resets all fields to their default values before pooling.
|
|
233
|
-
* @param state The watch state to return to the pool.
|
|
234
|
-
*/
|
|
235
|
-
function ReturnWatchState(state) {
|
|
236
|
-
state.emitterIndex = 0;
|
|
237
|
-
state.value = null;
|
|
238
|
-
state.emitters = null;
|
|
239
|
-
state.emitterIds = null;
|
|
240
|
-
state.currentCalc = null;
|
|
241
|
-
state.nextCalc = null;
|
|
242
|
-
state.strategy = SORTED_STRATEGY;
|
|
243
|
-
list_1.List.Push(watchPool, state);
|
|
244
|
-
}
|
|
245
212
|
/**
|
|
246
213
|
* Executes a callback while tracking all scope and emitter dependencies.
|
|
247
214
|
* Creates a watch context that records what was accessed during execution.
|
|
@@ -251,11 +218,15 @@ function ReturnWatchState(state) {
|
|
|
251
218
|
*/
|
|
252
219
|
function WatchFunction(callback, currentCalc, initialEmitters) {
|
|
253
220
|
const parent = watchState;
|
|
254
|
-
watchState =
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
221
|
+
watchState = {
|
|
222
|
+
emitterIndex: 0,
|
|
223
|
+
value: null,
|
|
224
|
+
emitters: initialEmitters ?? [],
|
|
225
|
+
emitterIds: null,
|
|
226
|
+
currentCalc,
|
|
227
|
+
nextCalc: null,
|
|
228
|
+
strategy: initialEmitters === null ? SORTED_STRATEGY : SAME_STRATEGY,
|
|
229
|
+
};
|
|
259
230
|
watchState.value = callback();
|
|
260
231
|
const resultState = watchState;
|
|
261
232
|
watchState = parent;
|
|
@@ -286,7 +257,6 @@ function ExecuteScope(scope) {
|
|
|
286
257
|
});
|
|
287
258
|
else
|
|
288
259
|
scope.value = state.value;
|
|
289
|
-
ReturnWatchState(state);
|
|
290
260
|
}
|
|
291
261
|
/**
|
|
292
262
|
* Creates a scope from a function, choosing between static and dynamic based on dependencies.
|
|
@@ -308,11 +278,9 @@ function ExecuteFunction(callback, greedy, allowStatic) {
|
|
|
308
278
|
scope.value = result;
|
|
309
279
|
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
310
280
|
});
|
|
311
|
-
ReturnWatchState(state);
|
|
312
281
|
return scope;
|
|
313
282
|
}
|
|
314
283
|
const value = state.value;
|
|
315
|
-
ReturnWatchState(state);
|
|
316
284
|
return CreateStaticScope(value);
|
|
317
285
|
}
|
|
318
286
|
/**
|