j-templates 7.0.8 → 7.0.10

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/elements.d.ts CHANGED
@@ -78,3 +78,4 @@ export declare const td: <T>(config: {
78
78
  on?: import("../Node/vNode.types").FunctionOr<import("../Node/vNode.types").vNodeEvents<HTMLElementEventMap>>;
79
79
  data?: () => T | Array<T> | Promise<Array<T>> | Promise<T>;
80
80
  }, children?: import("../Node/vNode.types").vNode[] | import("../Node/vNode.types").vNodeChildrenFunction<T>) => import("../Node/vNode.types").vNode;
81
+ export declare const text: (callback: () => string) => import("../Node/vNode.types").vNode;
package/DOM/elements.js CHANGED
@@ -1,14 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.td = exports.tr = exports.tbody = exports.table = exports.span = exports.input = exports.h1 = exports.button = exports.a = exports.div = void 0;
3
+ exports.text = exports.td = exports.tr = exports.tbody = exports.table = exports.span = exports.input = exports.h1 = exports.button = exports.a = exports.div = void 0;
4
4
  const vNode_1 = require("../Node/vNode");
5
- exports.div = vNode_1.vNode.ToFunction('div');
6
- exports.a = vNode_1.vNode.ToFunction('a');
7
- exports.button = vNode_1.vNode.ToFunction('button');
8
- exports.h1 = vNode_1.vNode.ToFunction('h1');
9
- exports.input = vNode_1.vNode.ToFunction('input');
10
- exports.span = vNode_1.vNode.ToFunction('span');
11
- exports.table = vNode_1.vNode.ToFunction('table');
12
- exports.tbody = vNode_1.vNode.ToFunction('tbody');
13
- exports.tr = vNode_1.vNode.ToFunction('tr');
14
- exports.td = vNode_1.vNode.ToFunction('td');
5
+ exports.div = vNode_1.vNode.ToFunction("div");
6
+ exports.a = vNode_1.vNode.ToFunction("a");
7
+ exports.button = vNode_1.vNode.ToFunction("button");
8
+ exports.h1 = vNode_1.vNode.ToFunction("h1");
9
+ exports.input = vNode_1.vNode.ToFunction("input");
10
+ exports.span = vNode_1.vNode.ToFunction("span");
11
+ exports.table = vNode_1.vNode.ToFunction("table");
12
+ exports.tbody = vNode_1.vNode.ToFunction("tbody");
13
+ exports.tr = vNode_1.vNode.ToFunction("tr");
14
+ exports.td = vNode_1.vNode.ToFunction("td");
15
+ const textElement = vNode_1.vNode.ToFunction("text");
16
+ const text = function (callback) {
17
+ return textElement({ props: () => ({ nodeValue: callback() }) });
18
+ };
19
+ exports.text = text;
package/Node/vNode.js CHANGED
@@ -141,30 +141,34 @@ function InitNode(vnode) {
141
141
  }
142
142
  function StaticChildren(vnode, children) {
143
143
  const childrenScope = Store_1.ObservableScope.Create(WrapStaticChildren(vnode.injector, children));
144
+ vnode.scopes.push(childrenScope);
144
145
  const child = Store_1.ObservableScope.Peek(childrenScope);
145
- if (typeof child === "string") {
146
- const node = vNode.Create({
147
- type: "text",
148
- namespace: null,
149
- props() {
150
- return { nodeValue: Store_1.ObservableScope.Value(childrenScope) };
151
- },
152
- });
153
- node.scopes.push(childrenScope);
154
- vnode.children = [node];
155
- }
156
- else {
157
- vnode.scopes.push(childrenScope);
158
- Store_1.ObservableScope.Touch(childrenScope);
159
- Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function () {
160
- if (vnode.destroyed)
161
- return;
162
- vNode.DestroyAll(vnode.children);
163
- const nodes = Store_1.ObservableScope.Peek(childrenScope);
164
- vnode.children = Array.isArray(nodes) ? nodes : [nodes];
165
- UpdateChildren(vnode);
166
- }));
167
- vnode.children = Array.isArray(child) ? child : [child];
146
+ const type = typeof child;
147
+ switch (type) {
148
+ case 'string': {
149
+ const node = vNode.Create({
150
+ type: "text",
151
+ namespace: null,
152
+ props() {
153
+ return { nodeValue: Store_1.ObservableScope.Value(childrenScope) };
154
+ },
155
+ });
156
+ vnode.children = [node];
157
+ break;
158
+ }
159
+ default: {
160
+ Store_1.ObservableScope.Touch(childrenScope);
161
+ Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function () {
162
+ if (vnode.destroyed)
163
+ return;
164
+ vNode.DestroyAll(vnode.children);
165
+ const nodes = Store_1.ObservableScope.Peek(childrenScope);
166
+ vnode.children = Array.isArray(nodes) ? nodes : [nodes];
167
+ UpdateChildren(vnode);
168
+ }));
169
+ vnode.children = (Array.isArray(child) ? child : [child]);
170
+ break;
171
+ }
168
172
  }
169
173
  }
170
174
  function WrapStaticChildren(injector, children) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.8",
3
+ "version": "7.0.10",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",