j-templates 7.0.0 → 7.0.3
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/createEventAssignment.d.ts +3 -0
- package/DOM/createEventAssignment.js +6 -0
- package/DOM/domNodeConfig.js +3 -2
- package/Node/nodeConfig.d.ts +1 -0
- package/Node/vNode.js +30 -34
- package/Node/vNode.types.d.ts +0 -7
- package/Store/Tree/observableScope.js +14 -9
- package/Utils/animation.js +4 -4
- package/Utils/list.js +4 -37
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateEventAssignment = CreateEventAssignment;
|
|
4
|
+
exports.AssignEvents = AssignEvents;
|
|
4
5
|
function CreateEventAssignment(target, event) {
|
|
5
6
|
let lastEvent;
|
|
6
7
|
return function (next) {
|
|
@@ -12,3 +13,8 @@ function CreateEventAssignment(target, event) {
|
|
|
12
13
|
lastEvent = nextEvent;
|
|
13
14
|
};
|
|
14
15
|
}
|
|
16
|
+
function AssignEvents(target, eventMap) {
|
|
17
|
+
const entries = Object.entries(eventMap);
|
|
18
|
+
for (let x = 0; x < entries.length; x++)
|
|
19
|
+
target.addEventListener(entries[x][0], entries[x][1]);
|
|
20
|
+
}
|
package/DOM/domNodeConfig.js
CHANGED
|
@@ -119,6 +119,9 @@ exports.DOMNodeConfig = {
|
|
|
119
119
|
createEventAssignment(target) {
|
|
120
120
|
return (0, createAssignment_1.CreateAssignment)(target, createEventAssignment_1.CreateEventAssignment);
|
|
121
121
|
},
|
|
122
|
+
assignEvents(target, next) {
|
|
123
|
+
(0, createEventAssignment_1.AssignEvents)(target, next);
|
|
124
|
+
},
|
|
122
125
|
createAttributeAssignment(target) {
|
|
123
126
|
return (0, createAssignment_1.CreateAssignment)(target, createAttributeAssignment_1.CreateAttributeAssignment);
|
|
124
127
|
},
|
|
@@ -139,8 +142,6 @@ exports.DOMNodeConfig = {
|
|
|
139
142
|
target.replaceChildren(...children);
|
|
140
143
|
},
|
|
141
144
|
reconcileChildren(target, children) {
|
|
142
|
-
if (children.length === 0 && !target.firstChild)
|
|
143
|
-
return;
|
|
144
145
|
if (children.length === 0 || !target.firstChild) {
|
|
145
146
|
target.replaceChildren(...children);
|
|
146
147
|
return;
|
package/Node/nodeConfig.d.ts
CHANGED
package/Node/vNode.js
CHANGED
|
@@ -15,16 +15,13 @@ var vNode;
|
|
|
15
15
|
node: null,
|
|
16
16
|
children: null,
|
|
17
17
|
destroyed: false,
|
|
18
|
-
assignProperties: null,
|
|
19
|
-
assignEvents: null,
|
|
20
|
-
assignAttributes: null,
|
|
21
18
|
component: null,
|
|
22
19
|
scopes: []
|
|
23
20
|
};
|
|
24
21
|
}
|
|
25
22
|
vNode.Create = Create;
|
|
26
23
|
function Init(vnode) {
|
|
27
|
-
if (vnode.
|
|
24
|
+
if (vnode.definition === null)
|
|
28
25
|
return;
|
|
29
26
|
InitNode(vnode);
|
|
30
27
|
}
|
|
@@ -38,7 +35,6 @@ var vNode;
|
|
|
38
35
|
if (vnode.destroyed)
|
|
39
36
|
return;
|
|
40
37
|
vnode.destroyed = true;
|
|
41
|
-
vnode.assignEvents?.(null);
|
|
42
38
|
vnode.component?.Destroy();
|
|
43
39
|
Store_1.ObservableScope.DestroyAll(vnode.scopes);
|
|
44
40
|
vnode.children && DestroyAll(vnode.children);
|
|
@@ -69,56 +65,43 @@ var vNode;
|
|
|
69
65
|
})(vNode || (exports.vNode = vNode = {}));
|
|
70
66
|
function InitNode(vnode) {
|
|
71
67
|
const { type, namespace, props, attrs, on, data, componentConstructor, children, childrenArray } = vnode.definition;
|
|
72
|
-
const node = nodeConfig_1.NodeConfig.createNode(type, namespace);
|
|
73
|
-
vnode.
|
|
68
|
+
const node = vnode.node = nodeConfig_1.NodeConfig.createNode(type, namespace);
|
|
69
|
+
vnode.definition = null;
|
|
74
70
|
if (props) {
|
|
75
|
-
|
|
71
|
+
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
76
72
|
if (typeof props === 'function') {
|
|
77
73
|
const scope = Store_1.ObservableScope.Create(props);
|
|
78
74
|
vnode.scopes.push(scope);
|
|
79
|
-
Store_1.ObservableScope.Watch(scope,
|
|
80
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
81
|
-
vnode.assignProperties(value);
|
|
82
|
-
}));
|
|
75
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
|
|
83
76
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
vnode.assignProperties(props);
|
|
88
|
-
vnode.assignProperties = null;
|
|
77
|
+
assignProperties(value);
|
|
89
78
|
}
|
|
79
|
+
else
|
|
80
|
+
assignProperties(props);
|
|
90
81
|
}
|
|
91
82
|
if (on) {
|
|
92
|
-
|
|
83
|
+
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
93
84
|
if (typeof on === 'function') {
|
|
94
85
|
const scope = Store_1.ObservableScope.Create(on);
|
|
95
86
|
vnode.scopes.push(scope);
|
|
96
|
-
Store_1.ObservableScope.Watch(scope,
|
|
97
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
98
|
-
vnode.assignEvents(value);
|
|
99
|
-
}));
|
|
87
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
|
|
100
88
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
101
|
-
|
|
89
|
+
assignEvents(value);
|
|
102
90
|
}
|
|
103
91
|
else
|
|
104
|
-
|
|
92
|
+
assignEvents(on);
|
|
105
93
|
}
|
|
106
94
|
if (attrs) {
|
|
107
|
-
|
|
95
|
+
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
108
96
|
if (typeof attrs === 'function') {
|
|
109
97
|
const scope = Store_1.ObservableScope.Create(attrs);
|
|
110
98
|
vnode.scopes.push(scope);
|
|
111
|
-
Store_1.ObservableScope.Watch(scope,
|
|
112
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
113
|
-
vnode.assignAttributes(value);
|
|
114
|
-
}));
|
|
99
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
|
|
115
100
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
vnode.assignAttributes(attrs);
|
|
120
|
-
vnode.assignAttributes = null;
|
|
101
|
+
assignAttributes(value);
|
|
121
102
|
}
|
|
103
|
+
else
|
|
104
|
+
assignAttributes(attrs);
|
|
122
105
|
}
|
|
123
106
|
if (componentConstructor) {
|
|
124
107
|
vnode.component = new componentConstructor(vnode);
|
|
@@ -286,6 +269,19 @@ function ToArray(callback) {
|
|
|
286
269
|
return [result];
|
|
287
270
|
};
|
|
288
271
|
}
|
|
272
|
+
function ScheduledAssignment(assign) {
|
|
273
|
+
let scheduled = false;
|
|
274
|
+
return function (scope) {
|
|
275
|
+
if (scheduled)
|
|
276
|
+
return;
|
|
277
|
+
scheduled = true;
|
|
278
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
279
|
+
scheduled = false;
|
|
280
|
+
const value = Store_1.ObservableScope.Peek(scope);
|
|
281
|
+
assign(value);
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
}
|
|
289
285
|
function CreateScheduledCallback(callback) {
|
|
290
286
|
let scheduled = false;
|
|
291
287
|
return function () {
|
package/Node/vNode.types.d.ts
CHANGED
|
@@ -18,13 +18,6 @@ export type vNode = {
|
|
|
18
18
|
node: Node | null;
|
|
19
19
|
children: vNode[] | null;
|
|
20
20
|
destroyed: boolean;
|
|
21
|
-
assignProperties: (next: any) => void;
|
|
22
|
-
assignEvents: (next: {
|
|
23
|
-
[event: string]: (event: Event) => void;
|
|
24
|
-
}) => void;
|
|
25
|
-
assignAttributes: (next: {
|
|
26
|
-
[attr: string]: string;
|
|
27
|
-
}) => void;
|
|
28
21
|
scopes: IObservableScope<unknown>[];
|
|
29
22
|
component: Component;
|
|
30
23
|
};
|
|
@@ -77,8 +77,8 @@ function CalcScope(callback) {
|
|
|
77
77
|
async: valueFunction[Symbol.toStringTag] === "AsyncFunction",
|
|
78
78
|
dirty: true,
|
|
79
79
|
emitter: emitter_1.Emitter.Create(),
|
|
80
|
-
emitters:
|
|
81
|
-
calcFunctions:
|
|
80
|
+
emitters: null,
|
|
81
|
+
calcFunctions: null,
|
|
82
82
|
onDestroyed: null,
|
|
83
83
|
destroyed: false,
|
|
84
84
|
setCallback: function () {
|
|
@@ -153,16 +153,15 @@ function CalcScope(callback) {
|
|
|
153
153
|
}
|
|
154
154
|
ObservableScope.DestroyAll = DestroyAll;
|
|
155
155
|
})(ObservableScope || (exports.ObservableScope = ObservableScope = {}));
|
|
156
|
-
function CalcChanged(calc) {
|
|
157
|
-
const value = calc.getFunction();
|
|
158
|
-
const changed = calc.value !== value;
|
|
159
|
-
calc.value = value;
|
|
160
|
-
return changed;
|
|
161
|
-
}
|
|
162
156
|
function DirtyScope(scope) {
|
|
163
157
|
if (scope.dirty || !scope.getFunction)
|
|
164
158
|
return;
|
|
165
|
-
|
|
159
|
+
let dirty = scope.calcFunctions.length === 0;
|
|
160
|
+
for (let x = 0; !dirty && x < scope.calcFunctions.length; x++) {
|
|
161
|
+
const calc = scope.calcFunctions[x];
|
|
162
|
+
dirty = dirty || calc.value !== calc.getFunction();
|
|
163
|
+
}
|
|
164
|
+
scope.dirty = dirty;
|
|
166
165
|
if (!scope.dirty)
|
|
167
166
|
return;
|
|
168
167
|
if (scope.async) {
|
|
@@ -209,6 +208,12 @@ function UpdateValue(scope) {
|
|
|
209
208
|
UpdateEmitters(scope, emitters);
|
|
210
209
|
}
|
|
211
210
|
function UpdateEmitters(scope, right) {
|
|
211
|
+
if (scope.emitters === null) {
|
|
212
|
+
for (let x = 0; x < right.length; x++)
|
|
213
|
+
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
214
|
+
scope.emitters = right;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
212
217
|
if (right.length === 0) {
|
|
213
218
|
if (scope.emitters.length > 0) {
|
|
214
219
|
for (let x = 0; x < scope.emitters.length; x++)
|
package/Utils/animation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Animation = exports.AnimationType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const nodeConfig_1 = require("../Node/nodeConfig");
|
|
5
5
|
var StepFunctions;
|
|
6
6
|
(function (StepFunctions) {
|
|
7
7
|
function EaseIn(start, duration) {
|
|
@@ -47,7 +47,7 @@ class Animation {
|
|
|
47
47
|
this.enabled = true;
|
|
48
48
|
this.type = type;
|
|
49
49
|
this.animationDuration = duration;
|
|
50
|
-
this.animationUpdate =
|
|
50
|
+
this.animationUpdate = nodeConfig_1.NodeConfig.wrapPriorityUpdates(update);
|
|
51
51
|
}
|
|
52
52
|
Animate(start, end) {
|
|
53
53
|
if (!this.enabled)
|
|
@@ -70,13 +70,13 @@ class Animation {
|
|
|
70
70
|
const next = this.start + step;
|
|
71
71
|
this.animationUpdate(next);
|
|
72
72
|
if (percent < 1)
|
|
73
|
-
|
|
73
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(this.animationRun);
|
|
74
74
|
else {
|
|
75
75
|
resolve();
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
this.animationRun = animationRun;
|
|
79
|
-
|
|
79
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(this.animationRun);
|
|
80
80
|
}).then(() => {
|
|
81
81
|
this.Cancel();
|
|
82
82
|
});
|
package/Utils/list.js
CHANGED
|
@@ -3,35 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.List = void 0;
|
|
4
4
|
var List;
|
|
5
5
|
(function (List) {
|
|
6
|
-
let maxTempListSize = 0;
|
|
7
|
-
let trimScheduled = false;
|
|
8
|
-
const tempList = Create();
|
|
9
6
|
function CreateNode(data) {
|
|
10
|
-
|
|
11
|
-
node.data = data;
|
|
12
|
-
return node;
|
|
13
|
-
}
|
|
14
|
-
function TrimTempList() {
|
|
15
|
-
trimScheduled = false;
|
|
16
|
-
if (maxTempListSize < tempList.size)
|
|
17
|
-
maxTempListSize = tempList.size;
|
|
18
|
-
const trimSize = Math.floor(maxTempListSize / 10);
|
|
19
|
-
Split(tempList, trimSize);
|
|
20
|
-
}
|
|
21
|
-
function ScheduleTrimTempList() {
|
|
22
|
-
if (!trimScheduled && tempList.size > maxTempListSize) {
|
|
23
|
-
trimScheduled = true;
|
|
24
|
-
requestIdleCallback(TrimTempList);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function ReturnNode(node) {
|
|
28
|
-
if (!node)
|
|
29
|
-
return;
|
|
30
|
-
node.previous = null;
|
|
31
|
-
node.next = null;
|
|
32
|
-
node.data = null;
|
|
33
|
-
AddNode(tempList, node);
|
|
34
|
-
ScheduleTrimTempList();
|
|
7
|
+
return { previous: null, next: null, data };
|
|
35
8
|
}
|
|
36
9
|
function Create() {
|
|
37
10
|
return {
|
|
@@ -65,13 +38,9 @@ var List;
|
|
|
65
38
|
}
|
|
66
39
|
List.Split = Split;
|
|
67
40
|
function Clear(list) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
node = node.next;
|
|
72
|
-
}
|
|
73
|
-
Append(tempList, list);
|
|
74
|
-
ScheduleTrimTempList();
|
|
41
|
+
list.head = null;
|
|
42
|
+
list.tail = null;
|
|
43
|
+
list.size = 0;
|
|
75
44
|
}
|
|
76
45
|
List.Clear = Clear;
|
|
77
46
|
function Push(list, data) {
|
|
@@ -108,7 +77,6 @@ var List;
|
|
|
108
77
|
function Pop(list) {
|
|
109
78
|
const node = PopNode(list);
|
|
110
79
|
const data = node?.data;
|
|
111
|
-
ReturnNode(node);
|
|
112
80
|
return data;
|
|
113
81
|
}
|
|
114
82
|
List.Pop = Pop;
|
|
@@ -177,7 +145,6 @@ var List;
|
|
|
177
145
|
if (list.size === 0)
|
|
178
146
|
list.head = null;
|
|
179
147
|
const data = node.data;
|
|
180
|
-
ReturnNode(node);
|
|
181
148
|
return data;
|
|
182
149
|
}
|
|
183
150
|
List.Remove = Remove;
|