j-templates 6.0.25 → 6.0.26
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/createAssignment.d.ts +3 -0
- package/DOM/createAssignment.js +21 -0
- package/DOM/createEventAssignment.d.ts +1 -3
- package/DOM/createEventAssignment.js +9 -24
- package/DOM/createPropertyAssignment.d.ts +2 -4
- package/DOM/createPropertyAssignment.js +23 -59
- package/DOM/domNodeConfig.js +7 -3
- package/Node/boundNode.js +79 -18
- package/Node/boundNode.types.d.ts +8 -2
- package/Node/component.d.ts +1 -3
- package/Node/component.js +4 -1
- package/Node/elementNode.js +2 -2
- package/Node/nodeConfig.d.ts +3 -0
- package/Node/nodeRef.js +5 -2
- package/Store/Tree/observableScope.d.ts +4 -2
- package/Store/Tree/observableScope.js +55 -58
- package/Utils/decorators.js +10 -8
- package/jTemplates.js +1 -1
- package/jTemplates.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateAssignment = CreateAssignment;
|
|
4
|
+
function CreateAssignment(target, createAssignment) {
|
|
5
|
+
let last;
|
|
6
|
+
let writeTo;
|
|
7
|
+
return function AssignNext(next) {
|
|
8
|
+
if (next === last)
|
|
9
|
+
return;
|
|
10
|
+
last = next;
|
|
11
|
+
writeTo ??= {};
|
|
12
|
+
const nextKeys = next && Object.keys(next);
|
|
13
|
+
for (let x = 0; nextKeys && x < nextKeys.length; x++) {
|
|
14
|
+
const key = nextKeys[x];
|
|
15
|
+
writeTo[key] ??= createAssignment(target, key);
|
|
16
|
+
}
|
|
17
|
+
const writeKeys = Object.keys(writeTo);
|
|
18
|
+
for (let x = 0; x < writeKeys.length; x++)
|
|
19
|
+
writeTo[writeKeys[x]](next);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateEventAssignment = CreateEventAssignment;
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
return function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
function DefaultAssignment(target, writeTo, next, event) {
|
|
15
|
-
const value = next;
|
|
16
|
-
writeTo[event] ??= AssignEvent(target, event);
|
|
17
|
-
writeTo[event](value);
|
|
18
|
-
}
|
|
19
|
-
function CreateEventAssignment(target) {
|
|
20
|
-
let priorKeys;
|
|
21
|
-
const writeTo = {};
|
|
22
|
-
return function AssignNext(next) {
|
|
23
|
-
const nextKeys = next !== null ? Object.keys(next) : [];
|
|
24
|
-
const keys = priorKeys === undefined ? nextKeys : nextKeys.concat(priorKeys);
|
|
25
|
-
priorKeys = nextKeys;
|
|
26
|
-
for (let x = 0; x < keys.length; x++)
|
|
27
|
-
DefaultAssignment(target, writeTo, next && next[keys[x]], keys[x]);
|
|
4
|
+
function CreateEventAssignment(target, event) {
|
|
5
|
+
let lastEvent;
|
|
6
|
+
return function (next) {
|
|
7
|
+
const nextEvent = next && next[event];
|
|
8
|
+
if (nextEvent === lastEvent)
|
|
9
|
+
return;
|
|
10
|
+
lastEvent && target.removeEventListener(event, lastEvent);
|
|
11
|
+
nextEvent && target.addEventListener(event, nextEvent);
|
|
12
|
+
lastEvent = nextEvent;
|
|
28
13
|
};
|
|
29
14
|
}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export declare function CreateNodeValueAssignment(target: HTMLElement): (value:
|
|
2
|
-
|
|
3
|
-
}) => void;
|
|
4
|
-
export declare function CreatePropertyAssignment(target: any, root?: boolean): (next: any) => void;
|
|
1
|
+
export declare function CreateNodeValueAssignment(target: HTMLElement): (value: string) => void;
|
|
2
|
+
export declare function CreatePropertyAssignment(target: any, prop: string): (next: any) => void;
|
|
@@ -3,85 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CreateNodeValueAssignment = CreateNodeValueAssignment;
|
|
4
4
|
exports.CreatePropertyAssignment = CreatePropertyAssignment;
|
|
5
5
|
const jsonType_1 = require("../Utils/jsonType");
|
|
6
|
-
|
|
7
|
-
let lastValue = target[prop];
|
|
8
|
-
return function Assign(value) {
|
|
9
|
-
if (value !== lastValue) {
|
|
10
|
-
target[prop] = value;
|
|
11
|
-
lastValue = value;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
6
|
+
const createAssignment_1 = require("./createAssignment");
|
|
15
7
|
function CreateNodeValueAssignment(target) {
|
|
16
8
|
let lastValue = target.nodeValue;
|
|
17
9
|
return function AssignNodeValue(value) {
|
|
18
|
-
if (value.nodeValue !== lastValue) {
|
|
19
|
-
target.nodeValue = value.nodeValue;
|
|
20
|
-
lastValue = value.nodeValue;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function CreateValueAssignment(target) {
|
|
25
|
-
let lastValue = target.value;
|
|
26
|
-
target.addEventListener('blur', function () {
|
|
27
|
-
target.value = lastValue;
|
|
28
|
-
});
|
|
29
|
-
return function AssignValue(value) {
|
|
30
10
|
if (value !== lastValue) {
|
|
31
|
-
|
|
32
|
-
const end = target.selectionEnd;
|
|
33
|
-
target.value = value;
|
|
34
|
-
if (target.ownerDocument.activeElement === target)
|
|
35
|
-
target.setSelectionRange(start, end);
|
|
11
|
+
target.nodeValue = value;
|
|
36
12
|
lastValue = value;
|
|
37
13
|
}
|
|
38
14
|
};
|
|
39
15
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
writeTo[prop] ??= (0, jsonType_1.JsonType)(value) === 'value' ?
|
|
47
|
-
AssignProp(target, prop) :
|
|
48
|
-
CreatePropertyAssignment(target[prop], false);
|
|
49
|
-
writeTo[prop](value);
|
|
16
|
+
function AssignValue(target, value) {
|
|
17
|
+
const start = target.selectionStart;
|
|
18
|
+
const end = target.selectionEnd;
|
|
19
|
+
target.value = value;
|
|
20
|
+
if (target.ownerDocument.activeElement === target)
|
|
21
|
+
target.setSelectionRange(start, end);
|
|
50
22
|
}
|
|
51
|
-
function
|
|
23
|
+
function CreatePropertyAssignment(target, prop) {
|
|
52
24
|
let lastValue;
|
|
53
25
|
let childPropertyAssignment;
|
|
54
26
|
return function (next) {
|
|
55
27
|
const nextValue = next && next[prop];
|
|
56
28
|
if (nextValue === lastValue)
|
|
57
29
|
return;
|
|
30
|
+
lastValue = nextValue;
|
|
31
|
+
if (childPropertyAssignment !== undefined)
|
|
32
|
+
childPropertyAssignment(target[prop], nextValue);
|
|
58
33
|
const nextValueType = (0, jsonType_1.JsonType)(nextValue);
|
|
59
34
|
switch (nextValueType) {
|
|
60
35
|
case "value":
|
|
61
|
-
|
|
36
|
+
switch (prop) {
|
|
37
|
+
case "value":
|
|
38
|
+
AssignValue(target, nextValue || "");
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
target[prop] = nextValue;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
62
45
|
default:
|
|
63
|
-
childPropertyAssignment ??=
|
|
46
|
+
childPropertyAssignment ??= (0, createAssignment_1.CreateAssignment)(target[prop], CreatePropertyAssignment);
|
|
64
47
|
childPropertyAssignment(target[prop], nextValue);
|
|
48
|
+
break;
|
|
65
49
|
}
|
|
66
50
|
};
|
|
67
51
|
}
|
|
68
|
-
function CreatePropertyAssignment(target, root = true) {
|
|
69
|
-
let last;
|
|
70
|
-
let writeTo;
|
|
71
|
-
return function AssignNext(next) {
|
|
72
|
-
if (next === last)
|
|
73
|
-
return;
|
|
74
|
-
last = next;
|
|
75
|
-
writeTo ??= {};
|
|
76
|
-
const nextKeys = next && Object.keys(next);
|
|
77
|
-
for (let x = 0; nextKeys && x < nextKeys.length; x++) {
|
|
78
|
-
const key = nextKeys[x];
|
|
79
|
-
if (writeTo[key] === undefined) {
|
|
80
|
-
writeTo[key] = CreateAssignProp(target, key);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const writeKeys = Object.keys(writeTo);
|
|
84
|
-
for (let x = 0; x < writeKeys.length; x++)
|
|
85
|
-
writeTo[writeKeys[x]](next);
|
|
86
|
-
};
|
|
87
|
-
}
|
package/DOM/domNodeConfig.js
CHANGED
|
@@ -5,6 +5,7 @@ const window_1 = require("./window");
|
|
|
5
5
|
const list_1 = require("../Utils/list");
|
|
6
6
|
const createPropertyAssignment_1 = require("./createPropertyAssignment");
|
|
7
7
|
const createEventAssignment_1 = require("./createEventAssignment");
|
|
8
|
+
const createAssignment_1 = require("./createAssignment");
|
|
8
9
|
let pendingUpdates = list_1.List.Create();
|
|
9
10
|
let updateScheduled = false;
|
|
10
11
|
const updateMs = 16;
|
|
@@ -70,8 +71,11 @@ exports.DOMNodeConfig = {
|
|
|
70
71
|
remove(target) {
|
|
71
72
|
target && target.parentNode && target.parentNode.removeChild(target);
|
|
72
73
|
},
|
|
74
|
+
createTextAssignment(target) {
|
|
75
|
+
return (0, createPropertyAssignment_1.CreateNodeValueAssignment)(target);
|
|
76
|
+
},
|
|
73
77
|
setText(target, text) {
|
|
74
|
-
target.
|
|
78
|
+
target.nodeValue = text;
|
|
75
79
|
},
|
|
76
80
|
getAttribute(target, attribute) {
|
|
77
81
|
return target.getAttribute(attribute);
|
|
@@ -82,10 +86,10 @@ exports.DOMNodeConfig = {
|
|
|
82
86
|
createPropertyAssignment(target) {
|
|
83
87
|
if (target.nodeType === Node.TEXT_NODE)
|
|
84
88
|
return (0, createPropertyAssignment_1.CreateNodeValueAssignment)(target);
|
|
85
|
-
return (0,
|
|
89
|
+
return (0, createAssignment_1.CreateAssignment)(target, createPropertyAssignment_1.CreatePropertyAssignment);
|
|
86
90
|
},
|
|
87
91
|
createEventAssignment(target) {
|
|
88
|
-
return (0,
|
|
92
|
+
return (0, createAssignment_1.CreateAssignment)(target, createEventAssignment_1.CreateEventAssignment);
|
|
89
93
|
},
|
|
90
94
|
fireEvent(target, event, data) {
|
|
91
95
|
var cEvent = new CustomEvent(event, data);
|
package/Node/boundNode.js
CHANGED
|
@@ -5,36 +5,97 @@ const nodeConfig_1 = require("./nodeConfig");
|
|
|
5
5
|
const observableScope_1 = require("../Store/Tree/observableScope");
|
|
6
6
|
var BoundNode;
|
|
7
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 (...args) {
|
|
15
|
+
if (node.destroyed)
|
|
16
|
+
return;
|
|
17
|
+
return eventFunc(...args);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return ret;
|
|
21
|
+
}
|
|
8
22
|
function Init(boundNode) {
|
|
9
23
|
const nodeDef = boundNode.nodeDef;
|
|
10
24
|
if (nodeDef.props) {
|
|
11
|
-
const scope = observableScope_1.ObservableScope.Create(nodeDef.props);
|
|
12
|
-
boundNode.scopes ??= [];
|
|
13
|
-
boundNode.scopes.push(scope);
|
|
14
25
|
boundNode.assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(boundNode.node);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|
|
18
38
|
}
|
|
19
39
|
if (nodeDef.attrs) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
49
|
}
|
|
26
50
|
if (nodeDef.on) {
|
|
27
|
-
const scope = observableScope_1.ObservableScope.Create(nodeDef.on);
|
|
28
|
-
boundNode.scopes ??= [];
|
|
29
|
-
boundNode.scopes.push(scope);
|
|
30
51
|
boundNode.assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(boundNode.node);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
if (nodeDef.text) {
|
|
70
|
+
boundNode.assignText = nodeConfig_1.NodeConfig.createTextAssignment(boundNode.node);
|
|
71
|
+
if (typeof nodeDef.text === 'function') {
|
|
72
|
+
const scope = observableScope_1.ObservableScope.Create(nodeDef.text);
|
|
73
|
+
boundNode.scopes ??= [];
|
|
74
|
+
boundNode.scopes.push(scope);
|
|
75
|
+
observableScope_1.ObservableScope.Watch(scope, function (scope) { ScheduleSetText(boundNode, scope); });
|
|
76
|
+
const next = observableScope_1.ObservableScope.Value(scope);
|
|
77
|
+
boundNode.assignText(next);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
boundNode.assignText(nodeDef.text);
|
|
81
|
+
boundNode.assignText = null;
|
|
82
|
+
}
|
|
34
83
|
}
|
|
35
84
|
}
|
|
36
85
|
BoundNode.Init = Init;
|
|
37
86
|
})(BoundNode || (exports.BoundNode = BoundNode = {}));
|
|
87
|
+
function ScheduleSetText(node, scope) {
|
|
88
|
+
if (node.setText)
|
|
89
|
+
return;
|
|
90
|
+
node.setText = true;
|
|
91
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
92
|
+
node.setText = false;
|
|
93
|
+
if (node.destroyed)
|
|
94
|
+
return;
|
|
95
|
+
const next = observableScope_1.ObservableScope.Value(scope);
|
|
96
|
+
node.assignText(next);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
38
99
|
function ScheduleSetProperties(node, scope) {
|
|
39
100
|
if (node.setProperties)
|
|
40
101
|
return;
|
|
@@ -44,7 +105,7 @@ function ScheduleSetProperties(node, scope) {
|
|
|
44
105
|
if (node.destroyed)
|
|
45
106
|
return;
|
|
46
107
|
const next = observableScope_1.ObservableScope.Value(scope);
|
|
47
|
-
node.assignProperties(next);
|
|
108
|
+
node.assignProperties(next || null);
|
|
48
109
|
});
|
|
49
110
|
}
|
|
50
111
|
function ScheduleSetAttributes(node, scope) {
|
|
@@ -13,21 +13,23 @@ export interface NodeDefinition<T = any, E = any> {
|
|
|
13
13
|
type: any;
|
|
14
14
|
namespace: string;
|
|
15
15
|
props?: FunctionOr<{
|
|
16
|
-
[name: string]:
|
|
16
|
+
[name: string]: unknown;
|
|
17
17
|
}>;
|
|
18
18
|
attrs?: FunctionOr<{
|
|
19
19
|
[name: string]: string;
|
|
20
20
|
}>;
|
|
21
21
|
on?: FunctionOr<NodeRefEvents>;
|
|
22
|
+
text?: FunctionOr<string>;
|
|
22
23
|
}
|
|
23
24
|
export interface BoundNodeFunctionParam {
|
|
24
25
|
props?: FunctionOr<{
|
|
25
|
-
[name: string]:
|
|
26
|
+
[name: string]: unknown;
|
|
26
27
|
}>;
|
|
27
28
|
attrs?: FunctionOr<{
|
|
28
29
|
[name: string]: string;
|
|
29
30
|
}>;
|
|
30
31
|
on?: FunctionOr<NodeRefEvents>;
|
|
32
|
+
text?: FunctionOr<string>;
|
|
31
33
|
}
|
|
32
34
|
export interface IBoundNodeBase extends INodeRefBase {
|
|
33
35
|
nodeDef: BoundNodeFunctionParam;
|
|
@@ -41,8 +43,12 @@ export interface IBoundNodeBase extends INodeRefBase {
|
|
|
41
43
|
[event: string]: (event: Event) => void;
|
|
42
44
|
}): void;
|
|
43
45
|
};
|
|
46
|
+
assignText: {
|
|
47
|
+
(next: string): void;
|
|
48
|
+
};
|
|
44
49
|
setAttributes: boolean;
|
|
45
50
|
setEvents: boolean;
|
|
51
|
+
setText: boolean;
|
|
46
52
|
}
|
|
47
53
|
export interface IBoundNode extends IBoundNodeBase {
|
|
48
54
|
type: NodeRefType.BoundNode;
|
package/Node/component.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ export declare class Component<D = void, T = void, E = void> {
|
|
|
12
12
|
protected get Data(): D;
|
|
13
13
|
protected get NodeRef(): INodeRefBase;
|
|
14
14
|
protected get Templates(): T;
|
|
15
|
-
constructor(data: D |
|
|
16
|
-
(): D | Promise<D>;
|
|
17
|
-
}, templates: T, nodeRef: INodeRefBase, componentEvents: ComponentNodeEvents<E>);
|
|
15
|
+
constructor(data: D | (() => (D | Promise<D>)), templates: T, nodeRef: INodeRefBase, componentEvents: ComponentNodeEvents<E>);
|
|
18
16
|
Template(): NodeRefTypes | NodeRefTypes[];
|
|
19
17
|
Bound(): void;
|
|
20
18
|
Fire<P extends keyof E>(event: P, data?: E[P]): void;
|
package/Node/component.js
CHANGED
|
@@ -27,7 +27,10 @@ class Component {
|
|
|
27
27
|
constructor(data, templates, nodeRef, componentEvents) {
|
|
28
28
|
this.nodeRef = nodeRef;
|
|
29
29
|
this.componentEvents = componentEvents;
|
|
30
|
-
|
|
30
|
+
if (typeof data === 'function')
|
|
31
|
+
this.scope = new observableScope_1.ObservableScope(data);
|
|
32
|
+
else
|
|
33
|
+
this.scope = new observableScope_1.ObservableScope(() => data);
|
|
31
34
|
this.templates = templates || {};
|
|
32
35
|
}
|
|
33
36
|
Template() {
|
package/Node/elementNode.js
CHANGED
|
@@ -155,8 +155,8 @@ function CreateNodeArray(childrenFunc, value) {
|
|
|
155
155
|
if (typeof newNodes === "string" || !newNodes) {
|
|
156
156
|
const textNode = nodeRef_1.NodeRef.Create("text", null, nodeRef_1.NodeRefType.BoundNode);
|
|
157
157
|
textNode.nodeDef = {
|
|
158
|
-
|
|
159
|
-
return
|
|
158
|
+
text: function () {
|
|
159
|
+
return childrenFunc(value);
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
return [textNode];
|
package/Node/nodeConfig.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export interface INodeConfig {
|
|
|
18
18
|
removeChild(root: any, child: any): void;
|
|
19
19
|
remove(target: any): void;
|
|
20
20
|
fireEvent(target: any, event: string, data: any): void;
|
|
21
|
+
createTextAssignment(target: any): {
|
|
22
|
+
(next: string): void;
|
|
23
|
+
};
|
|
21
24
|
createPropertyAssignment(target: any): {
|
|
22
25
|
(next: any): void;
|
|
23
26
|
};
|
package/Node/nodeRef.js
CHANGED
|
@@ -51,8 +51,10 @@ var NodeRef;
|
|
|
51
51
|
setProperties: false,
|
|
52
52
|
assignProperties: null,
|
|
53
53
|
assignEvents: null,
|
|
54
|
+
assignText: null,
|
|
54
55
|
setAttributes: false,
|
|
55
56
|
setEvents: false,
|
|
57
|
+
setText: false,
|
|
56
58
|
scopes: null
|
|
57
59
|
};
|
|
58
60
|
case NodeRefType.ElementNode:
|
|
@@ -70,11 +72,13 @@ var NodeRef;
|
|
|
70
72
|
setProperties: false,
|
|
71
73
|
assignProperties: null,
|
|
72
74
|
assignEvents: null,
|
|
75
|
+
assignText: null,
|
|
73
76
|
setAttributes: false,
|
|
74
77
|
setEvents: false,
|
|
75
78
|
childrenFunc: null,
|
|
76
79
|
nodeList: null,
|
|
77
80
|
setData: false,
|
|
81
|
+
setText: false,
|
|
78
82
|
scopes: null
|
|
79
83
|
};
|
|
80
84
|
case NodeRefType.ComponentNode:
|
|
@@ -201,9 +205,8 @@ var NodeRef;
|
|
|
201
205
|
switch (node.type) {
|
|
202
206
|
case NodeRefType.ComponentNode:
|
|
203
207
|
node.component?.Destroy();
|
|
204
|
-
case NodeRefType.ElementNode:
|
|
205
|
-
node.assignEvents?.(null);
|
|
206
208
|
case NodeRefType.BoundNode:
|
|
209
|
+
case NodeRefType.ElementNode:
|
|
207
210
|
for (let x = 0; node.scopes && x < node.scopes.length; x++)
|
|
208
211
|
Store_1.ObservableScope.Destroy(node.scopes[x]);
|
|
209
212
|
}
|
|
@@ -20,7 +20,7 @@ export declare class ObservableScopeWrapper<T> extends ObservableScopeValue<T> i
|
|
|
20
20
|
Destroy(): void;
|
|
21
21
|
}
|
|
22
22
|
export declare class ObservableScope<T> extends ObservableScopeWrapper<T> {
|
|
23
|
-
constructor(getFunction:
|
|
23
|
+
constructor(getFunction: {
|
|
24
24
|
(): T | Promise<T>;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
@@ -36,11 +36,13 @@ export interface IObservableScope<T> extends IDestroyable {
|
|
|
36
36
|
setCallback: EmitterCallback;
|
|
37
37
|
destroyed: boolean;
|
|
38
38
|
calc: any[] | null;
|
|
39
|
+
watchSet: Set<Emitter> | null;
|
|
40
|
+
watchCalc: any[] | null;
|
|
39
41
|
}
|
|
40
42
|
export declare namespace ObservableScope {
|
|
41
43
|
function Create<T>(valueFunction: {
|
|
42
44
|
(): T | Promise<T>;
|
|
43
|
-
}
|
|
45
|
+
}): IObservableScope<T>;
|
|
44
46
|
function Register(emitter: Emitter): void;
|
|
45
47
|
function Calc<T>(value: T): T;
|
|
46
48
|
function Value<T>(scope: IObservableScope<T>): T;
|
|
@@ -46,57 +46,50 @@ class ObservableScope extends ObservableScopeWrapper {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
exports.ObservableScope = ObservableScope;
|
|
49
|
-
let
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const lastSet = currentSet;
|
|
61
|
-
const lastCalc = currentCalc;
|
|
62
|
-
currentSet = parentSet;
|
|
63
|
-
currentCalc = parentCalc;
|
|
64
|
-
watching = parentWatching;
|
|
65
|
-
return [lastSet, lastCalc];
|
|
49
|
+
let currentScope = null;
|
|
50
|
+
let currentWatching = false;
|
|
51
|
+
function WatchScope(scope) {
|
|
52
|
+
const parentScope = currentScope;
|
|
53
|
+
const parentWatching = currentWatching;
|
|
54
|
+
currentScope = scope;
|
|
55
|
+
currentWatching = true;
|
|
56
|
+
const value = scope.getFunction();
|
|
57
|
+
currentScope = parentScope;
|
|
58
|
+
currentWatching = parentWatching;
|
|
59
|
+
return value;
|
|
66
60
|
}
|
|
67
61
|
(function (ObservableScope) {
|
|
68
62
|
function Create(valueFunction) {
|
|
69
|
-
const hasFunction = typeof valueFunction === "function";
|
|
70
63
|
const scope = {
|
|
71
|
-
getFunction:
|
|
72
|
-
value:
|
|
73
|
-
async:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
dirty: hasFunction,
|
|
77
|
-
emitter: hasFunction ? emitter_1.Emitter.Create() : null,
|
|
64
|
+
getFunction: valueFunction,
|
|
65
|
+
value: null,
|
|
66
|
+
async: valueFunction[Symbol.toStringTag] === "AsyncFunction",
|
|
67
|
+
dirty: true,
|
|
68
|
+
emitter: emitter_1.Emitter.Create(),
|
|
78
69
|
emitters: [],
|
|
79
70
|
destroyed: false,
|
|
80
71
|
calc: null,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
72
|
+
watchSet: null,
|
|
73
|
+
watchCalc: null,
|
|
74
|
+
setCallback: function () {
|
|
75
|
+
return OnSet(scope);
|
|
76
|
+
},
|
|
86
77
|
};
|
|
87
78
|
return scope;
|
|
88
79
|
}
|
|
89
80
|
ObservableScope.Create = Create;
|
|
90
81
|
function Register(emitter) {
|
|
91
|
-
if (!
|
|
82
|
+
if (!currentWatching)
|
|
92
83
|
return;
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
currentScope.watchSet ??= new Set();
|
|
85
|
+
currentScope.watchSet.add(emitter);
|
|
95
86
|
}
|
|
96
87
|
ObservableScope.Register = Register;
|
|
97
88
|
function Calc(value) {
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
if (!currentWatching)
|
|
90
|
+
return;
|
|
91
|
+
currentScope.watchCalc ??= [];
|
|
92
|
+
currentScope.watchCalc.push(value);
|
|
100
93
|
return value;
|
|
101
94
|
}
|
|
102
95
|
ObservableScope.Calc = Calc;
|
|
@@ -109,7 +102,7 @@ function WatchAction(action) {
|
|
|
109
102
|
}
|
|
110
103
|
ObservableScope.Value = Value;
|
|
111
104
|
function Watching() {
|
|
112
|
-
return
|
|
105
|
+
return currentWatching;
|
|
113
106
|
}
|
|
114
107
|
ObservableScope.Watching = Watching;
|
|
115
108
|
function Touch(scope) {
|
|
@@ -150,29 +143,24 @@ function UpdateValue(scope) {
|
|
|
150
143
|
if (!scope.dirty)
|
|
151
144
|
return;
|
|
152
145
|
scope.dirty = false;
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
scope.emitters = null;
|
|
170
|
-
scope.emitter = null;
|
|
171
|
-
scope.getFunction = null;
|
|
172
|
-
scope.setCallback = null;
|
|
173
|
-
scope.destroyed = true;
|
|
146
|
+
const value = WatchScope(scope);
|
|
147
|
+
const change = scope.watchCalc === null || (0, array_1.ArrayDiff)(scope.calc, scope.watchCalc);
|
|
148
|
+
scope.calc = scope.watchCalc;
|
|
149
|
+
if (change) {
|
|
150
|
+
if (scope.async)
|
|
151
|
+
Promise.resolve(value).then((val) => {
|
|
152
|
+
scope.value = val;
|
|
153
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
154
|
+
});
|
|
155
|
+
else
|
|
156
|
+
scope.value = value;
|
|
157
|
+
UpdateEmitters(scope);
|
|
158
|
+
}
|
|
159
|
+
scope.watchCalc = null;
|
|
160
|
+
scope.watchSet?.clear();
|
|
174
161
|
}
|
|
175
|
-
function UpdateEmitters(scope
|
|
162
|
+
function UpdateEmitters(scope) {
|
|
163
|
+
const newEmitters = scope.watchSet;
|
|
176
164
|
if (newEmitters === null) {
|
|
177
165
|
for (let x = 0; x < scope.emitters.length; x++)
|
|
178
166
|
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
@@ -193,3 +181,12 @@ function UpdateEmitters(scope, newEmitters) {
|
|
|
193
181
|
emitter_1.Emitter.On(scope.emitters[x], scope.setCallback);
|
|
194
182
|
removed && (0, array_1.RemoveNulls)(scope.emitters);
|
|
195
183
|
}
|
|
184
|
+
function DestroyScope(scope) {
|
|
185
|
+
if (!scope)
|
|
186
|
+
return;
|
|
187
|
+
scope.emitters = null;
|
|
188
|
+
scope.emitter = null;
|
|
189
|
+
scope.getFunction = null;
|
|
190
|
+
scope.setCallback = null;
|
|
191
|
+
scope.destroyed = true;
|
|
192
|
+
}
|