j-templates 5.0.38 → 5.0.40
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/domNodeConfig.js +2 -1
- package/DOM/elements.js +1 -0
- package/DOM/index.js +17 -6
- package/DOM/svgElements.js +1 -0
- package/DOM/utils.js +1 -0
- package/DOM/window.js +1 -0
- package/Node/boundNode.js +1 -0
- package/Node/boundNode.types.d.ts +2 -2
- package/Node/component.d.ts +1 -1
- package/Node/component.js +13 -7
- package/Node/componentNode.js +8 -7
- package/Node/componentNode.types.d.ts +2 -2
- package/Node/elementNode.js +7 -6
- package/Node/elementNode.types.d.ts +2 -2
- package/Node/nodeConfig.js +1 -0
- package/Node/nodeRef.js +1 -0
- package/Node/nodeRef.types.d.ts +1 -1
- package/Store/Diff/diffAsync.js +3 -1
- package/Store/Diff/diffSync.js +3 -1
- package/Store/Diff/diffTree.d.ts +1 -1
- package/Store/Diff/diffTree.js +3 -1
- package/Store/Diff/diffWorker.js +1 -0
- package/Store/Diff/workerQueue.js +3 -0
- package/Store/Store/store.js +7 -6
- package/Store/Store/storeAsync.js +6 -0
- package/Store/Store/storeAsyncWriter.js +4 -0
- package/Store/Store/storeSync.js +8 -7
- package/Store/Store/storeSyncWriter.js +3 -0
- package/Store/Store/storeWriter.js +2 -0
- package/Store/Tree/observableScope.js +6 -3
- package/Store/Tree/observableTree.js +50 -43
- package/Store/index.js +5 -4
- package/Utils/animation.js +22 -12
- package/Utils/asyncQueue.js +3 -4
- package/Utils/decorators.d.ts +1 -1
- package/Utils/decorators.js +1 -0
- package/Utils/emitter.d.ts +2 -2
- package/Utils/emitter.js +1 -0
- package/Utils/index.js +16 -5
- package/Utils/injector.js +3 -0
- package/Utils/list.js +1 -0
- package/Utils/router.js +13 -9
- package/Utils/thread.js +1 -0
- package/index.js +2 -1
- package/jTemplates.js +341 -366
- package/jTemplates.js.map +1 -1
- package/package.json +1 -1
- package/web.export.js +21 -9
package/DOM/domNodeConfig.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DOMNodeConfig = void 0;
|
|
3
4
|
const window_1 = require("./window");
|
|
4
5
|
const list_1 = require("../Utils/list");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
@@ -10,7 +11,7 @@ function processUpdates() {
|
|
|
10
11
|
list_1.List.Add(pendingUpdates, null);
|
|
11
12
|
var callback;
|
|
12
13
|
while ((callback = list_1.List.Pop(pendingUpdates)))
|
|
13
|
-
thread_1.Synch(callback);
|
|
14
|
+
(0, thread_1.Synch)(callback);
|
|
14
15
|
if (pendingUpdates.size === 0)
|
|
15
16
|
updateScheduled = false;
|
|
16
17
|
else
|
package/DOM/elements.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.td = exports.tr = exports.th = exports.table = exports.button = exports.style = exports.p = exports.h3 = exports.h2 = exports.h1 = exports.option = exports.select = exports.input = exports.source = exports.video = exports.img = exports.span = exports.b = exports.br = exports.li = exports.ul = exports.a = exports.div = void 0;
|
|
3
4
|
const elementNode_1 = require("../Node/elementNode");
|
|
4
5
|
function div(nodeDef, children) {
|
|
5
6
|
return elementNode_1.ElementNode.Create("div", null, nodeDef, children);
|
package/DOM/index.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
__exportStar(require("./elements"), exports);
|
|
18
|
+
__exportStar(require("./svgElements"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
package/DOM/svgElements.js
CHANGED
package/DOM/utils.js
CHANGED
package/DOM/window.js
CHANGED
package/Node/boundNode.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { NodeRefType } from "./nodeRef";
|
|
2
2
|
import { INodeRefBase } from "./nodeRef.types";
|
|
3
|
-
export
|
|
3
|
+
export type FunctionOr<T> = {
|
|
4
4
|
(...args: Array<any>): T | Promise<T>;
|
|
5
5
|
} | T;
|
|
6
|
-
export
|
|
6
|
+
export type NodeRefEvents = {
|
|
7
7
|
[name: string]: {
|
|
8
8
|
(...args: Array<any>): void;
|
|
9
9
|
};
|
package/Node/component.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare namespace Component {
|
|
|
27
27
|
function Register<D = void, T = void, E = void>(name: string, constructor: ComponentConstructor<D, T, E>): void;
|
|
28
28
|
function Attach(node: Node, nodeRef: NodeRefTypes): void;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type ComponentConstructor<D, T, E> = {
|
|
31
31
|
new (data: {
|
|
32
32
|
(): D | Promise<D>;
|
|
33
33
|
}, templates: T, nodeRef: INodeRefBase, componentEvents: ComponentNodeEvents<E>): Component<D, T, E>;
|
package/Node/component.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Component = void 0;
|
|
3
4
|
const nodeRef_1 = require("./nodeRef");
|
|
4
5
|
const componentNode_1 = require("./componentNode");
|
|
5
6
|
const decorators_1 = require("../Utils/decorators");
|
|
6
7
|
const observableScope_1 = require("../Store/Tree/observableScope");
|
|
7
8
|
class Component {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.decoratorMap = new Map();
|
|
14
|
-
}
|
|
9
|
+
nodeRef;
|
|
10
|
+
componentEvents;
|
|
11
|
+
scope;
|
|
12
|
+
templates;
|
|
13
|
+
decoratorMap;
|
|
15
14
|
get Injector() {
|
|
16
15
|
return this.nodeRef.injector;
|
|
17
16
|
}
|
|
@@ -33,6 +32,13 @@ class Component {
|
|
|
33
32
|
get Templates() {
|
|
34
33
|
return this.templates;
|
|
35
34
|
}
|
|
35
|
+
constructor(data, templates, nodeRef, componentEvents) {
|
|
36
|
+
this.nodeRef = nodeRef;
|
|
37
|
+
this.componentEvents = componentEvents;
|
|
38
|
+
this.scope = new observableScope_1.ObservableScope(data);
|
|
39
|
+
this.templates = templates || {};
|
|
40
|
+
this.decoratorMap = new Map();
|
|
41
|
+
}
|
|
36
42
|
Template() {
|
|
37
43
|
return [];
|
|
38
44
|
}
|
package/Node/componentNode.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentNode = void 0;
|
|
3
4
|
const boundNode_1 = require("./boundNode");
|
|
4
5
|
const nodeRef_1 = require("./nodeRef");
|
|
5
6
|
const nodeConfig_1 = require("./nodeConfig");
|
|
@@ -49,15 +50,15 @@ function SetChildren(node) {
|
|
|
49
50
|
}
|
|
50
51
|
function AddPreReqTemplate(node) {
|
|
51
52
|
return new Promise(resolve => {
|
|
52
|
-
thread_1.Thread(function () {
|
|
53
|
+
(0, thread_1.Thread)(function () {
|
|
53
54
|
var preNodes;
|
|
54
55
|
injector_1.Injector.Scope(node.injector, () => preNodes = decorators_1.PreReqTemplate.Get(node.component));
|
|
55
|
-
thread_1.Schedule(function () {
|
|
56
|
+
(0, thread_1.Schedule)(function () {
|
|
56
57
|
if (node.destroyed)
|
|
57
58
|
return;
|
|
58
59
|
nodeRef_1.NodeRef.InitAll(preNodes);
|
|
59
60
|
});
|
|
60
|
-
thread_1.Thread(function () {
|
|
61
|
+
(0, thread_1.Thread)(function () {
|
|
61
62
|
if (node.destroyed)
|
|
62
63
|
return;
|
|
63
64
|
for (var x = 0; x < preNodes.length; x++)
|
|
@@ -80,7 +81,7 @@ function AddPreReqTemplate(node) {
|
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
function AddTemplate(node, init) {
|
|
83
|
-
thread_1.Thread(function () {
|
|
84
|
+
(0, thread_1.Thread)(function () {
|
|
84
85
|
if (node.destroyed)
|
|
85
86
|
return;
|
|
86
87
|
var nodes;
|
|
@@ -89,10 +90,10 @@ function AddTemplate(node, init) {
|
|
|
89
90
|
});
|
|
90
91
|
if (!Array.isArray(nodes))
|
|
91
92
|
nodes = [nodes];
|
|
92
|
-
thread_1.Schedule(function () {
|
|
93
|
+
(0, thread_1.Schedule)(function () {
|
|
93
94
|
nodeRef_1.NodeRef.InitAll(nodes);
|
|
94
95
|
});
|
|
95
|
-
thread_1.Thread(function () {
|
|
96
|
+
(0, thread_1.Thread)(function () {
|
|
96
97
|
if (node.destroyed)
|
|
97
98
|
return;
|
|
98
99
|
if (init)
|
|
@@ -107,7 +108,7 @@ function AddTemplate(node, init) {
|
|
|
107
108
|
});
|
|
108
109
|
});
|
|
109
110
|
if (node.component.Bound !== component_1.Component.prototype.Bound)
|
|
110
|
-
thread_1.After(function () {
|
|
111
|
+
(0, thread_1.After)(function () {
|
|
111
112
|
nodeConfig_1.NodeConfig.scheduleUpdate(() => setTimeout(() => node.component.Bound(), 0));
|
|
112
113
|
});
|
|
113
114
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BoundNodeFunctionParam, IBoundNodeBase, NodeDefinition } from "./boundNode.types";
|
|
2
2
|
import { Component, ComponentConstructor } from "./component";
|
|
3
3
|
import { NodeRefType } from "./nodeRef";
|
|
4
|
-
export
|
|
4
|
+
export type ComponentNodeEvents<E = void> = {
|
|
5
5
|
[P in keyof E]: {
|
|
6
6
|
(data?: E[P]): void;
|
|
7
7
|
};
|
|
@@ -18,7 +18,7 @@ export interface ComponentNodeFunctionParam<D = void, E = void> extends BoundNod
|
|
|
18
18
|
(): D | Promise<D>;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type ComponentNodeFunction<D = void, T = void, E = void> = (nodeDef: ComponentNodeFunctionParam<D, E>, templates?: T) => IComponentNode<D, T, E>;
|
|
22
22
|
export interface IComponentNodeBase<D, T, E> extends IBoundNodeBase {
|
|
23
23
|
nodeDef: ComponentNodeFunctionParam<D, E>;
|
|
24
24
|
constructor: ComponentConstructor<D, T, E>;
|
package/Node/elementNode.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElementNode = void 0;
|
|
3
4
|
const boundNode_1 = require("./boundNode");
|
|
4
5
|
const nodeConfig_1 = require("./nodeConfig");
|
|
5
6
|
const injector_1 = require("../Utils/injector");
|
|
@@ -59,18 +60,18 @@ function ScheduleSetData(node, scope) {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
function SetDefaultData(node) {
|
|
62
|
-
thread_1.Synch(function () {
|
|
63
|
+
(0, thread_1.Synch)(function () {
|
|
63
64
|
var nodes;
|
|
64
65
|
injector_1.Injector.Scope(node.injector, function () {
|
|
65
66
|
nodes = CreateNodeArray(node.childrenFunc, true);
|
|
66
67
|
});
|
|
67
68
|
if (nodes.length > 0) {
|
|
68
|
-
thread_1.Schedule(function () {
|
|
69
|
+
(0, thread_1.Schedule)(function () {
|
|
69
70
|
if (node.destroyed)
|
|
70
71
|
return;
|
|
71
72
|
nodeRef_1.NodeRef.InitAll(nodes);
|
|
72
73
|
});
|
|
73
|
-
thread_1.Thread(function () {
|
|
74
|
+
(0, thread_1.Thread)(function () {
|
|
74
75
|
if (node.destroyed)
|
|
75
76
|
return;
|
|
76
77
|
DetachAndAddNodes(node, [], [nodes]);
|
|
@@ -79,7 +80,7 @@ function SetDefaultData(node) {
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
function SetData(node, value, init = false) {
|
|
82
|
-
thread_1.Synch(function () {
|
|
83
|
+
(0, thread_1.Synch)(function () {
|
|
83
84
|
var newNodesMap = new Map();
|
|
84
85
|
var values = value || valueDefault;
|
|
85
86
|
if (!Array.isArray(values))
|
|
@@ -99,7 +100,7 @@ function SetData(node, value, init = false) {
|
|
|
99
100
|
injector_1.Injector.Scope(node.injector, function () {
|
|
100
101
|
nodes = CreateNodeArray(node.childrenFunc, value);
|
|
101
102
|
});
|
|
102
|
-
thread_1.Schedule(function () {
|
|
103
|
+
(0, thread_1.Schedule)(function () {
|
|
103
104
|
if (node.destroyed || newNodesMap.size === 0)
|
|
104
105
|
return;
|
|
105
106
|
nodeRef_1.NodeRef.InitAll(nodes);
|
|
@@ -117,7 +118,7 @@ function SetData(node, value, init = false) {
|
|
|
117
118
|
node.nodesMap.clear();
|
|
118
119
|
}
|
|
119
120
|
node.nodesMap = newNodesMap;
|
|
120
|
-
thread_1.Thread(function () {
|
|
121
|
+
(0, thread_1.Thread)(function () {
|
|
121
122
|
if (node.destroyed)
|
|
122
123
|
return;
|
|
123
124
|
if (init)
|
|
@@ -15,10 +15,10 @@ export interface ElementNodeFunctionParam<T> extends BoundNodeFunctionParam {
|
|
|
15
15
|
(): T | Array<T> | Promise<Array<T>> | Promise<T>;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type ElementChildrenFunction<T> = {
|
|
19
19
|
(data?: T): string | NodeRefTypes | NodeRefTypes[];
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type ElementNodeFunction<T> = {
|
|
22
22
|
(nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunction<T>): INodeRefBase;
|
|
23
23
|
};
|
|
24
24
|
export interface IElementNodeBase<T> extends IBoundNodeBase {
|
package/Node/nodeConfig.js
CHANGED
package/Node/nodeRef.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeRef = exports.NodeRefType = void 0;
|
|
3
4
|
const nodeConfig_1 = require("./nodeConfig");
|
|
4
5
|
const injector_1 = require("../Utils/injector");
|
|
5
6
|
const boundNode_1 = require("./boundNode");
|
package/Node/nodeRef.types.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export interface INodeRefBase {
|
|
|
18
18
|
export interface INodeRef extends INodeRefBase {
|
|
19
19
|
type: NodeRefType.NodeRef;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type NodeRefTypes = INodeRef | IBoundNode | IElementNode<any> | IComponentNode<any, any, any>;
|
package/Store/Diff/diffAsync.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffAsync = void 0;
|
|
3
4
|
const diffTree_1 = require("./diffTree");
|
|
4
5
|
const workerQueue_1 = require("./workerQueue");
|
|
5
6
|
const diffWorker_1 = require("./diffWorker");
|
|
6
|
-
const diffCnstr = diffTree_1.DiffTreeScope();
|
|
7
|
+
const diffCnstr = (0, diffTree_1.DiffTreeScope)();
|
|
7
8
|
class DiffAsync {
|
|
9
|
+
workerQueue;
|
|
8
10
|
constructor(keyFunc) {
|
|
9
11
|
this.workerQueue = new workerQueue_1.WorkerQueue(diffWorker_1.DiffWorker.Create());
|
|
10
12
|
this.workerQueue.Push({ method: "create", arguments: [keyFunc.toString()] });
|
package/Store/Diff/diffSync.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffSync = void 0;
|
|
3
4
|
const diffTree_1 = require("./diffTree");
|
|
4
|
-
const diffCnstr = diffTree_1.DiffTreeScope();
|
|
5
|
+
const diffCnstr = (0, diffTree_1.DiffTreeScope)();
|
|
5
6
|
class DiffSync {
|
|
7
|
+
diffTree;
|
|
6
8
|
constructor(keyFunc) {
|
|
7
9
|
this.diffTree = new diffCnstr(keyFunc);
|
|
8
10
|
}
|
package/Store/Diff/diffTree.d.ts
CHANGED
package/Store/Diff/diffTree.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffTreeScope = void 0;
|
|
3
4
|
function DiffTreeScope(worker) {
|
|
4
5
|
const ctx = this;
|
|
5
6
|
if (ctx && worker) {
|
|
@@ -38,9 +39,10 @@ function DiffTreeScope(worker) {
|
|
|
38
39
|
return !(jsonConstructor === value.constructor || Array.isArray(value));
|
|
39
40
|
}
|
|
40
41
|
class DiffTree {
|
|
42
|
+
keyFunc;
|
|
43
|
+
rootStateMap = new Map();
|
|
41
44
|
constructor(keyFunc) {
|
|
42
45
|
this.keyFunc = keyFunc;
|
|
43
|
-
this.rootStateMap = new Map();
|
|
44
46
|
}
|
|
45
47
|
static GetKeyRef(key) {
|
|
46
48
|
return `___DiffTreeKeyRef.${key}`;
|
package/Store/Diff/diffWorker.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerQueue = void 0;
|
|
3
4
|
const list_1 = require("../../Utils/list");
|
|
4
5
|
class WorkerQueue {
|
|
6
|
+
callbacks;
|
|
7
|
+
worker;
|
|
5
8
|
constructor(worker) {
|
|
6
9
|
this.worker = worker;
|
|
7
10
|
this.callbacks = list_1.List.Create();
|
package/Store/Store/store.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Store = void 0;
|
|
3
4
|
const observableTree_1 = require("../Tree/observableTree");
|
|
4
5
|
const storeWriter_1 = require("./storeWriter");
|
|
5
6
|
class Store {
|
|
7
|
+
observableTree = new observableTree_1.ObservableTree();
|
|
8
|
+
storeWriter = new storeWriter_1.StoreWriter(this.observableTree);
|
|
9
|
+
rootScope = this.observableTree.Scope("ROOT", root => root);
|
|
10
|
+
get Root() {
|
|
11
|
+
return this.rootScope;
|
|
12
|
+
}
|
|
6
13
|
constructor(init) {
|
|
7
|
-
this.observableTree = new observableTree_1.ObservableTree();
|
|
8
|
-
this.storeWriter = new storeWriter_1.StoreWriter(this.observableTree);
|
|
9
|
-
this.rootScope = this.observableTree.Scope("ROOT", root => root);
|
|
10
14
|
if (init)
|
|
11
15
|
this.Write(init);
|
|
12
16
|
}
|
|
13
|
-
get Root() {
|
|
14
|
-
return this.rootScope;
|
|
15
|
-
}
|
|
16
17
|
Action(action) {
|
|
17
18
|
var proxy = this.observableTree.Get("ROOT");
|
|
18
19
|
action(proxy, this.storeWriter);
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreAsync = void 0;
|
|
3
4
|
const observableTree_1 = require("../Tree/observableTree");
|
|
4
5
|
const diffAsync_1 = require("../Diff/diffAsync");
|
|
5
6
|
const storeAsyncWriter_1 = require("./storeAsyncWriter");
|
|
6
7
|
const asyncQueue_1 = require("../../Utils/asyncQueue");
|
|
7
8
|
class StoreAsync {
|
|
9
|
+
idFunc;
|
|
10
|
+
diffAsync;
|
|
11
|
+
observableTree;
|
|
12
|
+
asyncWriter;
|
|
13
|
+
asyncQueue;
|
|
8
14
|
constructor(idFunc, init) {
|
|
9
15
|
this.idFunc = idFunc;
|
|
10
16
|
this.diffAsync = new diffAsync_1.DiffAsync(this.idFunc);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreAsyncWriter = void 0;
|
|
3
4
|
class StoreAsyncWriter {
|
|
5
|
+
idFunc;
|
|
6
|
+
diffAsync;
|
|
7
|
+
observableTree;
|
|
4
8
|
constructor(idFunc, diffAsync, observableTree) {
|
|
5
9
|
this.idFunc = idFunc;
|
|
6
10
|
this.diffAsync = diffAsync;
|
package/Store/Store/storeSync.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreSync = void 0;
|
|
3
4
|
const diffSync_1 = require("../Diff/diffSync");
|
|
4
5
|
const observableTree_1 = require("../Tree/observableTree");
|
|
5
6
|
const storeSyncWriter_1 = require("./storeSyncWriter");
|
|
6
7
|
class StoreSync {
|
|
8
|
+
diffSync = new diffSync_1.DiffSync();
|
|
9
|
+
observableTree = new observableTree_1.ObservableTree();
|
|
10
|
+
storeWriter = new storeSyncWriter_1.StoreSyncWriter(this.diffSync, this.observableTree);
|
|
11
|
+
rootScope = this.observableTree.Scope("ROOT", root => root);
|
|
12
|
+
get Root() {
|
|
13
|
+
return this.rootScope;
|
|
14
|
+
}
|
|
7
15
|
constructor(init) {
|
|
8
|
-
this.diffSync = new diffSync_1.DiffSync();
|
|
9
|
-
this.observableTree = new observableTree_1.ObservableTree();
|
|
10
|
-
this.storeWriter = new storeSyncWriter_1.StoreSyncWriter(this.diffSync, this.observableTree);
|
|
11
|
-
this.rootScope = this.observableTree.Scope("ROOT", root => root);
|
|
12
16
|
if (init)
|
|
13
17
|
this.Write(init);
|
|
14
18
|
}
|
|
15
|
-
get Root() {
|
|
16
|
-
return this.rootScope;
|
|
17
|
-
}
|
|
18
19
|
Action(action) {
|
|
19
20
|
var proxy = this.observableTree.Get("ROOT");
|
|
20
21
|
action(proxy, this.storeWriter);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreSyncWriter = void 0;
|
|
3
4
|
class StoreSyncWriter {
|
|
5
|
+
diffSync;
|
|
6
|
+
observableTree;
|
|
4
7
|
constructor(diffSync, observableTree) {
|
|
5
8
|
this.diffSync = diffSync;
|
|
6
9
|
this.observableTree = observableTree;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObservableScope = exports.ObservableScopeWrapper = exports.ObservableScopeValue = void 0;
|
|
3
4
|
const emitter_1 = require("../../Utils/emitter");
|
|
4
5
|
class ObservableScopeValue {
|
|
5
|
-
|
|
6
|
-
this.scope = scope;
|
|
7
|
-
}
|
|
6
|
+
scope;
|
|
8
7
|
get Value() {
|
|
9
8
|
return ObservableScope.Value(this.scope);
|
|
10
9
|
}
|
|
10
|
+
constructor(scope) {
|
|
11
|
+
this.scope = scope;
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
exports.ObservableScopeValue = ObservableScopeValue;
|
|
13
15
|
class ObservableScopeWrapper extends ObservableScopeValue {
|
|
16
|
+
scopeEmitter;
|
|
14
17
|
constructor(scope) {
|
|
15
18
|
super(scope);
|
|
16
19
|
if (scope.emitter) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObservableTree = void 0;
|
|
3
4
|
const observableScope_1 = require("../Tree/observableScope");
|
|
4
5
|
var Type;
|
|
5
6
|
(function (Type) {
|
|
@@ -18,50 +19,15 @@ function TypeOf(value) {
|
|
|
18
19
|
return Type.Value;
|
|
19
20
|
}
|
|
20
21
|
class ObservableTree {
|
|
22
|
+
valuePathResolver;
|
|
23
|
+
undefinedScope = observableScope_1.ObservableScope.Create(function () { return undefined; });
|
|
24
|
+
scopeCache = new WeakMap();
|
|
25
|
+
leafScopeCache = new WeakMap();
|
|
26
|
+
proxyCache = new WeakMap();
|
|
27
|
+
pathCache = new WeakMap();
|
|
28
|
+
rootStateMap = new Map();
|
|
21
29
|
constructor(valuePathResolver) {
|
|
22
30
|
this.valuePathResolver = valuePathResolver;
|
|
23
|
-
this.undefinedScope = observableScope_1.ObservableScope.Create(function () { return undefined; });
|
|
24
|
-
this.scopeCache = new WeakMap();
|
|
25
|
-
this.leafScopeCache = new WeakMap();
|
|
26
|
-
this.proxyCache = new WeakMap();
|
|
27
|
-
this.pathCache = new WeakMap();
|
|
28
|
-
this.rootStateMap = new Map();
|
|
29
|
-
this.ObjectProxyGetter = (value, prop) => {
|
|
30
|
-
function toJSON() {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
;
|
|
34
|
-
switch (prop) {
|
|
35
|
-
case "toJSON":
|
|
36
|
-
return toJSON;
|
|
37
|
-
default:
|
|
38
|
-
if (typeof prop === 'symbol')
|
|
39
|
-
return value[prop];
|
|
40
|
-
return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
this.ArrayProxyGetter = (value, prop) => {
|
|
44
|
-
function toJSON() {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
;
|
|
48
|
-
switch (prop) {
|
|
49
|
-
case "toJSON":
|
|
50
|
-
return toJSON;
|
|
51
|
-
default:
|
|
52
|
-
if (typeof prop === 'symbol')
|
|
53
|
-
return value[prop];
|
|
54
|
-
if (isNaN(parseInt(prop))) {
|
|
55
|
-
const ret = value[prop];
|
|
56
|
-
if (typeof ret === 'function') {
|
|
57
|
-
const copy = value.map((val, index) => observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, index.toString())));
|
|
58
|
-
return ret.bind(copy);
|
|
59
|
-
}
|
|
60
|
-
return ret;
|
|
61
|
-
}
|
|
62
|
-
return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
31
|
}
|
|
66
32
|
Get(path) {
|
|
67
33
|
const val = path.split(".").reduce((pre, curr, index) => {
|
|
@@ -157,11 +123,47 @@ class ObservableTree {
|
|
|
157
123
|
}
|
|
158
124
|
return proxy;
|
|
159
125
|
}
|
|
126
|
+
ObjectProxyGetter = (value, prop) => {
|
|
127
|
+
function toJSON() {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
;
|
|
131
|
+
switch (prop) {
|
|
132
|
+
case "toJSON":
|
|
133
|
+
return toJSON;
|
|
134
|
+
default:
|
|
135
|
+
if (typeof prop === 'symbol')
|
|
136
|
+
return value[prop];
|
|
137
|
+
return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
160
140
|
CreateObjectProxy(value) {
|
|
161
141
|
return new Proxy(value, {
|
|
162
142
|
get: this.ObjectProxyGetter
|
|
163
143
|
});
|
|
164
144
|
}
|
|
145
|
+
ArrayProxyGetter = (value, prop) => {
|
|
146
|
+
function toJSON() {
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
;
|
|
150
|
+
switch (prop) {
|
|
151
|
+
case "toJSON":
|
|
152
|
+
return toJSON;
|
|
153
|
+
default:
|
|
154
|
+
if (typeof prop === 'symbol')
|
|
155
|
+
return value[prop];
|
|
156
|
+
if (isNaN(parseInt(prop))) {
|
|
157
|
+
const ret = value[prop];
|
|
158
|
+
if (typeof ret === 'function') {
|
|
159
|
+
const copy = value.map((val, index) => observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, index.toString())));
|
|
160
|
+
return ret.bind(copy);
|
|
161
|
+
}
|
|
162
|
+
return ret;
|
|
163
|
+
}
|
|
164
|
+
return observableScope_1.ObservableScope.Value(this.GetPropertyScope(value, prop));
|
|
165
|
+
}
|
|
166
|
+
};
|
|
165
167
|
CreateArrayProxy(value) {
|
|
166
168
|
return new Proxy(value, {
|
|
167
169
|
get: this.ArrayProxyGetter
|
|
@@ -197,8 +199,13 @@ class ObservableTree {
|
|
|
197
199
|
if (!parentValue)
|
|
198
200
|
throw new Error("Unable to write path: " + path + ". Falsey value found at: " + pathParts.slice(0, x).join("."));
|
|
199
201
|
const prop = pathParts[x];
|
|
202
|
+
const oldValue = parentValue[prop];
|
|
203
|
+
const oldType = TypeOf(oldValue);
|
|
200
204
|
parentValue[prop] = value;
|
|
201
|
-
|
|
205
|
+
if (oldType !== Type.Value)
|
|
206
|
+
return this.scopeCache.get(oldValue) ||
|
|
207
|
+
this.scopeCache.get(parentValue);
|
|
208
|
+
const leafScopes = Object.hasOwn(parentValue, prop) && this.leafScopeCache.get(parentValue);
|
|
202
209
|
return leafScopes && leafScopes[prop] || this.scopeCache.get(parentValue);
|
|
203
210
|
}
|
|
204
211
|
UpdatePathCache(path, value) {
|