j-templates 6.1.3 → 6.1.5
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/Store/Tree/observableScope.js +6 -17
- package/Utils/array.d.ts +1 -0
- package/Utils/array.js +19 -0
- package/Utils/emitter.js +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObservableScope = exports.ObservableScopeWrapper = exports.ObservableScopeValue = void 0;
|
|
4
4
|
exports.CalcScope = CalcScope;
|
|
5
|
+
const array_1 = require("../../Utils/array");
|
|
5
6
|
const emitter_1 = require("../../Utils/emitter");
|
|
6
7
|
const list_1 = require("../../Utils/list");
|
|
7
8
|
class ObservableScopeValue {
|
|
@@ -206,23 +207,11 @@ function UpdateEmitters(scope) {
|
|
|
206
207
|
return;
|
|
207
208
|
}
|
|
208
209
|
emitter_1.Emitter.Sort(right);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
for (; y < right.length && left[leftIndex] !== right[y]; y++)
|
|
215
|
-
emitter_1.Emitter.On(right[rightIndex], scope.setCallback);
|
|
216
|
-
if (y === right.length)
|
|
217
|
-
emitter_1.Emitter.Remove(left[leftIndex], scope.setCallback);
|
|
218
|
-
else {
|
|
219
|
-
for (let x = rightIndex; x < y; x++)
|
|
220
|
-
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
221
|
-
rightIndex = y + 1;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
for (; rightIndex < right.length; rightIndex++)
|
|
225
|
-
emitter_1.Emitter.On(right[rightIndex], scope.setCallback);
|
|
210
|
+
(0, array_1.ReconcileSortedArrays)(scope.emitters, right, function (emitter) {
|
|
211
|
+
emitter_1.Emitter.On(emitter, scope.setCallback);
|
|
212
|
+
}, function (emitter) {
|
|
213
|
+
emitter_1.Emitter.Remove(emitter, scope.setCallback);
|
|
214
|
+
});
|
|
226
215
|
scope.emitters = right;
|
|
227
216
|
}
|
|
228
217
|
function DestroyScope(scope) {
|
package/Utils/array.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function RemoveNulls(array: (unknown | null)[], startIndex?: number): void;
|
|
2
2
|
export declare function ArrayDiff(source: any[], target: any[]): boolean;
|
|
3
|
+
export declare function ReconcileSortedArrays<T>(left: T[], right: T[], add: (value: T) => void, remove: (value: T) => void): void;
|
package/Utils/array.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoveNulls = RemoveNulls;
|
|
4
4
|
exports.ArrayDiff = ArrayDiff;
|
|
5
|
+
exports.ReconcileSortedArrays = ReconcileSortedArrays;
|
|
5
6
|
function RemoveNulls(array, startIndex = 0) {
|
|
6
7
|
let nullIndex = startIndex;
|
|
7
8
|
for (; nullIndex < array.length && array[nullIndex] !== null; nullIndex++) { }
|
|
@@ -24,3 +25,21 @@ function ArrayDiff(source, target) {
|
|
|
24
25
|
for (; x < source.length && source[x] === target[x]; x++) { }
|
|
25
26
|
return x < source.length;
|
|
26
27
|
}
|
|
28
|
+
function ReconcileSortedArrays(left, right, add, remove) {
|
|
29
|
+
let leftIndex = 0;
|
|
30
|
+
let rightIndex = 0;
|
|
31
|
+
while (leftIndex < left.length && rightIndex < right.length) {
|
|
32
|
+
let y = rightIndex;
|
|
33
|
+
for (; y < right.length && left[leftIndex] !== right[y]; y++) { }
|
|
34
|
+
if (y === right.length)
|
|
35
|
+
remove(left[leftIndex]);
|
|
36
|
+
else {
|
|
37
|
+
for (let z = rightIndex; z < y; z++)
|
|
38
|
+
add(right[z]);
|
|
39
|
+
rightIndex = y + 1;
|
|
40
|
+
}
|
|
41
|
+
leftIndex++;
|
|
42
|
+
}
|
|
43
|
+
for (; rightIndex < right.length; rightIndex++)
|
|
44
|
+
add(right[rightIndex]);
|
|
45
|
+
}
|
package/Utils/emitter.js
CHANGED