j-templates 6.0.33 → 6.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/DOM/createPropertyAssignment.js +1 -0
- package/DOM/elements.d.ts +21 -21
- package/Node/elementNode.d.ts +2 -2
- package/Node/elementNode.js +33 -26
- package/Node/elementNode.types.d.ts +10 -12
- package/Node/nodeRef.js +3 -4
- package/Store/Tree/observableNode.js +6 -9
- package/Store/Tree/observableScope.d.ts +10 -0
- package/Store/Tree/observableScope.js +60 -15
- package/Utils/emitter.d.ts +4 -1
- package/Utils/emitter.js +11 -1
- package/Utils/list.js +18 -24
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/jTemplates.js +1 -1
- package/jTemplates.js.map +1 -1
- package/package.json +1 -1
package/DOM/elements.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { ElementNodeFunctionParam,
|
|
2
|
-
export declare function div<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
3
|
-
export declare function a<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
4
|
-
export declare function ul<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
5
|
-
export declare function li<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
1
|
+
import { ElementNodeFunctionParam, ElementChildrenFunctionParam } from "../Node/elementNode.types";
|
|
2
|
+
export declare function div<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
3
|
+
export declare function a<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
4
|
+
export declare function ul<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
5
|
+
export declare function li<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
6
6
|
export declare function br<T>(nodeDef: ElementNodeFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
7
|
-
export declare function b<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
8
|
-
export declare function span<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
7
|
+
export declare function b<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
8
|
+
export declare function span<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
9
9
|
export declare function img<T>(nodeDef: ElementNodeFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
10
|
-
export declare function video<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
10
|
+
export declare function video<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
11
11
|
export declare function source<T>(nodeDef: ElementNodeFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
12
12
|
export declare function input<T>(nodeDef: ElementNodeFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
13
13
|
export declare function textarea<T>(nodeDef: ElementNodeFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
14
|
-
export declare function select<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
15
|
-
export declare function option<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
16
|
-
export declare function h1<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
17
|
-
export declare function h2<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
18
|
-
export declare function h3<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
19
|
-
export declare function p<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
20
|
-
export declare function style<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
21
|
-
export declare function button<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
22
|
-
export declare function table<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
23
|
-
export declare function tbody<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
24
|
-
export declare function th<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
25
|
-
export declare function tr<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
26
|
-
export declare function td<T>(nodeDef: ElementNodeFunctionParam<T>, children?:
|
|
14
|
+
export declare function select<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
15
|
+
export declare function option<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
16
|
+
export declare function h1<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
17
|
+
export declare function h2<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
18
|
+
export declare function h3<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
19
|
+
export declare function p<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
20
|
+
export declare function style<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
21
|
+
export declare function button<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
22
|
+
export declare function table<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
23
|
+
export declare function tbody<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
24
|
+
export declare function th<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
25
|
+
export declare function tr<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
|
26
|
+
export declare function td<T>(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): import("../Node/elementNode.types").IElementNode<T>;
|
package/Node/elementNode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ElementChildrenFunctionParam, ElementNodeFunctionParam, IElementNode, IElementNodeBase } from "./elementNode.types";
|
|
2
2
|
export declare namespace ElementNode {
|
|
3
|
-
function Create<T>(type: any, namespace: string, nodeDef: ElementNodeFunctionParam<T>, children:
|
|
3
|
+
function Create<T>(type: any, namespace: string, nodeDef: ElementNodeFunctionParam<T>, children: ElementChildrenFunctionParam<T>): IElementNode<T>;
|
|
4
4
|
function Init<T>(elementNode: IElementNodeBase<T>): void;
|
|
5
5
|
}
|
package/Node/elementNode.js
CHANGED
|
@@ -14,33 +14,35 @@ var ElementNode;
|
|
|
14
14
|
function Create(type, namespace, nodeDef, children) {
|
|
15
15
|
var elemNode = nodeRef_1.NodeRef.Create(type, namespace, nodeRef_1.NodeRefType.ElementNode);
|
|
16
16
|
elemNode.nodeDef = nodeDef;
|
|
17
|
-
|
|
17
|
+
if (Array.isArray(children))
|
|
18
|
+
elemNode.childrenArray = children;
|
|
19
|
+
else if (children !== undefined)
|
|
20
|
+
elemNode.children = children;
|
|
18
21
|
return elemNode;
|
|
19
22
|
}
|
|
20
23
|
ElementNode.Create = Create;
|
|
21
24
|
function Init(elementNode) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
SetDefaultData(elementNode);
|
|
25
|
+
const nodeDef = elementNode.nodeDef;
|
|
26
|
+
if (elementNode.childrenArray !== null || (elementNode.children !== null && !nodeDef.data)) {
|
|
27
|
+
SetDefaultData(elementNode);
|
|
28
|
+
}
|
|
29
|
+
else if (elementNode.children !== null) {
|
|
30
|
+
const dataScope = observableScope_1.ObservableScope.Create(nodeDef.data);
|
|
31
|
+
const valueScope = observableScope_1.ObservableScope.Create(function () {
|
|
32
|
+
const value = observableScope_1.ObservableScope.Value(dataScope);
|
|
33
|
+
if (!value)
|
|
34
|
+
return valueDefault;
|
|
35
|
+
if (!Array.isArray(value))
|
|
36
|
+
return [value];
|
|
37
|
+
return value;
|
|
38
|
+
});
|
|
39
|
+
elementNode.childNodes = new Set();
|
|
40
|
+
elementNode.scopes ??= [];
|
|
41
|
+
elementNode.scopes.push(dataScope, valueScope);
|
|
42
|
+
observableScope_1.ObservableScope.Watch(valueScope, function () {
|
|
43
|
+
ScheduleSetData(elementNode, valueScope);
|
|
44
|
+
});
|
|
45
|
+
SetData(elementNode, observableScope_1.ObservableScope.Value(valueScope), true);
|
|
44
46
|
}
|
|
45
47
|
boundNode_1.BoundNode.Init(elementNode);
|
|
46
48
|
}
|
|
@@ -59,9 +61,14 @@ function ScheduleSetData(node, scope) {
|
|
|
59
61
|
}
|
|
60
62
|
function SetDefaultData(node) {
|
|
61
63
|
(0, thread_1.Synch)(function () {
|
|
62
|
-
const nodes = injector_1.Injector.Scope(node.injector, CreateNodeArray, node.
|
|
64
|
+
const nodes = node.childrenArray || injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, true);
|
|
65
|
+
node.childrenArray = null;
|
|
63
66
|
if (nodes.length > 0) {
|
|
64
|
-
|
|
67
|
+
(0, thread_1.Schedule)(function () {
|
|
68
|
+
if (node.destroyed)
|
|
69
|
+
return;
|
|
70
|
+
nodeRef_1.NodeRef.InitAll(node, nodes);
|
|
71
|
+
});
|
|
65
72
|
(0, thread_1.Thread)(function () {
|
|
66
73
|
if (node.destroyed)
|
|
67
74
|
return;
|
|
@@ -104,7 +111,7 @@ function ReconcileNodeData(node, values) {
|
|
|
104
111
|
curNode = list_1.List.Add(nextNodeList, {
|
|
105
112
|
value: values[x],
|
|
106
113
|
init: false,
|
|
107
|
-
nodes: injector_1.Injector.Scope(node.injector, CreateNodeArray, node.
|
|
114
|
+
nodes: injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, values[x])
|
|
108
115
|
});
|
|
109
116
|
}
|
|
110
117
|
}
|
|
@@ -2,25 +2,24 @@ import { IList } from "../Utils/list";
|
|
|
2
2
|
import { NodeDefinition, BoundNodeFunctionParam, IBoundNodeBase } from "./boundNode.types";
|
|
3
3
|
import { NodeRefType } from "./nodeRef";
|
|
4
4
|
import { INodeRefBase, NodeRefTypes } from "./nodeRef.types";
|
|
5
|
+
export type ElementChildrenFunction<T> = {
|
|
6
|
+
(data: T): string | NodeRefTypes | NodeRefTypes[];
|
|
7
|
+
};
|
|
8
|
+
export type ElementChildrenFunctionParam<T> = ElementChildrenFunction<T> | NodeRefTypes[];
|
|
9
|
+
export type ElementNodeFunction<T> = {
|
|
10
|
+
(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): INodeRefBase;
|
|
11
|
+
};
|
|
5
12
|
export interface ElementNodeDefinition<T> extends NodeDefinition<T> {
|
|
6
13
|
data?: {
|
|
7
14
|
(): T | Array<T> | Promise<Array<T>> | Promise<T>;
|
|
8
15
|
};
|
|
9
|
-
children?:
|
|
10
|
-
(data?: T): string | NodeRefTypes | NodeRefTypes[];
|
|
11
|
-
};
|
|
16
|
+
children?: ElementChildrenFunction<T>;
|
|
12
17
|
}
|
|
13
18
|
export interface ElementNodeFunctionParam<T> extends BoundNodeFunctionParam {
|
|
14
19
|
data?: {
|
|
15
20
|
(): T | Array<T> | Promise<Array<T>> | Promise<T>;
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
|
-
export type ElementChildrenFunction<T> = {
|
|
19
|
-
(data: T): string | NodeRefTypes | NodeRefTypes[];
|
|
20
|
-
};
|
|
21
|
-
export type ElementNodeFunction<T> = {
|
|
22
|
-
(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunction<T>): INodeRefBase;
|
|
23
|
-
};
|
|
24
23
|
export interface IElementDataNode<T> {
|
|
25
24
|
value: T;
|
|
26
25
|
init: boolean;
|
|
@@ -28,9 +27,8 @@ export interface IElementDataNode<T> {
|
|
|
28
27
|
}
|
|
29
28
|
export interface IElementNodeBase<T> extends IBoundNodeBase {
|
|
30
29
|
nodeDef: ElementNodeFunctionParam<T>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
30
|
+
children: ElementChildrenFunction<T>;
|
|
31
|
+
childrenArray: NodeRefTypes[];
|
|
34
32
|
nodeList: IList<IElementDataNode<T>> | null;
|
|
35
33
|
setData: boolean;
|
|
36
34
|
}
|
package/Node/nodeRef.js
CHANGED
|
@@ -75,7 +75,8 @@ var NodeRef;
|
|
|
75
75
|
assignText: null,
|
|
76
76
|
setAttributes: false,
|
|
77
77
|
setEvents: false,
|
|
78
|
-
|
|
78
|
+
children: null,
|
|
79
|
+
childrenArray: null,
|
|
79
80
|
nodeList: null,
|
|
80
81
|
setData: false,
|
|
81
82
|
setText: false,
|
|
@@ -157,10 +158,9 @@ var NodeRef;
|
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
160
|
let priorNode;
|
|
160
|
-
let curDataNode = nextChildren?.head;
|
|
161
161
|
let insert = false;
|
|
162
162
|
let remove = false;
|
|
163
|
-
|
|
163
|
+
for (let curDataNode = nextChildren.head; curDataNode !== null; curDataNode = curDataNode.next) {
|
|
164
164
|
for (let x = 0; x < curDataNode.data.nodes.length; x++) {
|
|
165
165
|
const actualNode = priorNode ? nodeConfig_1.NodeConfig.getNextSibling(priorNode) : nodeConfig_1.NodeConfig.getFirstChild(rootNode);
|
|
166
166
|
const virtualNode = curDataNode.data.nodes[x];
|
|
@@ -177,7 +177,6 @@ var NodeRef;
|
|
|
177
177
|
}
|
|
178
178
|
priorNode = expectedNode;
|
|
179
179
|
}
|
|
180
|
-
curDataNode = curDataNode.next;
|
|
181
180
|
}
|
|
182
181
|
let lastChild = nodeConfig_1.NodeConfig.getLastChild(rootNode);
|
|
183
182
|
while (priorNode && priorNode !== lastChild) {
|
|
@@ -106,6 +106,7 @@ function CreateProxyFactory(alias) {
|
|
|
106
106
|
ownKeys,
|
|
107
107
|
getOwnPropertyDescriptor,
|
|
108
108
|
});
|
|
109
|
+
leafScopeCache.set(value, {});
|
|
109
110
|
proxyCache.set(value, proxy);
|
|
110
111
|
return proxy;
|
|
111
112
|
}
|
|
@@ -121,8 +122,6 @@ function CreateProxyFactory(alias) {
|
|
|
121
122
|
return true;
|
|
122
123
|
}
|
|
123
124
|
function ArrayProxyGetter(array, prop) {
|
|
124
|
-
if (prop === exports.IS_OBSERVABLE_NODE)
|
|
125
|
-
return true;
|
|
126
125
|
if (readOnly)
|
|
127
126
|
switch (prop) {
|
|
128
127
|
case "push":
|
|
@@ -136,6 +135,8 @@ function CreateProxyFactory(alias) {
|
|
|
136
135
|
throw `Object is readonly`;
|
|
137
136
|
}
|
|
138
137
|
switch (prop) {
|
|
138
|
+
case exports.IS_OBSERVABLE_NODE:
|
|
139
|
+
return true;
|
|
139
140
|
case exports.GET_TO_JSON:
|
|
140
141
|
return function () {
|
|
141
142
|
return ToJson(array);
|
|
@@ -211,9 +212,9 @@ function CreateProxyFactory(alias) {
|
|
|
211
212
|
return true;
|
|
212
213
|
}
|
|
213
214
|
function ObjectProxyGetter(object, prop) {
|
|
214
|
-
if (prop === exports.IS_OBSERVABLE_NODE)
|
|
215
|
-
return true;
|
|
216
215
|
switch (prop) {
|
|
216
|
+
case exports.IS_OBSERVABLE_NODE:
|
|
217
|
+
return true;
|
|
217
218
|
case exports.GET_TO_JSON:
|
|
218
219
|
return function () {
|
|
219
220
|
return ToJson(object);
|
|
@@ -226,11 +227,7 @@ function CreateProxyFactory(alias) {
|
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
function GetAccessorValue(parent, prop) {
|
|
229
|
-
|
|
230
|
-
if (leafScopes === undefined) {
|
|
231
|
-
leafScopes = {};
|
|
232
|
-
leafScopeCache.set(parent, leafScopes);
|
|
233
|
-
}
|
|
230
|
+
const leafScopes = leafScopeCache.get(parent);
|
|
234
231
|
leafScopes[prop] ??= observableScope_1.ObservableScope.Create(function () {
|
|
235
232
|
const value = parent[prop];
|
|
236
233
|
return CreateProxyFromValue(value);
|
|
@@ -24,6 +24,12 @@ export declare class ObservableScope<T> extends ObservableScopeWrapper<T> {
|
|
|
24
24
|
(): T | Promise<T>;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
interface ICalcFunction<T> {
|
|
28
|
+
getFunction: {
|
|
29
|
+
(): T;
|
|
30
|
+
};
|
|
31
|
+
value: T;
|
|
32
|
+
}
|
|
27
33
|
export interface IObservableScope<T> extends IDestroyable {
|
|
28
34
|
getFunction: {
|
|
29
35
|
(): T;
|
|
@@ -37,7 +43,10 @@ export interface IObservableScope<T> extends IDestroyable {
|
|
|
37
43
|
setCallback: EmitterCallback;
|
|
38
44
|
destroyed: boolean;
|
|
39
45
|
watchEmitters: Emitter[] | null;
|
|
46
|
+
watchEmittersSet: Set<Emitter> | null;
|
|
47
|
+
calcFunctions: ICalcFunction<any>[] | null;
|
|
40
48
|
}
|
|
49
|
+
export declare function CalcScope<T>(callback: () => T): T;
|
|
41
50
|
export declare namespace ObservableScope {
|
|
42
51
|
function Create<T>(valueFunction: {
|
|
43
52
|
(): T | Promise<T>;
|
|
@@ -51,3 +60,4 @@ export declare namespace ObservableScope {
|
|
|
51
60
|
function Update(scope: IObservableScope<any>): void;
|
|
52
61
|
function Destroy<T>(scope: IObservableScope<T>): void;
|
|
53
62
|
}
|
|
63
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObservableScope = exports.ObservableScopeWrapper = exports.ObservableScopeValue = void 0;
|
|
4
|
+
exports.CalcScope = CalcScope;
|
|
4
5
|
const emitter_1 = require("../../Utils/emitter");
|
|
5
6
|
const list_1 = require("../../Utils/list");
|
|
6
7
|
class ObservableScopeValue {
|
|
@@ -54,10 +55,22 @@ function WatchScope(scope) {
|
|
|
54
55
|
watchingScope = scope;
|
|
55
56
|
currentlyWatching = true;
|
|
56
57
|
const value = scope.getFunction();
|
|
58
|
+
watchingScope.watchEmittersSet = null;
|
|
57
59
|
watchingScope = parentScope;
|
|
58
60
|
currentlyWatching = parentWatching;
|
|
59
61
|
return value;
|
|
60
62
|
}
|
|
63
|
+
function CalcScope(callback) {
|
|
64
|
+
const value = callback();
|
|
65
|
+
if (currentlyWatching) {
|
|
66
|
+
watchingScope.calcFunctions ??= [];
|
|
67
|
+
watchingScope.calcFunctions.push({
|
|
68
|
+
getFunction: callback,
|
|
69
|
+
value
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
61
74
|
(function (ObservableScope) {
|
|
62
75
|
function Create(valueFunction) {
|
|
63
76
|
const scope = {
|
|
@@ -70,6 +83,8 @@ function WatchScope(scope) {
|
|
|
70
83
|
emitters: [],
|
|
71
84
|
destroyed: false,
|
|
72
85
|
watchEmitters: null,
|
|
86
|
+
watchEmittersSet: null,
|
|
87
|
+
calcFunctions: null,
|
|
73
88
|
setCallback: function () {
|
|
74
89
|
return OnSet(scope);
|
|
75
90
|
},
|
|
@@ -81,7 +96,12 @@ function WatchScope(scope) {
|
|
|
81
96
|
if (!currentlyWatching)
|
|
82
97
|
return;
|
|
83
98
|
watchingScope.watchEmitters ??= [];
|
|
84
|
-
watchingScope.watchEmitters.
|
|
99
|
+
if (watchingScope.watchEmitters.length === 10)
|
|
100
|
+
watchingScope.watchEmittersSet = new Set(watchingScope.watchEmitters);
|
|
101
|
+
if ((watchingScope.watchEmittersSet === null && !watchingScope.watchEmitters.includes(emitter)) || (watchingScope.watchEmittersSet !== null && !watchingScope.watchEmittersSet.has(emitter))) {
|
|
102
|
+
watchingScope.watchEmittersSet?.add(emitter);
|
|
103
|
+
watchingScope.watchEmitters.push(emitter);
|
|
104
|
+
}
|
|
85
105
|
}
|
|
86
106
|
ObservableScope.Register = Register;
|
|
87
107
|
function Value(scope) {
|
|
@@ -142,9 +162,15 @@ function QueueScopeUpdate(scope) {
|
|
|
142
162
|
if (updateScopeQueue.size === 1)
|
|
143
163
|
queueMicrotask(ProcessScopeUpdateQueue);
|
|
144
164
|
}
|
|
165
|
+
function CalcChanged(calc) {
|
|
166
|
+
const value = calc.getFunction();
|
|
167
|
+
const changed = calc.value !== value;
|
|
168
|
+
calc.value = value;
|
|
169
|
+
return changed;
|
|
170
|
+
}
|
|
145
171
|
function DirtyScope(scope) {
|
|
146
|
-
scope.dirty =
|
|
147
|
-
scope.async ? QueueScopeUpdate(scope) : emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
172
|
+
scope.dirty = scope.calcFunctions === null || scope.calcFunctions.some(CalcChanged);
|
|
173
|
+
scope.dirty && (scope.async ? QueueScopeUpdate(scope) : emitter_1.Emitter.Emit(scope.emitter, scope));
|
|
148
174
|
}
|
|
149
175
|
function OnSet(scope) {
|
|
150
176
|
if (!scope || scope.dirty || scope.destroyed)
|
|
@@ -157,6 +183,7 @@ function UpdateValue(scope) {
|
|
|
157
183
|
return;
|
|
158
184
|
scope.dirty = false;
|
|
159
185
|
scope.watchEmitters = null;
|
|
186
|
+
scope.calcFunctions = null;
|
|
160
187
|
const value = WatchScope(scope);
|
|
161
188
|
if (scope.async) {
|
|
162
189
|
scope.promise = value.then(function (result) {
|
|
@@ -169,27 +196,45 @@ function UpdateValue(scope) {
|
|
|
169
196
|
UpdateEmitters(scope);
|
|
170
197
|
}
|
|
171
198
|
function UpdateEmitters(scope) {
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
199
|
+
const right = scope.watchEmitters;
|
|
200
|
+
if (right === null) {
|
|
201
|
+
if (scope.emitters.length > 0) {
|
|
202
|
+
for (let x = 0; x < scope.emitters.length; x++)
|
|
203
|
+
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
204
|
+
scope.emitters = [];
|
|
205
|
+
}
|
|
177
206
|
return;
|
|
178
207
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
for (
|
|
184
|
-
|
|
185
|
-
|
|
208
|
+
emitter_1.Emitter.Sort(right);
|
|
209
|
+
const left = scope.emitters;
|
|
210
|
+
let leftIndex = 0;
|
|
211
|
+
let rightIndex = 0;
|
|
212
|
+
for (; leftIndex < left.length; leftIndex++) {
|
|
213
|
+
let y = rightIndex;
|
|
214
|
+
for (; y < right.length && left[leftIndex] !== right[y]; y++)
|
|
215
|
+
emitter_1.Emitter.On(right[rightIndex], scope.setCallback);
|
|
216
|
+
if (y === right.length)
|
|
217
|
+
emitter_1.Emitter.Remove(left[leftIndex], scope.setCallback);
|
|
218
|
+
else {
|
|
219
|
+
for (let x = rightIndex; x < y; x++)
|
|
220
|
+
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
221
|
+
rightIndex = y + 1;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (; rightIndex < right.length; rightIndex++)
|
|
225
|
+
emitter_1.Emitter.On(right[rightIndex], scope.setCallback);
|
|
226
|
+
scope.emitters = right;
|
|
186
227
|
}
|
|
187
228
|
function DestroyScope(scope) {
|
|
188
229
|
if (!scope)
|
|
189
230
|
return;
|
|
231
|
+
const emitters = scope.emitters;
|
|
190
232
|
scope.emitters = null;
|
|
191
233
|
scope.emitter = null;
|
|
192
234
|
scope.getFunction = null;
|
|
193
235
|
scope.setCallback = null;
|
|
236
|
+
scope.calcFunctions = null;
|
|
194
237
|
scope.destroyed = true;
|
|
238
|
+
for (let x = 0; x < emitters.length; x++)
|
|
239
|
+
emitter_1.Emitter.Remove(emitters[x], scope.setCallback);
|
|
195
240
|
}
|
package/Utils/emitter.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export type EmitterCallback<T extends readonly any[] = any[]> = (...args: T) => boolean | void;
|
|
2
|
-
export type Emitter = Array<EmitterCallback | null
|
|
2
|
+
export type Emitter = Array<EmitterCallback | null> & {
|
|
3
|
+
_id: number;
|
|
4
|
+
};
|
|
3
5
|
export declare namespace Emitter {
|
|
4
6
|
function Create(): Emitter;
|
|
5
7
|
function On(emitter: Emitter, callback: EmitterCallback): void;
|
|
6
8
|
function Emit(emitter: Emitter, ...args: any[]): void;
|
|
7
9
|
function Remove(emitter: Emitter, callback: EmitterCallback): void;
|
|
8
10
|
function Clear(emitter: Emitter): void;
|
|
11
|
+
function Sort(emitters: Emitter[]): Emitter[];
|
|
9
12
|
}
|
package/Utils/emitter.js
CHANGED
|
@@ -4,8 +4,11 @@ exports.Emitter = void 0;
|
|
|
4
4
|
const array_1 = require("./array");
|
|
5
5
|
var Emitter;
|
|
6
6
|
(function (Emitter) {
|
|
7
|
+
let globalId = 0;
|
|
7
8
|
function Create() {
|
|
8
|
-
|
|
9
|
+
const emitter = [];
|
|
10
|
+
emitter._id = globalId++;
|
|
11
|
+
return emitter;
|
|
9
12
|
}
|
|
10
13
|
Emitter.Create = Create;
|
|
11
14
|
function On(emitter, callback) {
|
|
@@ -34,4 +37,11 @@ var Emitter;
|
|
|
34
37
|
emitter.splice(0);
|
|
35
38
|
}
|
|
36
39
|
Emitter.Clear = Clear;
|
|
40
|
+
function Sort(emitters) {
|
|
41
|
+
return emitters.sort(Compare);
|
|
42
|
+
}
|
|
43
|
+
Emitter.Sort = Sort;
|
|
44
|
+
function Compare(a, b) {
|
|
45
|
+
return a._id - b._id;
|
|
46
|
+
}
|
|
37
47
|
})(Emitter || (exports.Emitter = Emitter = {}));
|
package/Utils/list.js
CHANGED
|
@@ -5,13 +5,25 @@ var List;
|
|
|
5
5
|
(function (List) {
|
|
6
6
|
let maxTempListSize = 0;
|
|
7
7
|
let trimScheduled = false;
|
|
8
|
-
let idleCallback;
|
|
9
8
|
const tempList = Create();
|
|
10
9
|
function CreateNode(data) {
|
|
11
10
|
const node = PopNode(tempList) ?? { previous: null, next: null, data: null };
|
|
12
11
|
node.data = data;
|
|
13
12
|
return node;
|
|
14
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) {
|
|
23
|
+
trimScheduled = true;
|
|
24
|
+
requestIdleCallback(TrimTempList);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
function ReturnNode(node) {
|
|
16
28
|
if (!node)
|
|
17
29
|
return;
|
|
@@ -21,22 +33,6 @@ var List;
|
|
|
21
33
|
AddNode(tempList, node);
|
|
22
34
|
ScheduleTrimTempList();
|
|
23
35
|
}
|
|
24
|
-
function ScheduleTrimTempList() {
|
|
25
|
-
if (!trimScheduled) {
|
|
26
|
-
trimScheduled = true;
|
|
27
|
-
setTimeout(function () {
|
|
28
|
-
trimScheduled = false;
|
|
29
|
-
cancelIdleCallback(idleCallback);
|
|
30
|
-
idleCallback = requestIdleCallback(TrimTempList);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function TrimTempList() {
|
|
35
|
-
if (maxTempListSize < tempList.size)
|
|
36
|
-
maxTempListSize = tempList.size;
|
|
37
|
-
const trimSize = Math.floor(maxTempListSize / 10);
|
|
38
|
-
Split(tempList, trimSize);
|
|
39
|
-
}
|
|
40
36
|
function Create() {
|
|
41
37
|
return {
|
|
42
38
|
head: null,
|
|
@@ -235,15 +231,13 @@ var List;
|
|
|
235
231
|
List.Append = Append;
|
|
236
232
|
function ToNodeMap(list, keyCallback) {
|
|
237
233
|
const map = new Map();
|
|
238
|
-
let node = list.head;
|
|
239
|
-
while (node) {
|
|
234
|
+
for (let node = list.head; node !== null; node = node.next) {
|
|
240
235
|
const key = keyCallback(node.data);
|
|
241
|
-
const nodes = map.get(key)
|
|
242
|
-
if (nodes
|
|
243
|
-
|
|
236
|
+
const nodes = map.get(key);
|
|
237
|
+
if (nodes === undefined)
|
|
238
|
+
map.set(key, [node]);
|
|
244
239
|
else
|
|
245
|
-
|
|
246
|
-
node = node.next;
|
|
240
|
+
nodes[nodes.length] = node;
|
|
247
241
|
}
|
|
248
242
|
return map;
|
|
249
243
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Component = void 0;
|
|
3
|
+
exports.calc = exports.Component = void 0;
|
|
4
4
|
var component_1 = require("./Node/component");
|
|
5
5
|
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return component_1.Component; } });
|
|
6
|
+
var observableScope_1 = require("./Store/Tree/observableScope");
|
|
7
|
+
Object.defineProperty(exports, "calc", { enumerable: true, get: function () { return observableScope_1.CalcScope; } });
|