j-templates 7.0.56 → 7.0.57
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/Node/vNode.js +71 -39
- package/Node/vNode.types.d.ts +1 -1
- package/Store/Tree/observableScope.d.ts +3 -0
- package/Store/Tree/observableScope.js +21 -2
- package/package.json +1 -1
package/Node/vNode.js
CHANGED
|
@@ -58,8 +58,10 @@ var vNode;
|
|
|
58
58
|
vnode.component?.Destroy();
|
|
59
59
|
Store_1.ObservableScope.DestroyAll(vnode.scopes);
|
|
60
60
|
vnode.onDestroyed && emitter_1.Emitter.Emit(vnode.onDestroyed);
|
|
61
|
-
for (let x = 0; vnode.children && x < vnode.children.length; x++)
|
|
61
|
+
for (let x = 0; vnode.children && x < vnode.children.length; x++) {
|
|
62
62
|
DestroyAll(vnode.children[x][1]);
|
|
63
|
+
Store_1.ObservableScope.Destroy(vnode.children[x][2]);
|
|
64
|
+
}
|
|
63
65
|
}
|
|
64
66
|
vNode.Destroy = Destroy;
|
|
65
67
|
function DestroyAll(vnodes) {
|
|
@@ -97,10 +99,11 @@ function InitNode(vnode) {
|
|
|
97
99
|
if (props) {
|
|
98
100
|
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
99
101
|
if (typeof props === "function") {
|
|
100
|
-
const scope = Store_1.ObservableScope.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const [value, scope] = Store_1.ObservableScope.CreateIf(props);
|
|
103
|
+
if (scope) {
|
|
104
|
+
vnode.scopes.push(scope);
|
|
105
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
|
|
106
|
+
}
|
|
104
107
|
assignProperties(value);
|
|
105
108
|
}
|
|
106
109
|
else
|
|
@@ -109,27 +112,24 @@ function InitNode(vnode) {
|
|
|
109
112
|
if (on) {
|
|
110
113
|
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
111
114
|
if (typeof on === "function") {
|
|
112
|
-
const scope = Store_1.ObservableScope.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const [value, scope] = Store_1.ObservableScope.CreateIf(on);
|
|
116
|
+
if (scope) {
|
|
117
|
+
vnode.scopes.push(scope);
|
|
118
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
|
|
119
|
+
}
|
|
116
120
|
assignEvents(value);
|
|
117
121
|
}
|
|
118
122
|
else
|
|
119
123
|
assignEvents(on);
|
|
120
|
-
vnode.onDestroyed ??= emitter_1.Emitter.Create();
|
|
121
|
-
emitter_1.Emitter.On(vnode.onDestroyed, function () {
|
|
122
|
-
assignEvents(null);
|
|
123
|
-
return true;
|
|
124
|
-
});
|
|
125
124
|
}
|
|
126
125
|
if (attrs) {
|
|
127
126
|
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
128
127
|
if (typeof attrs === "function") {
|
|
129
|
-
const scope = Store_1.ObservableScope.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
const [value, scope] = Store_1.ObservableScope.CreateIf(attrs);
|
|
129
|
+
if (scope) {
|
|
130
|
+
vnode.scopes.push(scope);
|
|
131
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
|
|
132
|
+
}
|
|
133
133
|
assignAttributes(value);
|
|
134
134
|
}
|
|
135
135
|
else
|
|
@@ -144,7 +144,7 @@ function InitNode(vnode) {
|
|
|
144
144
|
Children(vnode, componentChildren, DefaultData);
|
|
145
145
|
}
|
|
146
146
|
else if (childrenArray) {
|
|
147
|
-
vnode.children = [[undefined, childrenArray]];
|
|
147
|
+
vnode.children = [[undefined, childrenArray, null]];
|
|
148
148
|
vNode.InitAll(childrenArray);
|
|
149
149
|
}
|
|
150
150
|
else if (children) {
|
|
@@ -199,9 +199,9 @@ function WrapChildren(injector, children, data) {
|
|
|
199
199
|
case 0: {
|
|
200
200
|
for (let x = 0; x < nodeArray.length; x++) {
|
|
201
201
|
vNode.DestroyAll(nodeArray[x][1]);
|
|
202
|
+
Store_1.ObservableScope.Destroy(nodeArray[x][2]);
|
|
202
203
|
}
|
|
203
204
|
nodeArray.splice(0);
|
|
204
|
-
return [];
|
|
205
205
|
}
|
|
206
206
|
default: {
|
|
207
207
|
if (nodeArray.length < 21)
|
|
@@ -214,30 +214,47 @@ function WrapChildren(injector, children, data) {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
function EvaluateNextNodesSmall(injector, getNextChildren, nextData, nodeArray) {
|
|
217
|
-
if (nextData
|
|
217
|
+
if (nextData === DEFAULT_DATA) {
|
|
218
218
|
const nextChildren = injector_1.Injector.Scope(injector, getNextChildren, nextData[0]);
|
|
219
219
|
const children = CreateNodeArray(nextChildren, nodeArray[0]?.[1]);
|
|
220
|
-
for (let x = 0; x < nodeArray.length; x++)
|
|
220
|
+
for (let x = 0; x < nodeArray.length; x++) {
|
|
221
221
|
vNode.DestroyAll(nodeArray[x][1]);
|
|
222
|
-
|
|
222
|
+
Store_1.ObservableScope.Destroy(nodeArray[x][2]);
|
|
223
|
+
}
|
|
224
|
+
return [
|
|
225
|
+
[undefined, children, null],
|
|
226
|
+
];
|
|
223
227
|
}
|
|
224
|
-
let nodeArrayLength = nodeArray.length;
|
|
225
228
|
const nextNodes = new Array(nextData.length);
|
|
226
229
|
for (let x = 0; x < nextData.length; x++) {
|
|
227
230
|
const data = nextData[x];
|
|
228
|
-
const nextChildren = injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
229
231
|
let i = 0;
|
|
230
|
-
for (; i <
|
|
231
|
-
|
|
232
|
+
for (; i < nodeArray.length &&
|
|
233
|
+
(nodeArray[i] === null || nodeArray[i][0] !== data); i++) { }
|
|
234
|
+
if (i !== nodeArray.length) {
|
|
235
|
+
if (nodeArray[i][2]) {
|
|
236
|
+
const scope = nodeArray[i][2];
|
|
237
|
+
const value = scope.value;
|
|
238
|
+
const updatedValue = Store_1.ObservableScope.Value(scope);
|
|
239
|
+
if (value !== updatedValue)
|
|
240
|
+
nodeArray[i][1] = CreateNodeArray(updatedValue);
|
|
241
|
+
}
|
|
232
242
|
nextNodes[x] = nodeArray[i];
|
|
233
|
-
nodeArray[i] =
|
|
234
|
-
|
|
243
|
+
nodeArray[i] = null;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const [nextChildren, scope] = Store_1.ObservableScope.CreateIf(function () {
|
|
247
|
+
return injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
248
|
+
});
|
|
249
|
+
nextNodes[x] = [data, CreateNodeArray(nextChildren), scope];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (let x = 0; x < nodeArray.length; x++) {
|
|
253
|
+
if (nodeArray[x] !== null) {
|
|
254
|
+
vNode.DestroyAll(nodeArray[x][1]);
|
|
255
|
+
Store_1.ObservableScope.Destroy(nodeArray[x][2]);
|
|
235
256
|
}
|
|
236
|
-
else
|
|
237
|
-
nextNodes[x] = [data, CreateNodeArray(nextChildren)];
|
|
238
257
|
}
|
|
239
|
-
for (let x = 0; x < nodeArrayLength; x++)
|
|
240
|
-
vNode.DestroyAll(nodeArray[x][1]);
|
|
241
258
|
return nextNodes;
|
|
242
259
|
}
|
|
243
260
|
function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray) {
|
|
@@ -245,29 +262,44 @@ function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray)
|
|
|
245
262
|
const dataMap = new Map();
|
|
246
263
|
for (let x = 0; x < nodeArray.length; x++) {
|
|
247
264
|
const arr = dataMap.get(nodeArray[x][0]) ?? [];
|
|
248
|
-
arr.push(nodeArray[x]
|
|
265
|
+
arr.push(nodeArray[x]);
|
|
249
266
|
dataMap.set(nodeArray[x][0], arr);
|
|
250
267
|
}
|
|
251
268
|
for (let x = 0; x < nextData.length; x++) {
|
|
252
269
|
const data = nextData[x];
|
|
253
|
-
const nextChildren = injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
254
270
|
const currentChildren = dataMap.get(data);
|
|
255
271
|
let currentChildIndex = currentChildren ? currentChildren.length - 1 : -1;
|
|
256
272
|
for (; currentChildIndex >= 0 && currentChildren[currentChildIndex] === null; currentChildIndex--) { }
|
|
257
273
|
if (currentChildIndex !== -1) {
|
|
258
|
-
|
|
274
|
+
const currentChild = currentChildren[currentChildIndex];
|
|
275
|
+
if (currentChild[2]) {
|
|
276
|
+
const scope = currentChild[2];
|
|
277
|
+
const value = scope.value;
|
|
278
|
+
const updatedValue = Store_1.ObservableScope.Value(scope);
|
|
279
|
+
if (value !== updatedValue)
|
|
280
|
+
currentChild[1] = CreateNodeArray(updatedValue);
|
|
281
|
+
}
|
|
282
|
+
if (currentChild[2]?.dirty) {
|
|
283
|
+
const nextChildren = Store_1.ObservableScope.Value(currentChild[2]);
|
|
284
|
+
currentChild[1] = CreateNodeArray(nextChildren);
|
|
285
|
+
}
|
|
286
|
+
nextNodes[x] = currentChild;
|
|
259
287
|
currentChildren[currentChildIndex] = null;
|
|
260
288
|
if (currentChildIndex === 0)
|
|
261
289
|
dataMap.delete(data);
|
|
262
290
|
}
|
|
263
291
|
else {
|
|
264
|
-
|
|
292
|
+
const [nextChildren, scope] = Store_1.ObservableScope.CreateIf(function () {
|
|
293
|
+
return injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
294
|
+
});
|
|
295
|
+
nextNodes[x] = [data, CreateNodeArray(nextChildren), scope];
|
|
265
296
|
}
|
|
266
297
|
}
|
|
267
298
|
for (const value of dataMap.values()) {
|
|
268
299
|
for (let x = 0; x < value.length; x++) {
|
|
269
|
-
|
|
270
|
-
|
|
300
|
+
const row = value[x];
|
|
301
|
+
row && vNode.DestroyAll(row[1]);
|
|
302
|
+
row && Store_1.ObservableScope.Destroy(row[2]);
|
|
271
303
|
}
|
|
272
304
|
}
|
|
273
305
|
return nextNodes;
|
package/Node/vNode.types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type vNode = {
|
|
|
19
19
|
definition: vNodeDefinition<any, any, any>;
|
|
20
20
|
injector: Injector;
|
|
21
21
|
node: Node | null;
|
|
22
|
-
children: [any, vNode[]][] | null;
|
|
22
|
+
children: [any, vNode[], IObservableScope<string | vNode | vNode[]> | null][] | null;
|
|
23
23
|
destroyed: boolean;
|
|
24
24
|
onDestroyed: Emitter | null;
|
|
25
25
|
scopes: IObservableScope<unknown>[];
|
|
@@ -47,6 +47,9 @@ export declare namespace ObservableScope {
|
|
|
47
47
|
function Create<T>(valueFunction: {
|
|
48
48
|
(): T | Promise<T>;
|
|
49
49
|
}, calc?: boolean): IObservableScope<T>;
|
|
50
|
+
function CreateIf<T>(valueFunction: {
|
|
51
|
+
(): T | Promise<T>;
|
|
52
|
+
}): [T, IObservableScope<T> | null];
|
|
50
53
|
function Register(emitter: Emitter): void;
|
|
51
54
|
function Init<T>(scope: IObservableScope<T>): void;
|
|
52
55
|
function Peek<T>(scope: IObservableScope<T>): T;
|
|
@@ -65,6 +65,21 @@ function WatchScope(scope) {
|
|
|
65
65
|
watchState = parent;
|
|
66
66
|
return value;
|
|
67
67
|
}
|
|
68
|
+
function WatchFunction(func) {
|
|
69
|
+
const parent = watchState;
|
|
70
|
+
watchState = [[], null, null];
|
|
71
|
+
const async = (0, functions_1.IsAsync)(func);
|
|
72
|
+
const result = func();
|
|
73
|
+
let scope = null;
|
|
74
|
+
if (watchState[0].length > 0 || async) {
|
|
75
|
+
scope = ObservableScope.Create(func);
|
|
76
|
+
UpdateEmitters(scope, watchState[0]);
|
|
77
|
+
scope.calcScopes = watchState[2];
|
|
78
|
+
UpdateValue(scope, result);
|
|
79
|
+
}
|
|
80
|
+
watchState = parent;
|
|
81
|
+
return [async ? null : result, scope];
|
|
82
|
+
}
|
|
68
83
|
function CalcScope(callback, idOverride) {
|
|
69
84
|
if (watchState === null)
|
|
70
85
|
return callback();
|
|
@@ -103,6 +118,10 @@ function CalcScope(callback, idOverride) {
|
|
|
103
118
|
return scope;
|
|
104
119
|
}
|
|
105
120
|
ObservableScope.Create = Create;
|
|
121
|
+
function CreateIf(valueFunction) {
|
|
122
|
+
return WatchFunction(valueFunction);
|
|
123
|
+
}
|
|
124
|
+
ObservableScope.CreateIf = CreateIf;
|
|
106
125
|
function Register(emitter) {
|
|
107
126
|
if (watchState === null)
|
|
108
127
|
return;
|
|
@@ -205,11 +224,11 @@ function OnSet(scope) {
|
|
|
205
224
|
}
|
|
206
225
|
DirtyScope(scope);
|
|
207
226
|
}
|
|
208
|
-
function UpdateValue(scope) {
|
|
227
|
+
function UpdateValue(scope, valueOverride = undefined) {
|
|
209
228
|
if (!scope.dirty)
|
|
210
229
|
return;
|
|
211
230
|
scope.dirty = false;
|
|
212
|
-
const value = WatchScope(scope);
|
|
231
|
+
const value = valueOverride === undefined ? WatchScope(scope) : valueOverride;
|
|
213
232
|
if (scope.async) {
|
|
214
233
|
scope.promise = value.then(function (result) {
|
|
215
234
|
if (scope.destroyed)
|