j-templates 7.0.33 → 7.0.35

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 CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vNode = void 0;
4
4
  const Store_1 = require("../Store");
5
+ const functions_1 = require("../Utils/functions");
5
6
  const injector_1 = require("../Utils/injector");
6
7
  const list_1 = require("../Utils/list");
7
8
  const thread_1 = require("../Utils/thread");
@@ -152,8 +153,10 @@ function Children(vnode, children, data) {
152
153
  function CreateChildrenScope(vnode, children, data) {
153
154
  if (data === undefined)
154
155
  return Store_1.ObservableScope.Create(WrapStaticChildren(vnode, children));
156
+ const dataIsAsync = (0, functions_1.IsAsync)(data);
155
157
  const nodeList = list_1.List.Create();
156
158
  const scope = Store_1.ObservableScope.Create(WrapChildren(vnode.injector, children, ToArray(data), nodeList));
159
+ scope.async = dataIsAsync;
157
160
  Store_1.ObservableScope.OnDestroyed(scope, function () {
158
161
  DestroyNodeList(nodeList);
159
162
  });
@@ -162,7 +165,8 @@ function CreateChildrenScope(vnode, children, data) {
162
165
  function WrapStaticChildren(vnode, children) {
163
166
  return function () {
164
167
  vnode.children && vNode.DestroyAll(vnode.children);
165
- return injector_1.Injector.Scope(vnode.injector, children, undefined);
168
+ const childNodes = injector_1.Injector.Scope(vnode.injector, children, undefined);
169
+ return CreateNodeArray(childNodes, vnode.children);
166
170
  };
167
171
  }
168
172
  function WrapChildren(injector, children, data, nodeList) {
@@ -191,14 +195,7 @@ function WrapChildren(injector, children, data, nodeList) {
191
195
  nodeListMap.delete(data);
192
196
  const childrenScope = Store_1.ObservableScope.Create(function () {
193
197
  const childNodes = injector_1.Injector.Scope(injector, children, data);
194
- const nodes = typeof childNodes === 'string' ? [vNode.Create({
195
- type: 'text',
196
- namespace: null,
197
- props: {
198
- nodeValue: childNodes
199
- }
200
- })] : Array.isArray(childNodes) ? childNodes : [childNodes];
201
- return nodes;
198
+ return CreateNodeArray(childNodes);
202
199
  });
203
200
  list_1.List.Add(nextNodeList, {
204
201
  data,
@@ -216,6 +213,18 @@ function WrapChildren(injector, children, data, nodeList) {
216
213
  }
217
214
  };
218
215
  }
216
+ function CreateNodeArray(children, previousChildren) {
217
+ if (Array.isArray(children))
218
+ return children;
219
+ return typeof children === 'string' ? [vNode.Create({
220
+ type: 'text',
221
+ namespace: null,
222
+ node: previousChildren?.[0]?.type === 'text' && previousChildren[0].node || undefined,
223
+ props: {
224
+ nodeValue: children
225
+ }
226
+ })] : [children];
227
+ }
219
228
  function DestroyNodeList(nodeList) {
220
229
  for (let node = nodeList.head; node !== null; node = node.next) {
221
230
  vNode.DestroyAll(node.data.nodes);
@@ -228,23 +237,7 @@ function GetData(data) {
228
237
  }
229
238
  function AssignChildren(vnode, childrenScope) {
230
239
  const children = Store_1.ObservableScope.Peek(childrenScope);
231
- switch (typeof children) {
232
- case 'string': {
233
- vnode.children = [vNode.Create({
234
- type: 'text',
235
- namespace: null,
236
- node: vnode.children?.[0]?.type === 'text' && vnode.children[0].node || undefined,
237
- props: {
238
- nodeValue: children
239
- }
240
- })];
241
- break;
242
- }
243
- default: {
244
- vnode.children = Array.isArray(children) ? children : [children];
245
- break;
246
- }
247
- }
240
+ vnode.children = children;
248
241
  }
249
242
  function UpdateChildren(vnode, init = false, skipInit = false) {
250
243
  if (!vnode.children)
@@ -5,6 +5,7 @@ exports.CalcScope = CalcScope;
5
5
  const array_1 = require("../../Utils/array");
6
6
  const distinctArray_1 = require("../../Utils/distinctArray");
7
7
  const emitter_1 = require("../../Utils/emitter");
8
+ const functions_1 = require("../../Utils/functions");
8
9
  class ObservableScopeValue {
9
10
  get Value() {
10
11
  return ObservableScope.Value(this.scope);
@@ -74,7 +75,7 @@ function CalcScope(callback) {
74
75
  getFunction: valueFunction,
75
76
  value: null,
76
77
  promise: null,
77
- async: valueFunction[Symbol.toStringTag] === "AsyncFunction",
78
+ async: (0, functions_1.IsAsync)(valueFunction),
78
79
  dirty: true,
79
80
  emitter: emitter_1.Emitter.Create(),
80
81
  emitters: null,
@@ -0,0 +1 @@
1
+ export declare function IsAsync(func: Function): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsAsync = IsAsync;
4
+ function IsAsync(func) {
5
+ return func[Symbol.toStringTag] === "AsyncFunction";
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.33",
3
+ "version": "7.0.35",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",