j-templates 6.1.12 → 7.0.1

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.
Files changed (48) hide show
  1. package/DOM/createAssignment.js +4 -5
  2. package/DOM/createAttributeAssignment.d.ts +1 -0
  3. package/DOM/createAttributeAssignment.js +16 -0
  4. package/DOM/createPropertyAssignment.d.ts +1 -0
  5. package/DOM/createPropertyAssignment.js +7 -0
  6. package/DOM/domNodeConfig.js +40 -0
  7. package/DOM/elements.d.ts +80 -26
  8. package/DOM/elements.js +12 -101
  9. package/DOM/index.d.ts +0 -1
  10. package/DOM/index.js +0 -1
  11. package/DOM/svgElements.d.ts +0 -4
  12. package/DOM/svgElements.js +0 -16
  13. package/Node/component.d.ts +19 -16
  14. package/Node/component.js +25 -31
  15. package/Node/component.types.d.ts +5 -0
  16. package/Node/nodeConfig.d.ts +7 -0
  17. package/Node/vNode.d.ts +20 -0
  18. package/Node/vNode.js +296 -0
  19. package/Node/vNode.types.d.ts +45 -0
  20. package/Store/Tree/observableNode.js +1 -2
  21. package/Store/Tree/observableScope.d.ts +2 -0
  22. package/Store/Tree/observableScope.js +29 -8
  23. package/Utils/avlTree.js +5 -6
  24. package/Utils/decorators.d.ts +4 -25
  25. package/Utils/decorators.js +3 -61
  26. package/Utils/distinctArray.d.ts +1 -1
  27. package/Utils/distinctArray.js +2 -2
  28. package/Utils/list.js +4 -37
  29. package/index.d.ts +1 -2
  30. package/package.json +1 -1
  31. package/Node/boundNode.d.ts +0 -4
  32. package/Node/boundNode.js +0 -115
  33. package/Node/boundNode.types.d.ts +0 -57
  34. package/Node/componentNode.d.ts +0 -7
  35. package/Node/componentNode.js +0 -123
  36. package/Node/componentNode.types.d.ts +0 -37
  37. package/Node/elementNode.d.ts +0 -5
  38. package/Node/elementNode.js +0 -176
  39. package/Node/elementNode.types.d.ts +0 -40
  40. package/Node/elementNode.types.js +0 -2
  41. package/Node/nodeRef.d.ts +0 -26
  42. package/Node/nodeRef.js +0 -253
  43. package/Node/nodeRef.types.d.ts +0 -21
  44. package/Node/nodeRef.types.js +0 -2
  45. package/Node/textNode.types.d.ts +0 -7
  46. package/Node/textNode.types.js +0 -2
  47. /package/Node/{boundNode.types.js → component.types.js} +0 -0
  48. /package/Node/{componentNode.types.js → vNode.types.js} +0 -0
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
- const node = PopNode(tempList) ?? { previous: null, next: null, data: null };
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
- let node = list.head;
69
- while (node) {
70
- node.data = null;
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;
package/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { AllNodeRefTypes as NodeRefTypes } from "./Node/nodeRef.types";
2
- export { Component } from "./Node/component";
1
+ export { Component } from './Node/component';
3
2
  export { CalcScope as calc } from './Store/Tree/observableScope';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "6.1.12",
3
+ "version": "7.0.1",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",
@@ -1,4 +0,0 @@
1
- import { IBoundNodeBase } from "./boundNode.types";
2
- export declare namespace BoundNode {
3
- function Init(boundNode: IBoundNodeBase): void;
4
- }
package/Node/boundNode.js DELETED
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BoundNode = void 0;
4
- const nodeConfig_1 = require("./nodeConfig");
5
- const observableScope_1 = require("../Store/Tree/observableScope");
6
- var BoundNode;
7
- (function (BoundNode) {
8
- function WrapEventObject(node, events) {
9
- const keys = Object.keys(events);
10
- const ret = {};
11
- for (let x = 0; x < keys.length; x++) {
12
- const event = keys[x];
13
- const eventFunc = events[event];
14
- ret[event] = function (event) {
15
- if (node.destroyed)
16
- return;
17
- return eventFunc(event);
18
- };
19
- }
20
- return ret;
21
- }
22
- function Init(boundNode) {
23
- const nodeDef = boundNode.nodeDef;
24
- if (nodeDef.props) {
25
- boundNode.assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(boundNode.node);
26
- if (typeof nodeDef.props === 'function') {
27
- const scope = observableScope_1.ObservableScope.Create(nodeDef.props);
28
- boundNode.scopes ??= [];
29
- boundNode.scopes.push(scope);
30
- observableScope_1.ObservableScope.Watch(scope, function (scope) { ScheduleSetProperties(boundNode, scope); });
31
- const next = observableScope_1.ObservableScope.Value(scope);
32
- boundNode.assignProperties(next);
33
- }
34
- else {
35
- boundNode.assignProperties(nodeDef.props);
36
- boundNode.assignProperties = null;
37
- }
38
- }
39
- if (nodeDef.attrs) {
40
- if (typeof nodeDef.attrs === 'function') {
41
- const scope = observableScope_1.ObservableScope.Create(nodeDef.attrs);
42
- boundNode.scopes ??= [];
43
- boundNode.scopes.push(scope);
44
- observableScope_1.ObservableScope.Watch(scope, function (scope) { ScheduleSetAttributes(boundNode, scope); });
45
- SetAttributes(boundNode, observableScope_1.ObservableScope.Value(scope));
46
- }
47
- else
48
- SetAttributes(boundNode, nodeDef.attrs);
49
- }
50
- if (nodeDef.on) {
51
- boundNode.assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(boundNode.node);
52
- if (typeof nodeDef.on === 'function') {
53
- const scope = observableScope_1.ObservableScope.Create(nodeDef.on);
54
- const eventScope = observableScope_1.ObservableScope.Create(function () {
55
- const events = observableScope_1.ObservableScope.Value(scope);
56
- return WrapEventObject(boundNode, events);
57
- });
58
- boundNode.scopes ??= [];
59
- boundNode.scopes.push(scope, eventScope);
60
- observableScope_1.ObservableScope.Watch(eventScope, function (scope) { ScheduleSetEvents(boundNode, scope); });
61
- const next = observableScope_1.ObservableScope.Value(eventScope);
62
- boundNode.assignEvents(next);
63
- }
64
- else {
65
- boundNode.assignEvents(WrapEventObject(boundNode, nodeDef.on));
66
- boundNode.assignEvents = null;
67
- }
68
- }
69
- }
70
- BoundNode.Init = Init;
71
- })(BoundNode || (exports.BoundNode = BoundNode = {}));
72
- function ScheduleSetProperties(node, scope) {
73
- if (node.setProperties)
74
- return;
75
- node.setProperties = true;
76
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
77
- node.setProperties = false;
78
- if (node.destroyed)
79
- return;
80
- const next = observableScope_1.ObservableScope.Value(scope);
81
- node.assignProperties(next || null);
82
- });
83
- }
84
- function ScheduleSetAttributes(node, scope) {
85
- if (node.setAttributes)
86
- return;
87
- node.setAttributes = true;
88
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
89
- node.setAttributes = false;
90
- if (node.destroyed)
91
- return;
92
- SetAttributes(node, observableScope_1.ObservableScope.Value(scope));
93
- });
94
- }
95
- function SetAttributes(node, attributes) {
96
- if (!attributes)
97
- return;
98
- for (var key in attributes) {
99
- var val = nodeConfig_1.NodeConfig.getAttribute(node.node, key);
100
- if (val !== attributes[key])
101
- nodeConfig_1.NodeConfig.setAttribute(node.node, key, attributes[key]);
102
- }
103
- }
104
- function ScheduleSetEvents(node, scope) {
105
- if (node.setEvents)
106
- return;
107
- node.setEvents = true;
108
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
109
- node.setEvents = false;
110
- if (node.destroyed)
111
- return;
112
- const next = observableScope_1.ObservableScope.Value(scope);
113
- node.assignEvents(next);
114
- });
115
- }
@@ -1,57 +0,0 @@
1
- import { IObservableScope } from "../Store/Tree/observableScope";
2
- import { RecursivePartial } from "../Utils/utils.types";
3
- import { NodeRefType } from "./nodeRef";
4
- import { AllNodeRefTypes, INodeRefBase } from "./nodeRef.types";
5
- export type FunctionOr<T> = {
6
- (...args: Array<any>): T | Promise<T>;
7
- } | T;
8
- export type NodeRefEvents<E extends {
9
- [event: string]: any;
10
- } = any> = {
11
- [P in keyof E]?: {
12
- (events: E[P]): void;
13
- };
14
- };
15
- export interface NodeDefinition<T = any, E = any> {
16
- type: any;
17
- namespace: string;
18
- props?: FunctionOr<{
19
- [name: string]: unknown;
20
- }>;
21
- attrs?: FunctionOr<{
22
- [name: string]: string;
23
- }>;
24
- on?: FunctionOr<NodeRefEvents<E>>;
25
- text?: FunctionOr<string>;
26
- }
27
- export interface BoundNodeFunctionParam<P = HTMLElement, E = HTMLElementEventMap> {
28
- props?: FunctionOr<RecursivePartial<P>>;
29
- attrs?: FunctionOr<{
30
- [name: string]: string;
31
- }>;
32
- on?: FunctionOr<NodeRefEvents<E>>;
33
- text?: FunctionOr<string>;
34
- }
35
- export interface IBoundNodeBase extends INodeRefBase {
36
- nodeDef: BoundNodeFunctionParam;
37
- scopes: IObservableScope<unknown>[];
38
- setProperties: boolean;
39
- assignProperties: {
40
- (next: any): void;
41
- };
42
- assignEvents: {
43
- (next: {
44
- [event: string]: (event: Event) => void;
45
- }): void;
46
- };
47
- assignText: {
48
- (next: string): void;
49
- };
50
- setAttributes: boolean;
51
- setEvents: boolean;
52
- setText: boolean;
53
- }
54
- export interface IBoundNode extends IBoundNodeBase {
55
- type: NodeRefType.BoundNode;
56
- childNodes: AllNodeRefTypes[];
57
- }
@@ -1,7 +0,0 @@
1
- import { ComponentConstructor } from "./component";
2
- import { ComponentNodeFunction, IComponentNodeBase } from "./componentNode.types";
3
- export declare namespace ComponentNode {
4
- function Fire<E, P extends keyof E>(event: P, data?: E[P]): void;
5
- function ToFunction<D = void, T = void, E = void>(type: any, namespace: string, constructor: ComponentConstructor<D, T, E>): ComponentNodeFunction<D, T, E>;
6
- function Init(componentNode: IComponentNodeBase<any, any, any>): void;
7
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComponentNode = void 0;
4
- const boundNode_1 = require("./boundNode");
5
- const nodeRef_1 = require("./nodeRef");
6
- const nodeConfig_1 = require("./nodeConfig");
7
- const component_1 = require("./component");
8
- const injector_1 = require("../Utils/injector");
9
- const decorators_1 = require("../Utils/decorators");
10
- const thread_1 = require("../Utils/thread");
11
- const list_1 = require("../Utils/list");
12
- var ComponentNode;
13
- (function (ComponentNode) {
14
- function Fire(event, data) {
15
- var eventCallback = this.componentEvents && this.componentEvents[event];
16
- eventCallback && eventCallback(data);
17
- }
18
- ComponentNode.Fire = Fire;
19
- function ToFunction(type, namespace, constructor) {
20
- return function (nodeDef, templates) {
21
- return Create(type, namespace, nodeDef, constructor, templates);
22
- };
23
- }
24
- ComponentNode.ToFunction = ToFunction;
25
- function Init(componentNode) {
26
- var nodeDef = componentNode.nodeDef;
27
- var events = nodeDef.on;
28
- nodeDef.on = null;
29
- componentNode.component = new componentNode.constructor(nodeDef.data, componentNode.templates, componentNode, events);
30
- SetChildren(componentNode);
31
- boundNode_1.BoundNode.Init(componentNode);
32
- }
33
- ComponentNode.Init = Init;
34
- })(ComponentNode || (exports.ComponentNode = ComponentNode = {}));
35
- function Create(type, namespace, nodeDef, constructor, templates) {
36
- var compNode = nodeRef_1.NodeRef.Create(type, namespace, nodeRef_1.NodeRefType.ComponentNode);
37
- compNode.nodeDef = nodeDef;
38
- compNode.constructor = constructor;
39
- compNode.templates = templates;
40
- return compNode;
41
- }
42
- function SetChildren(node) {
43
- if (decorators_1.PreReq.Has(node.component)) {
44
- AddPreReqTemplate(node).then(function () {
45
- AddTemplate(node, false);
46
- });
47
- }
48
- else
49
- AddTemplate(node, true);
50
- }
51
- function AddPreReqTemplate(node) {
52
- return new Promise(resolve => {
53
- (0, thread_1.Thread)(function () {
54
- const preNodes = injector_1.Injector.Scope(node.injector, decorators_1.PreReqTemplate.Get, node.component);
55
- (0, thread_1.Schedule)(function () {
56
- if (node.destroyed)
57
- return;
58
- nodeRef_1.NodeRef.InitAll(node, preNodes);
59
- });
60
- (0, thread_1.Thread)(function () {
61
- if (node.destroyed)
62
- return;
63
- for (var x = 0; x < preNodes.length; x++)
64
- nodeRef_1.NodeRef.AddChild(node, preNodes[x]);
65
- decorators_1.PreReq.All(node.component).then(function () {
66
- if (node.destroyed)
67
- return;
68
- for (var x = 0; x < preNodes.length; x++)
69
- nodeRef_1.NodeRef.Destroy(preNodes[x]);
70
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
71
- if (node.destroyed)
72
- return;
73
- for (var x = 0; x < preNodes.length; x++)
74
- nodeRef_1.NodeRef.DetachChild(node, preNodes[x]);
75
- resolve();
76
- });
77
- });
78
- });
79
- });
80
- });
81
- }
82
- function InvokeNodeTemplate(node) {
83
- const nodes = node.component.Template();
84
- if (!Array.isArray(nodes))
85
- return [nodes];
86
- return nodes;
87
- }
88
- function AddTemplate(node, init) {
89
- (0, thread_1.Thread)(function () {
90
- if (node.destroyed)
91
- return;
92
- const nodes = injector_1.Injector.Scope(node.injector, InvokeNodeTemplate, node);
93
- (0, thread_1.Schedule)(function () {
94
- nodeRef_1.NodeRef.InitAll(node, nodes);
95
- });
96
- (0, thread_1.Thread)(function () {
97
- if (node.destroyed)
98
- return;
99
- const list = list_1.List.Create();
100
- list_1.List.Add(list, {
101
- value: undefined,
102
- init: true,
103
- scope: null,
104
- nodes
105
- });
106
- if (init) {
107
- nodeRef_1.NodeRef.ReconcileChildren(node, list);
108
- list_1.List.Clear(list);
109
- }
110
- else
111
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
112
- if (node.destroyed)
113
- return;
114
- nodeRef_1.NodeRef.ReconcileChildren(node, list);
115
- list_1.List.Clear(list);
116
- });
117
- });
118
- if (node.component.Bound !== component_1.Component.prototype.Bound)
119
- (0, thread_1.After)(function () {
120
- nodeConfig_1.NodeConfig.scheduleUpdate(() => setTimeout(() => node.component.Bound(), 0));
121
- });
122
- });
123
- }
@@ -1,37 +0,0 @@
1
- import { BoundNodeFunctionParam, IBoundNodeBase, NodeDefinition } from "./boundNode.types";
2
- import { Component, ComponentConstructor } from "./component";
3
- import { NodeRefType } from "./nodeRef";
4
- import { AllNodeRefTypes } from "./nodeRef.types";
5
- export type ComponentNodeEvents<E = void> = {
6
- [P in keyof E]?: {
7
- (data: E[P]): void;
8
- };
9
- };
10
- export interface ComponentNodeDefinition<D = void, E = void> extends NodeDefinition<D> {
11
- on: ComponentNodeEvents<E>;
12
- data?: {
13
- (): D | Promise<D>;
14
- };
15
- }
16
- export interface ComponentNodeFunctionParam<D = void, E = void, P = HTMLElement> extends BoundNodeFunctionParam<P> {
17
- on?: ComponentNodeEvents<E>;
18
- data?: {
19
- (): D | Promise<D>;
20
- };
21
- }
22
- export type ComponentNodeFunction<D = void, T = void, E = void> = (nodeDef: ComponentNodeFunctionParam<D, E>, templates?: T) => IComponentNode<D, T, E>;
23
- export interface IComponentNodeBase<D, T, E> extends IBoundNodeBase {
24
- nodeDef: ComponentNodeFunctionParam<D, E>;
25
- constructor: ComponentConstructor<D, T, E>;
26
- component: Component<D, T, E>;
27
- componentEvents: {
28
- [name: string]: {
29
- (...args: Array<any>): void;
30
- };
31
- };
32
- templates: T;
33
- }
34
- export interface IComponentNode<D, T, E> extends IComponentNodeBase<D, T, E> {
35
- type: NodeRefType.ComponentNode;
36
- childNodes: AllNodeRefTypes[];
37
- }
@@ -1,5 +0,0 @@
1
- import { ElementChildrenFunctionParam, ElementNodeFunctionParam, IElementNode, IElementNodeBase } from "./elementNode.types";
2
- export declare namespace ElementNode {
3
- function Create<T>(type: any, namespace: string, nodeDef: ElementNodeFunctionParam<T>, children: ElementChildrenFunctionParam<T>): IElementNode<T>;
4
- function Init<T>(elementNode: IElementNodeBase<T>): void;
5
- }
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElementNode = void 0;
4
- const observableScope_1 = require("../Store/Tree/observableScope");
5
- const injector_1 = require("../Utils/injector");
6
- const list_1 = require("../Utils/list");
7
- const thread_1 = require("../Utils/thread");
8
- const boundNode_1 = require("./boundNode");
9
- const nodeConfig_1 = require("./nodeConfig");
10
- const nodeRef_1 = require("./nodeRef");
11
- const valueDefault = [];
12
- var ElementNode;
13
- (function (ElementNode) {
14
- function Create(type, namespace, nodeDef, children) {
15
- var elemNode = nodeRef_1.NodeRef.Create(type, namespace, nodeRef_1.NodeRefType.ElementNode);
16
- elemNode.nodeDef = nodeDef;
17
- if (Array.isArray(children))
18
- elemNode.childrenArray = children;
19
- else if (children !== undefined)
20
- elemNode.children = children;
21
- return elemNode;
22
- }
23
- ElementNode.Create = Create;
24
- function CreateValueScopeCallback(dataScope) {
25
- return function () {
26
- const value = observableScope_1.ObservableScope.Value(dataScope);
27
- if (!value)
28
- return valueDefault;
29
- if (!Array.isArray(value))
30
- return [value];
31
- return value;
32
- };
33
- }
34
- function CreateNodeScopeCallback(elementNode, valueScope) {
35
- let lastNodeList;
36
- return function () {
37
- const values = observableScope_1.ObservableScope.Value(valueScope);
38
- const lastNodeMap = lastNodeList && list_1.List.ToNodeMap(lastNodeList, GetDataValue);
39
- const nextNodeList = list_1.List.Create();
40
- for (let x = 0; x < values.length; x++) {
41
- let curNode = null;
42
- if (lastNodeMap !== undefined) {
43
- const nodeArr = lastNodeMap.get(values[x]);
44
- if (nodeArr !== undefined) {
45
- let y = nodeArr.length - 1;
46
- for (; y >= 0 && nodeArr[y] === null; y--) { }
47
- curNode = nodeArr[y];
48
- nodeArr[y] = null;
49
- }
50
- }
51
- const value = values[x];
52
- if (curNode !== null) {
53
- list_1.List.RemoveNode(lastNodeList, curNode);
54
- list_1.List.AddNode(nextNodeList, curNode);
55
- const nextNodes = observableScope_1.ObservableScope.Value(curNode.data.scope);
56
- if (curNode.data.nodes !== nextNodes) {
57
- list_1.List.Add(elementNode.destroyNodeList, {
58
- ...curNode.data,
59
- scope: null
60
- });
61
- curNode.data.init = false;
62
- curNode.data.nodes = nextNodes;
63
- }
64
- }
65
- else {
66
- const scope = observableScope_1.ObservableScope.Create(function () {
67
- return injector_1.Injector.Scope(elementNode.injector, CreateNodeArray, elementNode.children, value);
68
- });
69
- curNode = list_1.List.Add(nextNodeList, {
70
- value,
71
- init: false,
72
- scope,
73
- nodes: observableScope_1.ObservableScope.Value(scope),
74
- });
75
- }
76
- }
77
- lastNodeList && list_1.List.Append(elementNode.destroyNodeList, lastNodeList);
78
- lastNodeList = nextNodeList;
79
- return nextNodeList;
80
- };
81
- }
82
- function Init(elementNode) {
83
- elementNode.childNodes = new Set();
84
- if (elementNode.children !== null) {
85
- const dataScope = elementNode.nodeDef.data ? observableScope_1.ObservableScope.Create(elementNode.nodeDef.data) : observableScope_1.ObservableScope.Create(function () {
86
- return [true];
87
- });
88
- const valueScope = observableScope_1.ObservableScope.Create(CreateValueScopeCallback(dataScope));
89
- const nodeScope = observableScope_1.ObservableScope.Create(CreateNodeScopeCallback(elementNode, valueScope));
90
- elementNode.childNodes = new Set();
91
- elementNode.scopes ??= [];
92
- elementNode.scopes.push(dataScope, valueScope, nodeScope);
93
- observableScope_1.ObservableScope.Watch(nodeScope, function (scope) {
94
- ScheduleSetData(elementNode, scope);
95
- });
96
- UpdateNodes(elementNode, observableScope_1.ObservableScope.Value(nodeScope), true);
97
- }
98
- else if (elementNode.childrenArray !== null) {
99
- SetDefaultData(elementNode);
100
- }
101
- boundNode_1.BoundNode.Init(elementNode);
102
- }
103
- ElementNode.Init = Init;
104
- })(ElementNode || (exports.ElementNode = ElementNode = {}));
105
- function ScheduleSetData(node, scope) {
106
- if (node.setData)
107
- return;
108
- node.setData = true;
109
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
110
- node.setData = false;
111
- if (node.destroyed)
112
- return;
113
- UpdateNodes(node, observableScope_1.ObservableScope.Value(scope));
114
- });
115
- }
116
- function SetDefaultData(node) {
117
- const nodes = node.childrenArray ||
118
- injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, true);
119
- node.childrenArray = null;
120
- const defaultNodeList = list_1.List.Create();
121
- list_1.List.Add(defaultNodeList, {
122
- value: null,
123
- init: false,
124
- scope: null,
125
- nodes
126
- });
127
- UpdateNodes(node, defaultNodeList, true);
128
- }
129
- function GetDataValue(data) {
130
- return data.value;
131
- }
132
- function UpdateNodes(elementNode, nodeList, init = false) {
133
- (0, thread_1.Synch)(function () {
134
- let data;
135
- while (data = list_1.List.Pop(elementNode.destroyNodeList)) {
136
- observableScope_1.ObservableScope.Destroy(data.scope);
137
- for (let x = 0; x < data.nodes.length; x++)
138
- elementNode.childNodes.delete(data.nodes[x]);
139
- nodeRef_1.NodeRef.DestroyAll(data.nodes);
140
- }
141
- for (let node = nodeList.head; node !== null; node = node.next) {
142
- if (!node.data.init) {
143
- const nodeData = node.data;
144
- (0, thread_1.Schedule)(function () {
145
- if (elementNode.destroyed || nodeData.init)
146
- return;
147
- nodeRef_1.NodeRef.InitAll(elementNode, nodeData.nodes);
148
- nodeData.init = true;
149
- });
150
- }
151
- }
152
- const startSize = nodeList.size;
153
- (0, thread_1.Thread)(function (async) {
154
- if (elementNode.destroyed)
155
- return;
156
- if (init || !async)
157
- nodeRef_1.NodeRef.ReconcileChildren(elementNode, nodeList);
158
- else
159
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
160
- if (elementNode.destroyed || nodeList.size !== startSize)
161
- return;
162
- nodeRef_1.NodeRef.ReconcileChildren(elementNode, nodeList);
163
- });
164
- });
165
- });
166
- }
167
- function CreateNodeArray(childrenFunc, value) {
168
- const newNodes = childrenFunc(value);
169
- if (typeof newNodes === "string" || !newNodes) {
170
- const textNode = nodeRef_1.NodeRef.Create(newNodes, null, nodeRef_1.NodeRefType.TextNode);
171
- return [textNode];
172
- }
173
- if (Array.isArray(newNodes))
174
- return newNodes;
175
- return [newNodes];
176
- }
@@ -1,40 +0,0 @@
1
- import { IObservableScope } from "../Store/Tree/observableScope";
2
- import { IList } from "../Utils/list";
3
- import { NodeDefinition, BoundNodeFunctionParam, IBoundNodeBase } from "./boundNode.types";
4
- import { NodeRefType } from "./nodeRef";
5
- import { INodeRefBase, ElementNodeRefTypes, AllNodeRefTypes } from "./nodeRef.types";
6
- export type ElementChildrenFunction<T> = {
7
- (data: T): string | ElementNodeRefTypes | ElementNodeRefTypes[];
8
- };
9
- export type ElementChildrenFunctionParam<T> = ElementChildrenFunction<T> | ElementNodeRefTypes[];
10
- export type ElementNodeFunction<T> = {
11
- (nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): INodeRefBase;
12
- };
13
- export interface ElementNodeDefinition<T> extends NodeDefinition<T> {
14
- data?: {
15
- (): T | Array<T> | Promise<Array<T>> | Promise<T>;
16
- };
17
- children?: ElementChildrenFunction<T>;
18
- }
19
- export interface ElementNodeFunctionParam<T, P = HTMLElement, E = HTMLElementEventMap> extends BoundNodeFunctionParam<P, E> {
20
- data?: {
21
- (): T | Array<T> | Promise<Array<T>> | Promise<T>;
22
- };
23
- }
24
- export interface IElementDataNode<T> {
25
- value: T;
26
- init: boolean;
27
- scope: IObservableScope<AllNodeRefTypes[] | null>;
28
- nodes: AllNodeRefTypes[] | null;
29
- }
30
- export interface IElementNodeBase<T> extends IBoundNodeBase {
31
- nodeDef: ElementNodeFunctionParam<T>;
32
- children: ElementChildrenFunction<T>;
33
- childrenArray: ElementNodeRefTypes[];
34
- destroyNodeList: IList<IElementDataNode<T>>;
35
- setData: boolean;
36
- }
37
- export interface IElementNode<T> extends IElementNodeBase<T> {
38
- type: NodeRefType.ElementNode;
39
- childNodes: Set<AllNodeRefTypes>;
40
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });