j-templates 7.0.90 → 7.0.92
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/DOM/createAssignment.d.ts +3 -0
- package/DOM/createAssignment.js +6 -0
- package/DOM/createAttributeAssignment.d.ts +1 -0
- package/DOM/createAttributeAssignment.js +4 -0
- package/DOM/createEventAssignment.d.ts +1 -0
- package/DOM/createEventAssignment.js +4 -0
- package/DOM/createPropertyAssignment.d.ts +1 -0
- package/DOM/createPropertyAssignment.js +29 -0
- package/DOM/domNodeConfig.js +35 -15
- package/Node/component.js +2 -0
- package/Node/nodeConfig.d.ts +3 -0
- package/Node/vNode.js +61 -160
- package/Node/vNode.types.d.ts +1 -5
- package/Store/Store/store.js +1 -1
- package/Store/Store/storeAsync.js +1 -1
- package/Store/Store/storeSync.js +3 -3
- package/Store/Tree/observableNode.d.ts +1 -15
- package/Store/Tree/observableNode.js +129 -112
- package/Store/Tree/observableScope.d.ts +29 -11
- package/Store/Tree/observableScope.js +162 -52
- package/Utils/decorators.js +4 -4
- package/Utils/emitter.d.ts +1 -3
- package/Utils/emitter.js +43 -92
- package/Utils/functions.js +1 -1
- package/Utils/json.js +3 -3
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/package.json +1 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare function Assignment(target: any, next: any, assignment: {
|
|
2
|
+
(target: any, key: string, value: any): void;
|
|
3
|
+
}): void;
|
|
1
4
|
export declare function CreateAssignment(target: any, createAssignment: {
|
|
2
5
|
(target: any, key: string): (next: any) => void;
|
|
3
6
|
}): (next: any) => void;
|
package/DOM/createAssignment.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Assignment = Assignment;
|
|
3
4
|
exports.CreateAssignment = CreateAssignment;
|
|
4
5
|
const DEFAULT_ASSIGNMENT = {};
|
|
6
|
+
function Assignment(target, next, assignment) {
|
|
7
|
+
for (const key in next) {
|
|
8
|
+
assignment(target, key, next[key]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
5
11
|
function CreateAssignment(target, createAssignment) {
|
|
6
12
|
let last;
|
|
7
13
|
let writeTo = {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttributeAssignment = AttributeAssignment;
|
|
3
4
|
exports.CreateAttributeAssignment = CreateAttributeAssignment;
|
|
5
|
+
function AttributeAssignment(target, attribute, next) {
|
|
6
|
+
target.setAttribute(attribute, next);
|
|
7
|
+
}
|
|
4
8
|
function CreateAttributeAssignment(target, attribute) {
|
|
5
9
|
let lastValue;
|
|
6
10
|
return function (next) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventAssignment = EventAssignment;
|
|
3
4
|
exports.CreateEventAssignment = CreateEventAssignment;
|
|
5
|
+
function EventAssignment(target, event, next) {
|
|
6
|
+
target.addEventListener(event, next);
|
|
7
|
+
}
|
|
4
8
|
function CreateEventAssignment(target, event) {
|
|
5
9
|
let lastEvent;
|
|
6
10
|
return function (next) {
|
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyAssignment = PropertyAssignment;
|
|
3
4
|
exports.CreateRootPropertyAssignment = CreateRootPropertyAssignment;
|
|
4
5
|
const json_1 = require("../Utils/json");
|
|
5
6
|
const createAssignment_1 = require("./createAssignment");
|
|
7
|
+
function PropertyAssignment(target, property, next) {
|
|
8
|
+
switch (property) {
|
|
9
|
+
case "nodeValue": {
|
|
10
|
+
AssignNodeValue(target, next);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case "className": {
|
|
14
|
+
AssignClassName(target, next);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case "value": {
|
|
18
|
+
AssignValue(target, next);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
const jsonType = (0, json_1.JsonType)(next);
|
|
23
|
+
switch (jsonType) {
|
|
24
|
+
case "value":
|
|
25
|
+
target[property] = next;
|
|
26
|
+
break;
|
|
27
|
+
default: {
|
|
28
|
+
const childTarget = target[property];
|
|
29
|
+
(0, createAssignment_1.Assignment)(childTarget, next, PropertyAssignment);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
6
35
|
function CreatePropertyAssignment(target, property) {
|
|
7
36
|
let lastValue;
|
|
8
37
|
let jsonType;
|
package/DOM/domNodeConfig.js
CHANGED
|
@@ -119,12 +119,21 @@ exports.DOMNodeConfig = {
|
|
|
119
119
|
setAttribute(target, attribute, value) {
|
|
120
120
|
target.setAttribute(attribute, value);
|
|
121
121
|
},
|
|
122
|
+
propertyAssignment(target, next) {
|
|
123
|
+
(0, createAssignment_1.Assignment)(target, next, createPropertyAssignment_1.PropertyAssignment);
|
|
124
|
+
},
|
|
122
125
|
createPropertyAssignment(target) {
|
|
123
126
|
return (0, createAssignment_1.CreateAssignment)(target, createPropertyAssignment_1.CreateRootPropertyAssignment);
|
|
124
127
|
},
|
|
128
|
+
eventAssignment(target, next) {
|
|
129
|
+
(0, createAssignment_1.Assignment)(target, next, createEventAssignment_1.EventAssignment);
|
|
130
|
+
},
|
|
125
131
|
createEventAssignment(target) {
|
|
126
132
|
return (0, createAssignment_1.CreateAssignment)(target, createEventAssignment_1.CreateEventAssignment);
|
|
127
133
|
},
|
|
134
|
+
attributeAssignment(target, next) {
|
|
135
|
+
(0, createAssignment_1.Assignment)(target, next, createAttributeAssignment_1.AttributeAssignment);
|
|
136
|
+
},
|
|
128
137
|
createAttributeAssignment(target) {
|
|
129
138
|
return (0, createAssignment_1.CreateAssignment)(target, createAttributeAssignment_1.CreateAttributeAssignment);
|
|
130
139
|
},
|
|
@@ -145,6 +154,13 @@ exports.DOMNodeConfig = {
|
|
|
145
154
|
target.replaceChildren(...children);
|
|
146
155
|
},
|
|
147
156
|
reconcileChildren(target, children) {
|
|
157
|
+
if (!target.hasChildNodes()) {
|
|
158
|
+
for (let x = 0; x < children.length; x++) {
|
|
159
|
+
const nextChild = getHTMLNode(children[x], null);
|
|
160
|
+
target.appendChild(nextChild);
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
148
164
|
let lastChild = null;
|
|
149
165
|
switch (children.length) {
|
|
150
166
|
case 0:
|
|
@@ -155,26 +171,30 @@ exports.DOMNodeConfig = {
|
|
|
155
171
|
if (target.firstChild !== lastChild)
|
|
156
172
|
target.insertBefore(lastChild, target.firstChild);
|
|
157
173
|
break;
|
|
158
|
-
default:
|
|
159
|
-
let
|
|
160
|
-
let
|
|
161
|
-
let x = 0;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
default: {
|
|
175
|
+
let currentChild = target.firstChild;
|
|
176
|
+
let inNextChildren = false;
|
|
177
|
+
for (let x = 0; x < children.length; x++) {
|
|
178
|
+
const nextChild = (lastChild = getHTMLNode(children[x], currentChild));
|
|
179
|
+
if (!currentChild)
|
|
180
|
+
target.appendChild(nextChild);
|
|
181
|
+
else if (nextChild !== currentChild) {
|
|
182
|
+
while (currentChild && (!(inNextChildren = inNextChildren || children.indexOf(currentChild, x + 1) >= 0))) {
|
|
183
|
+
const toRemove = currentChild;
|
|
184
|
+
currentChild = currentChild.nextSibling;
|
|
185
|
+
target.removeChild(toRemove);
|
|
186
|
+
}
|
|
187
|
+
nextChild !== currentChild &&
|
|
188
|
+
target.insertBefore(nextChild, currentChild);
|
|
168
189
|
}
|
|
169
|
-
if (actualChild)
|
|
170
|
-
actualChild = actualChild.nextSibling;
|
|
171
190
|
else
|
|
172
|
-
|
|
191
|
+
inNextChildren = false;
|
|
192
|
+
currentChild = nextChild.nextSibling;
|
|
173
193
|
}
|
|
174
|
-
lastChild = nextChild;
|
|
175
194
|
break;
|
|
195
|
+
}
|
|
176
196
|
}
|
|
177
197
|
while (target.lastChild !== lastChild)
|
|
178
198
|
target.removeChild(target.lastChild);
|
|
179
|
-
}
|
|
199
|
+
}
|
|
180
200
|
};
|
package/Node/component.js
CHANGED
package/Node/nodeConfig.d.ts
CHANGED
|
@@ -21,14 +21,17 @@ export interface INodeConfig {
|
|
|
21
21
|
removeChild(root: any, child: any): void;
|
|
22
22
|
remove(target: any): void;
|
|
23
23
|
fireEvent(target: any, event: string, data: any): void;
|
|
24
|
+
propertyAssignment(target: any, next: any): void;
|
|
24
25
|
createPropertyAssignment(target: any): {
|
|
25
26
|
(next: any): void;
|
|
26
27
|
};
|
|
28
|
+
eventAssignment(target: any, next: any): void;
|
|
27
29
|
createEventAssignment(target: any): {
|
|
28
30
|
(next: {
|
|
29
31
|
[event: string]: (event: Event) => void;
|
|
30
32
|
}): void;
|
|
31
33
|
};
|
|
34
|
+
attributeAssignment(target: any, next: any): void;
|
|
32
35
|
createAttributeAssignment(target: any): {
|
|
33
36
|
(next: {
|
|
34
37
|
[attribute: string]: string;
|
package/Node/vNode.js
CHANGED
|
@@ -61,10 +61,7 @@ var vNode;
|
|
|
61
61
|
vnode.component?.Destroy();
|
|
62
62
|
Store_1.ObservableScope.DestroyAll(vnode.scopes);
|
|
63
63
|
vnode.onDestroyed && emitter_1.Emitter.Emit(vnode.onDestroyed);
|
|
64
|
-
|
|
65
|
-
DestroyAll(vnode.children[x][1]);
|
|
66
|
-
Store_1.ObservableScope.Destroy(vnode.children[x][2]);
|
|
67
|
-
}
|
|
64
|
+
vnode.children && DestroyAll(vnode.children);
|
|
68
65
|
}
|
|
69
66
|
vNode.Destroy = Destroy;
|
|
70
67
|
function DestroyAll(vnodes) {
|
|
@@ -94,54 +91,54 @@ var vNode;
|
|
|
94
91
|
}
|
|
95
92
|
vNode.Attach = Attach;
|
|
96
93
|
})(vNode || (exports.vNode = vNode = {}));
|
|
94
|
+
function ComponentChildren() {
|
|
95
|
+
return this.Template();
|
|
96
|
+
}
|
|
97
97
|
function InitNode(vnode) {
|
|
98
98
|
const { type, namespace, props, attrs, on, data, componentFactory, children, childrenArray, } = vnode.definition;
|
|
99
99
|
const node = (vnode.node =
|
|
100
100
|
vnode.definition.node ?? nodeConfig_1.NodeConfig.createNode(type, namespace));
|
|
101
101
|
vnode.definition = null;
|
|
102
102
|
if (props) {
|
|
103
|
-
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
104
103
|
if (typeof props === "function") {
|
|
104
|
+
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
105
105
|
const scope = Store_1.ObservableScope.Create(props);
|
|
106
106
|
vnode.scopes.push(scope);
|
|
107
107
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
|
|
108
108
|
assignProperties(Store_1.ObservableScope.Value(scope));
|
|
109
109
|
}
|
|
110
110
|
else
|
|
111
|
-
|
|
111
|
+
nodeConfig_1.NodeConfig.propertyAssignment(node, props);
|
|
112
112
|
}
|
|
113
113
|
if (on) {
|
|
114
|
-
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
115
114
|
if (typeof on === "function") {
|
|
115
|
+
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
116
116
|
const scope = Store_1.ObservableScope.Create(on);
|
|
117
117
|
vnode.scopes.push(scope);
|
|
118
118
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
|
|
119
119
|
assignEvents(Store_1.ObservableScope.Value(scope));
|
|
120
120
|
}
|
|
121
121
|
else
|
|
122
|
-
|
|
122
|
+
nodeConfig_1.NodeConfig.eventAssignment(node, on);
|
|
123
123
|
}
|
|
124
124
|
if (attrs) {
|
|
125
|
-
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
126
125
|
if (typeof attrs === "function") {
|
|
126
|
+
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
127
127
|
const scope = Store_1.ObservableScope.Create(attrs);
|
|
128
128
|
vnode.scopes.push(scope);
|
|
129
129
|
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
|
|
130
130
|
assignAttributes(Store_1.ObservableScope.Value(scope));
|
|
131
131
|
}
|
|
132
132
|
else
|
|
133
|
-
|
|
133
|
+
nodeConfig_1.NodeConfig.attributeAssignment(node, attrs);
|
|
134
134
|
}
|
|
135
135
|
if (componentFactory) {
|
|
136
136
|
vnode.component = componentFactory(vnode);
|
|
137
137
|
vnode.component.Bound();
|
|
138
|
-
|
|
139
|
-
return vnode.component.Template();
|
|
140
|
-
}
|
|
141
|
-
Children(vnode, componentChildren, DefaultData);
|
|
138
|
+
Children(vnode, ComponentChildren.bind(vnode.component));
|
|
142
139
|
}
|
|
143
140
|
else if (childrenArray) {
|
|
144
|
-
vnode.children =
|
|
141
|
+
vnode.children = childrenArray;
|
|
145
142
|
vNode.InitAll(childrenArray);
|
|
146
143
|
}
|
|
147
144
|
else if (children) {
|
|
@@ -151,26 +148,22 @@ function InitNode(vnode) {
|
|
|
151
148
|
}
|
|
152
149
|
function Children(vnode, children, data) {
|
|
153
150
|
const childrenScope = CreateChildrenScope(vnode, children, data);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (startChildren !== newChildren) {
|
|
162
|
-
vnode.children = newChildren;
|
|
163
|
-
UpdateChildren(vnode);
|
|
164
|
-
}
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
151
|
+
vnode.scopes.push(childrenScope);
|
|
152
|
+
Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function (scope) {
|
|
153
|
+
if (vnode.destroyed)
|
|
154
|
+
return;
|
|
155
|
+
vnode.children = Store_1.ObservableScope.Value(scope);
|
|
156
|
+
UpdateChildren(vnode);
|
|
157
|
+
}));
|
|
167
158
|
vnode.children = Store_1.ObservableScope.Value(childrenScope);
|
|
168
159
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
160
|
+
function CreateChildrenScope(vnode, children, data) {
|
|
161
|
+
if (data === undefined) {
|
|
162
|
+
const scope = Store_1.ObservableScope.Create(GetNextNodesAsArray.bind(null, vnode.injector, children));
|
|
163
|
+
Store_1.ObservableScope.OnUpdated(scope, DestroyScopedVNodes);
|
|
164
|
+
Store_1.ObservableScope.OnDestroyed(scope, DestroyScopedVNodes);
|
|
165
|
+
return scope;
|
|
166
|
+
}
|
|
174
167
|
if ((0, functions_1.IsAsync)(data)) {
|
|
175
168
|
const asyncData = data;
|
|
176
169
|
data = function () {
|
|
@@ -179,35 +172,27 @@ function CreateChildrenScope(vnode, children, data = DefaultData) {
|
|
|
179
172
|
});
|
|
180
173
|
};
|
|
181
174
|
}
|
|
182
|
-
return Store_1.ObservableScope.Create(
|
|
175
|
+
return Store_1.ObservableScope.Create(DynamicChildrenFunction.bind(null, vnode.injector, children, data));
|
|
183
176
|
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
nodeArray = EvaluateNextNodesSmall(injector, children, nextData, nodeArray);
|
|
204
|
-
else
|
|
205
|
-
nodeArray = EvaluateNextNodesLarge(injector, children, nextData, nodeArray);
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return nodeArray;
|
|
210
|
-
};
|
|
177
|
+
function GetNextNodes(injector, children, data) {
|
|
178
|
+
return ToVNodeType(injector_1.Injector.Scope(injector, children, data));
|
|
179
|
+
}
|
|
180
|
+
function GetNextNodesAsArray(injector, children, data) {
|
|
181
|
+
const nodes = GetNextNodes(injector, children, data);
|
|
182
|
+
return ToArray(nodes);
|
|
183
|
+
}
|
|
184
|
+
function DestroyScopedVNodes(value) {
|
|
185
|
+
Array.isArray(value) ? vNode.DestroyAll(value) : vNode.Destroy(value);
|
|
186
|
+
}
|
|
187
|
+
function DynamicChildrenFunction(injector, children, data) {
|
|
188
|
+
const nextData = ToArray(data());
|
|
189
|
+
const getNextNodes = GetNextNodes.bind(null, injector, children);
|
|
190
|
+
let results = new Array(nextData.length);
|
|
191
|
+
for (let x = 0; x < nextData.length; x++) {
|
|
192
|
+
const nodes = (0, observableScope_1.MappedScope)(nextData[x], getNextNodes, DestroyScopedVNodes, DestroyScopedVNodes);
|
|
193
|
+
results[x] = nodes;
|
|
194
|
+
}
|
|
195
|
+
return results.flat();
|
|
211
196
|
}
|
|
212
197
|
function ToArray(result) {
|
|
213
198
|
if (!result)
|
|
@@ -216,124 +201,40 @@ function ToArray(result) {
|
|
|
216
201
|
return result;
|
|
217
202
|
return [result];
|
|
218
203
|
}
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
data === undefined
|
|
222
|
-
? null
|
|
223
|
-
: Store_1.ObservableScope.Create(function () {
|
|
224
|
-
const children = injector_1.Injector.Scope(injector, getNextChildren, data);
|
|
225
|
-
return CreateNodeArray(children);
|
|
226
|
-
});
|
|
227
|
-
const children = scope === null
|
|
228
|
-
? CreateNodeArray(injector_1.Injector.Scope(injector, getNextChildren, undefined))
|
|
229
|
-
: Store_1.ObservableScope.Value(scope);
|
|
230
|
-
return [data, children, scope];
|
|
231
|
-
}
|
|
232
|
-
function InitializeNextNodes(injector, getNextChildren, nextData) {
|
|
233
|
-
const nextNodes = new Array(nextData.length);
|
|
234
|
-
for (let x = 0; x < nextData.length; x++) {
|
|
235
|
-
const data = nextData[x];
|
|
236
|
-
nextNodes[x] = GetNextNodeRow(data, injector, getNextChildren);
|
|
237
|
-
}
|
|
238
|
-
return nextNodes;
|
|
239
|
-
}
|
|
240
|
-
function GetNextNodeRowSmall(injector, getNextChildren, nodeArray, data) {
|
|
241
|
-
let i = 0;
|
|
242
|
-
for (; i < nodeArray.length && (nodeArray[i] === null || nodeArray[i][0] !== data); i++) { }
|
|
243
|
-
if (i === nodeArray.length)
|
|
244
|
-
return GetNextNodeRow(data, injector, getNextChildren);
|
|
245
|
-
const nextNodeRow = GetNextNodeRow(data, injector, getNextChildren, nodeArray[i][2]);
|
|
246
|
-
if (nodeArray[i][1] !== nextNodeRow[1])
|
|
247
|
-
vNode.DestroyAll(nodeArray[i][1]);
|
|
248
|
-
nodeArray[i] = null;
|
|
249
|
-
return nextNodeRow;
|
|
250
|
-
}
|
|
251
|
-
function EvaluateNextNodesSmall(injector, getNextChildren, nextData, nodeArray) {
|
|
252
|
-
const nextNodes = new Array(nextData.length);
|
|
253
|
-
for (let x = 0; x < nextData.length; x++)
|
|
254
|
-
nextNodes[x] = GetNextNodeRowSmall(injector, getNextChildren, nodeArray, nextData[x]);
|
|
255
|
-
return nextNodes;
|
|
256
|
-
}
|
|
257
|
-
function GetNextNodeRowLarge(injector, getNextChildren, nodeRowMap, data) {
|
|
258
|
-
const currentChildren = nodeRowMap.get(data);
|
|
259
|
-
let currentChildIndex = currentChildren ? currentChildren.length - 1 : -1;
|
|
260
|
-
for (; currentChildIndex >= 0 && currentChildren[currentChildIndex] === null; currentChildIndex--) { }
|
|
261
|
-
if (currentChildIndex >= 0) {
|
|
262
|
-
const nodeRow = currentChildren[currentChildIndex];
|
|
263
|
-
if (currentChildIndex === 0)
|
|
264
|
-
nodeRowMap.delete(data);
|
|
265
|
-
else
|
|
266
|
-
currentChildren[currentChildIndex] = null;
|
|
267
|
-
const nextNodeRow = GetNextNodeRow(data, injector, getNextChildren, nodeRow[2]);
|
|
268
|
-
if (nodeRow[1] !== nextNodeRow[1])
|
|
269
|
-
vNode.DestroyAll(nodeRow[1]);
|
|
270
|
-
return nextNodeRow;
|
|
271
|
-
}
|
|
272
|
-
return GetNextNodeRow(data, injector, getNextChildren);
|
|
273
|
-
}
|
|
274
|
-
function EvaluateNextNodesLarge(injector, getNextChildren, nextData, nodeArray) {
|
|
275
|
-
const nextNodes = new Array(nextData.length);
|
|
276
|
-
const dataMap = new Map();
|
|
277
|
-
for (let x = 0; x < nodeArray.length; x++) {
|
|
278
|
-
const arr = dataMap.get(nodeArray[x][0]) ?? [];
|
|
279
|
-
arr.push(nodeArray[x]);
|
|
280
|
-
dataMap.set(nodeArray[x][0], arr);
|
|
281
|
-
}
|
|
282
|
-
for (let x = 0; x < nextData.length; x++) {
|
|
283
|
-
nextNodes[x] = GetNextNodeRowLarge(injector, getNextChildren, dataMap, nextData[x]);
|
|
284
|
-
}
|
|
285
|
-
for (const value of dataMap.values()) {
|
|
286
|
-
for (let x = 0; x < value.length; x++) {
|
|
287
|
-
const row = value[x];
|
|
288
|
-
row && vNode.DestroyAll(row[1]);
|
|
289
|
-
row && Store_1.ObservableScope.Destroy(row[2]);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return nextNodes;
|
|
204
|
+
function ToVNodeType(children) {
|
|
205
|
+
return typeof children === "string" ? { type: "string", node: children } : children;
|
|
293
206
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
return typeof children === "string"
|
|
297
|
-
? [{ type: "string", node: children }]
|
|
298
|
-
: [children];
|
|
299
|
-
}
|
|
300
|
-
return children;
|
|
207
|
+
function GetNode(vnode) {
|
|
208
|
+
return vnode.node;
|
|
301
209
|
}
|
|
302
210
|
function UpdateChildren(vnode, init = false, skipInit = false) {
|
|
303
211
|
if (!vnode.children)
|
|
304
212
|
return;
|
|
305
|
-
if (vnode.children.length === 1 &&
|
|
306
|
-
vnode.children[0][1].length === 1 &&
|
|
307
|
-
vnode.children[0][1][0].node) {
|
|
308
|
-
nodeConfig_1.NodeConfig.reconcileChildren(vnode.node, vnode.children.flatMap((row) => row[1].map((vnode) => vnode.node)));
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
213
|
const children = vnode.children;
|
|
312
214
|
(0, thread_1.Thread)(function () {
|
|
313
215
|
if (vnode.destroyed || children !== vnode.children)
|
|
314
216
|
return;
|
|
315
|
-
for (let x = 0; !skipInit && x < children.length; x++)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
}
|
|
217
|
+
for (let x = 0; !skipInit && x < children.length; x++) {
|
|
218
|
+
const childNode = children[x];
|
|
219
|
+
if (!(0, vNode_types_1.isStringNode)(childNode) && childNode.definition) {
|
|
220
|
+
(0, thread_1.Schedule)(function () {
|
|
221
|
+
if (vnode.destroyed || children !== vnode.children)
|
|
222
|
+
return;
|
|
223
|
+
vNode.Init(childNode);
|
|
224
|
+
});
|
|
325
225
|
}
|
|
226
|
+
}
|
|
326
227
|
(0, thread_1.Thread)(function (async) {
|
|
327
228
|
if (vnode.destroyed || children !== vnode.children)
|
|
328
229
|
return;
|
|
329
230
|
if (init || !async) {
|
|
330
|
-
nodeConfig_1.NodeConfig.reconcileChildren(vnode.node, vnode.children.
|
|
231
|
+
nodeConfig_1.NodeConfig.reconcileChildren(vnode.node, vnode.children.map(GetNode));
|
|
331
232
|
}
|
|
332
233
|
else
|
|
333
234
|
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
334
235
|
if (vnode.destroyed || children !== vnode.children)
|
|
335
236
|
return;
|
|
336
|
-
nodeConfig_1.NodeConfig.reconcileChildren(vnode.node, vnode.children.
|
|
237
|
+
nodeConfig_1.NodeConfig.reconcileChildren(vnode.node, vnode.children.map(GetNode));
|
|
337
238
|
});
|
|
338
239
|
});
|
|
339
240
|
});
|
package/Node/vNode.types.d.ts
CHANGED
|
@@ -23,11 +23,7 @@ export type vElementNode = {
|
|
|
23
23
|
definition: vNodeDefinition<any, any, any>;
|
|
24
24
|
injector: Injector;
|
|
25
25
|
node: Node | null;
|
|
26
|
-
children:
|
|
27
|
-
any,
|
|
28
|
-
vNode[],
|
|
29
|
-
IObservableScope<string | vNode | vNode[]> | null
|
|
30
|
-
])[] | null;
|
|
26
|
+
children: vNode[];
|
|
31
27
|
destroyed: boolean;
|
|
32
28
|
onDestroyed: Emitter | null;
|
|
33
29
|
scopes: IObservableScope<unknown>[];
|
package/Store/Store/store.js
CHANGED
|
@@ -26,7 +26,7 @@ class Store {
|
|
|
26
26
|
const rootObject = this.rootMap.get(key);
|
|
27
27
|
if (rootObject === undefined)
|
|
28
28
|
throw `No root object found for key: ${key}`;
|
|
29
|
-
const rootValue = rootObject[
|
|
29
|
+
const rootValue = observableNode_1.ObservableNode.Unwrap(rootObject); // rootObject[GET_OBSERVABLE_VALUE];
|
|
30
30
|
const alias = rootValue[key];
|
|
31
31
|
return alias;
|
|
32
32
|
});
|
|
@@ -118,7 +118,7 @@ class StoreAsync extends store_1.Store {
|
|
|
118
118
|
async Splice(key, start, deleteCount, ...items) {
|
|
119
119
|
return await this.queue.Next(async () => {
|
|
120
120
|
const arr = this.Get(key);
|
|
121
|
-
const arrValue = arr[
|
|
121
|
+
const arrValue = observableNode_1.ObservableNode.Unwrap(arr); // (arr as any)[GET_OBSERVABLE_VALUE] as any[];
|
|
122
122
|
const arrCopy = arrValue.slice();
|
|
123
123
|
const spliceResult = (0, json_1.JsonDeepClone)(arrCopy.splice(start, deleteCount, ...items));
|
|
124
124
|
const diffResult = await this.diff.DiffPath(key, arrCopy);
|
package/Store/Store/storeSync.js
CHANGED
|
@@ -49,7 +49,7 @@ class StoreSync extends store_1.Store {
|
|
|
49
49
|
* @throws Will throw an error if no key is provided for the data.
|
|
50
50
|
*/
|
|
51
51
|
Write(data, key) {
|
|
52
|
-
data =
|
|
52
|
+
// data = JsonDeepClone(data);
|
|
53
53
|
key = key || this.keyFunc?.(data);
|
|
54
54
|
if (!key)
|
|
55
55
|
throw "No key provided for data";
|
|
@@ -66,7 +66,7 @@ class StoreSync extends store_1.Store {
|
|
|
66
66
|
const value = this.Get(key);
|
|
67
67
|
if (value === undefined)
|
|
68
68
|
throw "Unable to patch undefined value";
|
|
69
|
-
const json =
|
|
69
|
+
const json = observableNode_1.ObservableNode.Unwrap(value);
|
|
70
70
|
const mergedJson = (0, json_1.JsonMerge)(json, patch);
|
|
71
71
|
const diffResult = this.diff.DiffPath(key, mergedJson);
|
|
72
72
|
this.UpdateRootMap(diffResult);
|
|
@@ -98,7 +98,7 @@ class StoreSync extends store_1.Store {
|
|
|
98
98
|
*/
|
|
99
99
|
Splice(key, start, deleteCount, ...items) {
|
|
100
100
|
const arr = this.Get(key);
|
|
101
|
-
const arrValue = arr[
|
|
101
|
+
const arrValue = observableNode_1.ObservableNode.Unwrap(arr); // (arr as any)[GET_OBSERVABLE_VALUE] as any[];
|
|
102
102
|
const arrCopy = arrValue.slice();
|
|
103
103
|
const spliceResult = (0, json_1.JsonDeepClone)(arrCopy.splice(start, deleteCount, ...items));
|
|
104
104
|
const diffResult = this.diff.DiffPath(key, arrCopy);
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
import { JsonDiffResult } from "../../Utils/json";
|
|
2
|
-
/**
|
|
3
|
-
* Symbol to identify observable nodes.
|
|
4
|
-
* Used to check if a value is an observable node proxy.
|
|
5
|
-
*/
|
|
6
|
-
export declare const IS_OBSERVABLE_NODE: unique symbol;
|
|
7
|
-
/**
|
|
8
|
-
* Symbol to get the raw underlying value from an observable node.
|
|
9
|
-
* Returns the unwrapped, non-proxied value.
|
|
10
|
-
*/
|
|
11
|
-
export declare const GET_OBSERVABLE_VALUE: unique symbol;
|
|
12
|
-
/**
|
|
13
|
-
* Symbol for the toJSON method on observable nodes.
|
|
14
|
-
* Used to serialize observable nodes to plain JSON.
|
|
15
|
-
*/
|
|
16
|
-
export declare const GET_TO_JSON: unique symbol;
|
|
17
2
|
export declare namespace ObservableNode {
|
|
18
3
|
/**
|
|
19
4
|
* Unwraps an observable node to get the raw underlying value.
|
|
@@ -38,6 +23,7 @@ export declare namespace ObservableNode {
|
|
|
38
23
|
* @param prop Optional property name or index to touch a specific nested property.
|
|
39
24
|
*/
|
|
40
25
|
function Touch(value: unknown, prop?: string | number): void;
|
|
26
|
+
function Apply(rootNode: any, update: any): void;
|
|
41
27
|
/**
|
|
42
28
|
* Applies a JSON diff result to an observable node, efficiently updating only changed properties.
|
|
43
29
|
* Optimizes nested object updates by computing paths incrementally and touching modified properties.
|