j-templates 7.0.57 → 7.0.59

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,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vNode = void 0;
4
4
  const Store_1 = require("../Store");
5
+ const observableScope_1 = require("../Store/Tree/observableScope");
5
6
  const emitter_1 = require("../Utils/emitter");
7
+ const functions_1 = require("../Utils/functions");
6
8
  const injector_1 = require("../Utils/injector");
7
9
  const thread_1 = require("../Utils/thread");
8
10
  const nodeConfig_1 = require("./nodeConfig");
@@ -153,48 +155,45 @@ function InitNode(vnode) {
153
155
  UpdateChildren(vnode, true, !!childrenArray);
154
156
  }
155
157
  function Children(vnode, children, data) {
156
- const childrenScope = CreateChildrenScope(vnode, children, data);
157
- vnode.scopes.push(childrenScope);
158
- Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function (scope) {
159
- if (vnode.destroyed)
160
- return;
161
- const startChildren = vnode.children;
162
- AssignChildren(vnode, scope);
163
- startChildren !== vnode.children && UpdateChildren(vnode);
164
- }));
165
- AssignChildren(vnode, childrenScope);
158
+ const [childNodes, childrenScope] = CreateChildrenScope(vnode, children, data);
159
+ if (childrenScope) {
160
+ vnode.scopes.push(childrenScope);
161
+ Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function (scope) {
162
+ if (vnode.destroyed)
163
+ return;
164
+ const startChildren = vnode.children;
165
+ const newChildren = Store_1.ObservableScope.Value(scope);
166
+ if (startChildren !== newChildren) {
167
+ vnode.children = newChildren;
168
+ UpdateChildren(vnode);
169
+ }
170
+ }));
171
+ }
172
+ vnode.children = childNodes;
173
+ }
174
+ function AssignChildren(vnode, childrenScope) {
175
+ const children = Store_1.ObservableScope.Peek(childrenScope);
176
+ vnode.children = children;
166
177
  }
167
178
  const DEFAULT_DATA = [undefined];
168
179
  function DefaultData() {
169
180
  return DEFAULT_DATA;
170
181
  }
171
- function CreateChildrenScope(vnode, children, data) {
172
- let dataScope;
173
- if (data !== undefined) {
174
- dataScope = Store_1.ObservableScope.Create(data);
182
+ function CreateChildrenScope(vnode, children, data = DefaultData) {
183
+ if ((0, functions_1.IsAsync)(data)) {
184
+ const asyncData = data;
175
185
  data = function () {
176
- const result = Store_1.ObservableScope.Value(dataScope);
177
- if (!result)
178
- return [];
179
- if (Array.isArray(result))
180
- return result;
181
- return [result];
186
+ return (0, observableScope_1.CalcScope)(async function () {
187
+ return asyncData();
188
+ });
182
189
  };
183
190
  }
184
- else
185
- data = DefaultData;
186
- const scope = Store_1.ObservableScope.Create(WrapChildren(vnode.injector, children, data));
187
- dataScope &&
188
- Store_1.ObservableScope.OnDestroyed(scope, function () {
189
- Store_1.ObservableScope.Destroy(dataScope);
190
- return true;
191
- });
192
- return scope;
191
+ return Store_1.ObservableScope.CreateIf(WrapChildren(vnode.injector, children, data));
193
192
  }
194
193
  function WrapChildren(injector, children, data) {
195
194
  let nodeArray = [];
196
195
  return function () {
197
- const nextData = data();
196
+ const nextData = ToArray(data());
198
197
  switch (nextData.length) {
199
198
  case 0: {
200
199
  for (let x = 0; x < nodeArray.length; x++) {
@@ -213,6 +212,13 @@ function WrapChildren(injector, children, data) {
213
212
  return nodeArray;
214
213
  };
215
214
  }
215
+ function ToArray(result) {
216
+ if (!result)
217
+ return [];
218
+ if (Array.isArray(result))
219
+ return result;
220
+ return [result];
221
+ }
216
222
  function EvaluateNextNodesSmall(injector, getNextChildren, nextData, nodeArray) {
217
223
  if (nextData === DEFAULT_DATA) {
218
224
  const nextChildren = injector_1.Injector.Scope(injector, getNextChildren, nextData[0]);
@@ -321,10 +327,6 @@ function CreateNodeArray(children, previousChildren) {
321
327
  }
322
328
  return [children];
323
329
  }
324
- function AssignChildren(vnode, childrenScope) {
325
- const children = Store_1.ObservableScope.Peek(childrenScope);
326
- vnode.children = children;
327
- }
328
330
  function UpdateChildren(vnode, init = false, skipInit = false) {
329
331
  if (!vnode.children)
330
332
  return;
@@ -4,7 +4,8 @@ export declare class Store {
4
4
  private rootMap;
5
5
  private createNode;
6
6
  constructor(keyFunc?: (value: any) => string | undefined);
7
- Get<O>(id: string, defaultValue?: O): O | undefined;
7
+ Get<O>(id: string): O | undefined;
8
+ Get<O>(id: string, defaultValue: O): O;
8
9
  protected UpdateRootMap(results: JsonDiffResult): void;
9
10
  private UpdateRootObject;
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.57",
3
+ "version": "7.0.59",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",