j-templates 7.0.12 → 7.0.14
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/component.d.ts +1 -0
- package/Node/component.js +13 -0
- package/Node/vNode.js +4 -3
- package/Store/Tree/observableScope.js +1 -3
- package/package.json +1 -1
package/Node/component.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ type ComponentConstructor<D, T, E> = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare namespace Component {
|
|
31
31
|
function ToFunction<D, T, E, P = HTMLElement>(type: string, constructor: ComponentConstructor<D, T, E>, namespace?: string): (config: vComponentConfig<D, E, P>, templates?: T) => vNodeType;
|
|
32
|
+
function Register<D = void, T = void, E = void>(name: string, constructor: ComponentConstructor<D, T, E>): void;
|
|
32
33
|
function Attach(node: any, vnode: vNodeType): vNodeType;
|
|
33
34
|
}
|
|
34
35
|
export {};
|
package/Node/component.js
CHANGED
|
@@ -65,6 +65,19 @@ exports.Component = Component;
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
Component.ToFunction = ToFunction;
|
|
68
|
+
function Register(name, constructor) {
|
|
69
|
+
const componentFunction = ToFunction(`${name}-component`, constructor);
|
|
70
|
+
class WebComponent extends HTMLElement {
|
|
71
|
+
constructor() {
|
|
72
|
+
super();
|
|
73
|
+
const shadowRoot = this.attachShadow({ mode: "open" });
|
|
74
|
+
const node = componentFunction({});
|
|
75
|
+
Attach(shadowRoot, node);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
customElements.define(name, WebComponent);
|
|
79
|
+
}
|
|
80
|
+
Component.Register = Register;
|
|
68
81
|
function Attach(node, vnode) {
|
|
69
82
|
return vNode_1.vNode.Attach(node, vnode);
|
|
70
83
|
}
|
package/Node/vNode.js
CHANGED
|
@@ -129,6 +129,7 @@ function InitNode(vnode) {
|
|
|
129
129
|
}
|
|
130
130
|
else if (childrenArray) {
|
|
131
131
|
vnode.children = childrenArray;
|
|
132
|
+
vNode.InitAll(vnode.children);
|
|
132
133
|
}
|
|
133
134
|
else if (children) {
|
|
134
135
|
if (data) {
|
|
@@ -137,7 +138,7 @@ function InitNode(vnode) {
|
|
|
137
138
|
else
|
|
138
139
|
StaticChildren(vnode, children);
|
|
139
140
|
}
|
|
140
|
-
UpdateChildren(vnode, true);
|
|
141
|
+
UpdateChildren(vnode, true, !!childrenArray);
|
|
141
142
|
}
|
|
142
143
|
function StaticChildren(vnode, children) {
|
|
143
144
|
const childrenScope = Store_1.ObservableScope.Create(WrapStaticChildren(vnode.injector, children));
|
|
@@ -256,14 +257,14 @@ function WrapDynamicChildren(dataScope, nodeList, injector, children) {
|
|
|
256
257
|
return nextNodeArray;
|
|
257
258
|
};
|
|
258
259
|
}
|
|
259
|
-
function UpdateChildren(vnode, init = false) {
|
|
260
|
+
function UpdateChildren(vnode, init = false, skipInit = false) {
|
|
260
261
|
if (!vnode.children)
|
|
261
262
|
return;
|
|
262
263
|
const children = vnode.children;
|
|
263
264
|
(0, thread_1.Thread)(function () {
|
|
264
265
|
if (vnode.destroyed || children !== vnode.children)
|
|
265
266
|
return;
|
|
266
|
-
for (let x = 0; x < children.length; x++)
|
|
267
|
+
for (let x = 0; !skipInit && x < children.length; x++)
|
|
267
268
|
if (children[x].node === null) {
|
|
268
269
|
const childNode = children[x];
|
|
269
270
|
(0, thread_1.Schedule)(function () {
|
|
@@ -166,9 +166,6 @@ function DirtyScope(scope) {
|
|
|
166
166
|
return;
|
|
167
167
|
if (scope.async) {
|
|
168
168
|
UpdateValue(scope);
|
|
169
|
-
scope.promise.then(function () {
|
|
170
|
-
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
171
|
-
});
|
|
172
169
|
}
|
|
173
170
|
else
|
|
174
171
|
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
@@ -199,6 +196,7 @@ function UpdateValue(scope) {
|
|
|
199
196
|
if (scope.async) {
|
|
200
197
|
scope.promise = value.then(function (result) {
|
|
201
198
|
scope.value = result;
|
|
199
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
202
200
|
return result;
|
|
203
201
|
});
|
|
204
202
|
}
|