j-templates 5.0.53 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Node/component.d.ts +0 -2
- package/Node/component.js +2 -8
- package/Store/Diff/diffAsync.d.ts +9 -8
- package/Store/Diff/diffAsync.js +1 -15
- package/Store/Diff/diffSync.d.ts +4 -6
- package/Store/Diff/diffSync.js +4 -10
- package/Store/Diff/diffTree.d.ts +4 -10
- package/Store/Diff/diffTree.js +96 -189
- package/Store/Diff/diffWorker.js +5 -4
- package/Store/Store/store.d.ts +0 -14
- package/Store/Store/store.js +0 -31
- package/Store/Store/storeAsync.d.ts +0 -20
- package/Store/Store/storeAsync.js +0 -49
- package/Store/Store/storeAsyncWriter.d.ts +0 -15
- package/Store/Store/storeAsyncWriter.js +0 -52
- package/Store/Store/storeSync.d.ts +0 -15
- package/Store/Store/storeSync.js +0 -33
- package/Store/Store/storeSyncWriter.d.ts +0 -12
- package/Store/Store/storeSyncWriter.js +0 -41
- package/Store/Store/storeWriter.d.ts +0 -9
- package/Store/Store/storeWriter.js +0 -30
- package/Store/Tree/observableComputed.d.ts +0 -4
- package/Store/Tree/observableComputed.js +0 -45
- package/Store/Tree/observableNode.d.ts +2 -0
- package/Store/Tree/observableNode.js +186 -131
- package/Store/Tree/observableScope.js +16 -12
- package/Store/index.d.ts +0 -4
- package/Store/index.js +1 -9
- package/Utils/array.d.ts +1 -0
- package/Utils/array.js +15 -0
- package/Utils/decorators.d.ts +8 -8
- package/Utils/decorators.js +77 -165
- package/Utils/emitter.d.ts +2 -1
- package/Utils/emitter.js +20 -11
- package/Utils/json.d.ts +8 -3
- package/Utils/json.js +116 -96
- package/Utils/jsonDeepClone.d.ts +1 -0
- package/Utils/jsonDeepClone.js +20 -0
- package/Utils/router.d.ts +0 -23
- package/Utils/router.js +0 -116
- package/jTemplates.js +1 -1
- package/jTemplates.js.map +1 -1
- package/package.json +1 -1
- package/web.export.d.ts +1 -1
- package/web.export.js +1 -4
|
@@ -37,7 +37,7 @@ class ObservableScopeWrapper extends ObservableScopeValue {
|
|
|
37
37
|
}
|
|
38
38
|
Destroy() {
|
|
39
39
|
DestroyScope(this.scope);
|
|
40
|
-
this.scopeEmitter && this.scopeEmitter
|
|
40
|
+
this.scopeEmitter && emitter_1.Emitter.Clear(this.scopeEmitter);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.ObservableScopeWrapper = ObservableScopeWrapper;
|
|
@@ -62,19 +62,23 @@ function WatchAction(action) {
|
|
|
62
62
|
}
|
|
63
63
|
(function (ObservableScope) {
|
|
64
64
|
function Create(valueFunction, dependencies) {
|
|
65
|
-
const hasFunction = typeof valueFunction ===
|
|
65
|
+
const hasFunction = typeof valueFunction === "function";
|
|
66
66
|
const scope = {
|
|
67
67
|
getFunction: hasFunction ? valueFunction : null,
|
|
68
68
|
value: hasFunction ? null : valueFunction,
|
|
69
|
-
async: hasFunction
|
|
69
|
+
async: hasFunction
|
|
70
|
+
? valueFunction[Symbol.toStringTag] === "AsyncFunction"
|
|
71
|
+
: false,
|
|
70
72
|
dirty: hasFunction,
|
|
71
73
|
emitter: hasFunction ? emitter_1.Emitter.Create() : null,
|
|
72
74
|
emitters: null,
|
|
73
75
|
destroyed: false,
|
|
74
|
-
setCallback: hasFunction
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
setCallback: hasFunction
|
|
77
|
+
? function () {
|
|
78
|
+
return OnSet(scope);
|
|
79
|
+
}
|
|
80
|
+
: null,
|
|
81
|
+
dependencies,
|
|
78
82
|
};
|
|
79
83
|
return scope;
|
|
80
84
|
}
|
|
@@ -137,9 +141,9 @@ function UpdateValue(scope) {
|
|
|
137
141
|
return;
|
|
138
142
|
scope.dirty = false;
|
|
139
143
|
let value = null;
|
|
140
|
-
const emitters = scope.getFunction && WatchAction(() => value = scope.getFunction());
|
|
144
|
+
const emitters = scope.getFunction && WatchAction(() => (value = scope.getFunction()));
|
|
141
145
|
if (scope.async)
|
|
142
|
-
Promise.resolve(value).then(val => {
|
|
146
|
+
Promise.resolve(value).then((val) => {
|
|
143
147
|
scope.value = val;
|
|
144
148
|
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
145
149
|
});
|
|
@@ -154,19 +158,19 @@ function DestroyScope(scope) {
|
|
|
154
158
|
for (let x = 0; x < scope.dependencies.length; x++)
|
|
155
159
|
DestroyScope(scope.dependencies[x]);
|
|
156
160
|
scope.emitters && scope.emitters.clear();
|
|
157
|
-
scope.emitter && scope.emitter
|
|
161
|
+
scope.emitter && emitter_1.Emitter.Clear(scope.emitter);
|
|
158
162
|
scope.getFunction = null;
|
|
159
163
|
scope.setCallback = null;
|
|
160
164
|
scope.destroyed = true;
|
|
161
165
|
}
|
|
162
166
|
function UpdateEmitters(scope, newEmitters) {
|
|
163
167
|
if (newEmitters) {
|
|
164
|
-
newEmitters.forEach(e => {
|
|
168
|
+
newEmitters.forEach((e) => {
|
|
165
169
|
if (!scope.emitters?.delete(e))
|
|
166
170
|
emitter_1.Emitter.On(e, scope.setCallback);
|
|
167
171
|
});
|
|
168
172
|
}
|
|
169
173
|
if (scope.emitters)
|
|
170
|
-
scope.emitters.forEach(e => emitter_1.Emitter.Remove(e, scope.setCallback));
|
|
174
|
+
scope.emitters.forEach((e) => emitter_1.Emitter.Remove(e, scope.setCallback));
|
|
171
175
|
scope.emitters = newEmitters;
|
|
172
176
|
}
|
package/Store/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export { Store } from "./Store/store";
|
|
2
|
-
export { StoreSync } from "./Store/storeSync";
|
|
3
|
-
export { StoreAsync } from "./Store/storeAsync";
|
|
4
1
|
export { ObservableScope } from "./Tree/observableScope";
|
|
5
2
|
export { ObservableNode } from "./Tree/observableNode";
|
|
6
|
-
export { ObservableComputed } from './Tree/observableComputed';
|
package/Store/index.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var store_1 = require("./Store/store");
|
|
5
|
-
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return store_1.Store; } });
|
|
6
|
-
var storeSync_1 = require("./Store/storeSync");
|
|
7
|
-
Object.defineProperty(exports, "StoreSync", { enumerable: true, get: function () { return storeSync_1.StoreSync; } });
|
|
8
|
-
var storeAsync_1 = require("./Store/storeAsync");
|
|
9
|
-
Object.defineProperty(exports, "StoreAsync", { enumerable: true, get: function () { return storeAsync_1.StoreAsync; } });
|
|
3
|
+
exports.ObservableNode = exports.ObservableScope = void 0;
|
|
10
4
|
var observableScope_1 = require("./Tree/observableScope");
|
|
11
5
|
Object.defineProperty(exports, "ObservableScope", { enumerable: true, get: function () { return observableScope_1.ObservableScope; } });
|
|
12
6
|
var observableNode_1 = require("./Tree/observableNode");
|
|
13
7
|
Object.defineProperty(exports, "ObservableNode", { enumerable: true, get: function () { return observableNode_1.ObservableNode; } });
|
|
14
|
-
var observableComputed_1 = require("./Tree/observableComputed");
|
|
15
|
-
Object.defineProperty(exports, "ObservableComputed", { enumerable: true, get: function () { return observableComputed_1.ObservableComputed; } });
|
package/Utils/array.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function RemoveNulls(array: (unknown | null)[], startIndex?: number): void;
|
package/Utils/array.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoveNulls = RemoveNulls;
|
|
4
|
+
function RemoveNulls(array, startIndex = 0) {
|
|
5
|
+
let nullIndex = startIndex;
|
|
6
|
+
for (; nullIndex < array.length && array[nullIndex] !== null; nullIndex++) { }
|
|
7
|
+
let notNullIndex = nullIndex + 1;
|
|
8
|
+
while (notNullIndex < array.length) {
|
|
9
|
+
for (; notNullIndex < array.length && array[notNullIndex] === null; notNullIndex++) { }
|
|
10
|
+
array[nullIndex] = array[notNullIndex];
|
|
11
|
+
nullIndex++;
|
|
12
|
+
notNullIndex++;
|
|
13
|
+
}
|
|
14
|
+
array.splice(nullIndex);
|
|
15
|
+
}
|
package/Utils/decorators.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import { Component } from "../Node/component";
|
|
|
2
2
|
import { IDestroyable } from "./utils.types";
|
|
3
3
|
import { NodeRefTypes } from "../Node/nodeRef.types";
|
|
4
4
|
export declare function State(): any;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function StateAsync(): any;
|
|
5
|
+
export declare function Value(): any;
|
|
6
|
+
export declare function StateAsync(defaultValue: any, keyFunc?: (val: any) => string): any;
|
|
7
|
+
export declare function StateAsyncDecorator<T extends Component<any, any, any>, K extends string>(defaultValue: any, keyFunc: ((val: any) => string) | undefined, target: T, propertyKey: K): {
|
|
8
|
+
configurable: boolean;
|
|
9
|
+
enumerable: boolean;
|
|
10
|
+
get: (this: T) => any;
|
|
11
|
+
set: (this: T, val: any) => void;
|
|
12
|
+
};
|
|
7
13
|
export declare function Scope(): typeof ScopeDecorator;
|
|
8
14
|
declare function ScopeDecorator<T extends Component<any, any, any>, K extends string>(target: T, propertyKey: K, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
9
|
-
export declare function DestroyScope(): typeof DestroyScopeDecorator;
|
|
10
|
-
declare function DestroyScopeDecorator<T extends Component<any, any, any> & Record<K, IDestroyable>, K extends string>(target: T, propertyKey: K, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
11
|
-
export declare function Computed(): <T extends Component<any, any, any>, K extends string>(target: T, propertyKey: K, descriptor: PropertyDescriptor) => any;
|
|
12
|
-
export declare function ComputedAsync(idFunc?: {
|
|
13
|
-
(val: any): string;
|
|
14
|
-
}): <T extends Component<any, any, any>, K extends string>(target: T, propertyKey: K, descriptor: PropertyDescriptor) => any;
|
|
15
15
|
export declare function Inject<I>(type: {
|
|
16
16
|
new (...args: Array<any>): I;
|
|
17
17
|
}): <F extends I, T extends Component<any, any, any> & Record<K, F>, K extends string>(target: T, propertyKey: K, descriptor?: PropertyDescriptor) => any;
|
package/Utils/decorators.js
CHANGED
|
@@ -1,35 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.State = State;
|
|
4
|
-
exports.
|
|
4
|
+
exports.Value = Value;
|
|
5
5
|
exports.StateAsync = StateAsync;
|
|
6
|
+
exports.StateAsyncDecorator = StateAsyncDecorator;
|
|
6
7
|
exports.Scope = Scope;
|
|
7
|
-
exports.DestroyScope = DestroyScope;
|
|
8
|
-
exports.Computed = Computed;
|
|
9
|
-
exports.ComputedAsync = ComputedAsync;
|
|
10
8
|
exports.Inject = Inject;
|
|
11
9
|
exports.Destroy = Destroy;
|
|
12
10
|
exports.PreReqTemplate = PreReqTemplate;
|
|
13
11
|
exports.PreReq = PreReq;
|
|
14
|
-
const Store_1 = require("../Store");
|
|
15
12
|
const observableScope_1 = require("../Store/Tree/observableScope");
|
|
16
|
-
const observableTree_1 = require("../Store/Tree/observableTree");
|
|
17
13
|
const observableNode_1 = require("../Store/Tree/observableNode");
|
|
14
|
+
const diffAsync_1 = require("../Store/Diff/diffAsync");
|
|
15
|
+
const json_1 = require("./json");
|
|
16
|
+
const decoratorInstanceMap = new WeakMap();
|
|
17
|
+
const valueInstanceMap = new WeakMap();
|
|
18
|
+
function GetDecoratorMapForInstance(instance) {
|
|
19
|
+
const map = decoratorInstanceMap.get(instance) ?? new Map();
|
|
20
|
+
decoratorInstanceMap.set(instance, map);
|
|
21
|
+
return map;
|
|
22
|
+
}
|
|
23
|
+
function GetValueMapForInstance(instance) {
|
|
24
|
+
const map = valueInstanceMap.get(instance) ?? new Map();
|
|
25
|
+
valueInstanceMap.set(instance, map);
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
18
28
|
function State() {
|
|
19
29
|
return StateDecorator;
|
|
20
30
|
}
|
|
21
31
|
function StateDecorator(target, propertyKey) {
|
|
22
|
-
const propKey = `
|
|
32
|
+
const propKey = `StateDecorator_${propertyKey}`;
|
|
23
33
|
return {
|
|
24
34
|
configurable: false,
|
|
25
35
|
enumerable: true,
|
|
26
36
|
get: function () {
|
|
27
|
-
const map = this
|
|
37
|
+
const map = GetDecoratorMapForInstance(this);
|
|
28
38
|
const node = map.get(propKey);
|
|
29
39
|
return node;
|
|
30
40
|
},
|
|
31
41
|
set: function (val) {
|
|
32
|
-
const map = this
|
|
42
|
+
const map = GetDecoratorMapForInstance(this);
|
|
33
43
|
const node = map.get(propKey);
|
|
34
44
|
if (!node)
|
|
35
45
|
map.set(propKey, observableNode_1.ObservableNode.Create(val));
|
|
@@ -38,65 +48,77 @@ function StateDecorator(target, propertyKey) {
|
|
|
38
48
|
for (let x = 0; x < keys.length; x++)
|
|
39
49
|
node[keys[x]] = val[keys[x]];
|
|
40
50
|
}
|
|
41
|
-
}
|
|
51
|
+
},
|
|
42
52
|
};
|
|
43
53
|
}
|
|
44
|
-
function
|
|
45
|
-
return
|
|
54
|
+
function Value() {
|
|
55
|
+
return ValueDecorator;
|
|
46
56
|
}
|
|
47
|
-
function
|
|
48
|
-
const propKey = `
|
|
57
|
+
function ValueDecorator(target, propertyKey) {
|
|
58
|
+
const propKey = `ValueDecorator_${propertyKey}`;
|
|
49
59
|
return {
|
|
50
60
|
configurable: false,
|
|
51
61
|
enumerable: true,
|
|
52
62
|
get: function () {
|
|
53
|
-
const map = this
|
|
54
|
-
const
|
|
55
|
-
return
|
|
63
|
+
const map = GetDecoratorMapForInstance(this);
|
|
64
|
+
const scope = map.get(propKey);
|
|
65
|
+
return observableScope_1.ObservableScope.Value(scope);
|
|
56
66
|
},
|
|
57
67
|
set: function (val) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const valueMap = GetValueMapForInstance(this);
|
|
69
|
+
if (valueMap.get(propKey) === val)
|
|
70
|
+
return;
|
|
71
|
+
valueMap.set(propKey, val);
|
|
72
|
+
const map = GetDecoratorMapForInstance(this);
|
|
73
|
+
let scope = map.get(propKey);
|
|
74
|
+
if (scope === undefined) {
|
|
75
|
+
scope = observableScope_1.ObservableScope.Create(function () {
|
|
76
|
+
return valueMap.get(propKey);
|
|
77
|
+
});
|
|
78
|
+
map.set(propKey, scope);
|
|
66
79
|
}
|
|
67
|
-
|
|
80
|
+
else
|
|
81
|
+
observableScope_1.ObservableScope.Update(scope);
|
|
82
|
+
},
|
|
68
83
|
};
|
|
69
84
|
}
|
|
70
|
-
function StateAsync() {
|
|
71
|
-
return StateAsyncDecorator;
|
|
85
|
+
function StateAsync(defaultValue, keyFunc) {
|
|
86
|
+
return StateAsyncDecorator.bind(null, defaultValue, keyFunc);
|
|
72
87
|
}
|
|
73
|
-
function StateAsyncDecorator(target, propertyKey) {
|
|
74
|
-
const propKey = `
|
|
75
|
-
const
|
|
76
|
-
DestroyDecorator(target, propKey);
|
|
77
|
-
DestroyDecorator(target, scopeKey);
|
|
88
|
+
function StateAsyncDecorator(defaultValue, keyFunc, target, propertyKey) {
|
|
89
|
+
const propKey = `ValueDecorator_${propertyKey}`;
|
|
90
|
+
const treeKey = `ValueDecoratorTree_${propertyKey}`;
|
|
78
91
|
return {
|
|
79
92
|
configurable: false,
|
|
80
93
|
enumerable: true,
|
|
81
94
|
get: function () {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (observableScope_1.ObservableScope.Watching())
|
|
86
|
-
return value;
|
|
87
|
-
return observableTree_1.ObservableTree.UnwrapProxyValues(value);
|
|
95
|
+
const map = GetDecoratorMapForInstance(this);
|
|
96
|
+
const node = map.get(propKey);
|
|
97
|
+
return node?.root;
|
|
88
98
|
},
|
|
89
99
|
set: function (val) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!
|
|
93
|
-
|
|
94
|
-
map.set(propKey,
|
|
95
|
-
|
|
100
|
+
const map = GetDecoratorMapForInstance(this);
|
|
101
|
+
const node = map.get(propKey);
|
|
102
|
+
if (!node) {
|
|
103
|
+
const newNode = observableNode_1.ObservableNode.Create({ root: defaultValue });
|
|
104
|
+
map.set(propKey, newNode);
|
|
105
|
+
const newTree = new diffAsync_1.DiffAsync(keyFunc);
|
|
106
|
+
map.set(treeKey, newTree);
|
|
107
|
+
newTree.DiffPath("", val).then((result) => {
|
|
108
|
+
observableNode_1.ObservableNode.EnableDiff(false);
|
|
109
|
+
(0, json_1.ApplyDiff)(newNode, result);
|
|
110
|
+
observableNode_1.ObservableNode.EnableDiff(true);
|
|
111
|
+
});
|
|
96
112
|
}
|
|
97
|
-
else
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
else {
|
|
114
|
+
const tree = map.get(treeKey);
|
|
115
|
+
tree.DiffPath("", val).then((result) => {
|
|
116
|
+
observableNode_1.ObservableNode.EnableDiff(false);
|
|
117
|
+
(0, json_1.ApplyDiff)(node, result);
|
|
118
|
+
observableNode_1.ObservableNode.EnableDiff(true);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
100
122
|
};
|
|
101
123
|
}
|
|
102
124
|
function Scope() {
|
|
@@ -113,122 +135,15 @@ function ScopeDecorator(target, propertyKey, descriptor) {
|
|
|
113
135
|
configurable: false,
|
|
114
136
|
enumerable: true,
|
|
115
137
|
get: function () {
|
|
116
|
-
var map = this
|
|
117
|
-
var scope = map.get(propKey);
|
|
118
|
-
if (!scope) {
|
|
119
|
-
const getter = descriptor.get.bind(this);
|
|
120
|
-
scope = new observableScope_1.ObservableScope(getter);
|
|
121
|
-
map.set(propKey, scope);
|
|
122
|
-
}
|
|
123
|
-
return scope.Value;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function DestroyScope() {
|
|
128
|
-
return DestroyScopeDecorator;
|
|
129
|
-
}
|
|
130
|
-
function DestroyScopeDecorator(target, propertyKey, descriptor) {
|
|
131
|
-
if (!(descriptor && descriptor.get))
|
|
132
|
-
throw "Destroy Scope decorator requires a getter";
|
|
133
|
-
if (descriptor && descriptor.set)
|
|
134
|
-
throw "Destroy Scope decorator does not support setters";
|
|
135
|
-
const propKey = `ScopeDecorator_${propertyKey}`;
|
|
136
|
-
DestroyDecorator(target, propKey);
|
|
137
|
-
const valKey = `ScopeDecorator_${propertyKey}_Value`;
|
|
138
|
-
DestroyDecorator(target, valKey);
|
|
139
|
-
return {
|
|
140
|
-
configurable: false,
|
|
141
|
-
enumerable: true,
|
|
142
|
-
get: function () {
|
|
143
|
-
var map = this.DecoratorMap;
|
|
138
|
+
var map = GetDecoratorMapForInstance(this);
|
|
144
139
|
var scope = map.get(propKey);
|
|
145
140
|
if (!scope) {
|
|
146
141
|
const getter = descriptor.get.bind(this);
|
|
147
142
|
scope = new observableScope_1.ObservableScope(getter);
|
|
148
143
|
map.set(propKey, scope);
|
|
149
|
-
scope.Watch(scope => {
|
|
150
|
-
var lastValue = map.get(valKey);
|
|
151
|
-
lastValue && lastValue.Destroy();
|
|
152
|
-
map.set(valKey, scope.Value);
|
|
153
|
-
});
|
|
154
144
|
}
|
|
155
145
|
return scope.Value;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function Computed() {
|
|
160
|
-
return ComputedDecorator;
|
|
161
|
-
}
|
|
162
|
-
function ComputedDecorator(target, propertyKey, descriptor) {
|
|
163
|
-
if (!(descriptor && descriptor.get))
|
|
164
|
-
throw "Computed decorator requires a getter";
|
|
165
|
-
if (descriptor && descriptor.set)
|
|
166
|
-
throw "Computed decorator does not support setters";
|
|
167
|
-
const scopeKey = `ComputedDecorator_Scope_${propertyKey}`;
|
|
168
|
-
const storeKey = `ComputedDecorator_Store_${propertyKey}`;
|
|
169
|
-
DestroyDecorator(target, scopeKey);
|
|
170
|
-
DestroyDecorator(target, storeKey);
|
|
171
|
-
return {
|
|
172
|
-
configurable: false,
|
|
173
|
-
enumerable: true,
|
|
174
|
-
get: function () {
|
|
175
|
-
var map = this.DecoratorMap;
|
|
176
|
-
var store = map.get(storeKey);
|
|
177
|
-
if (!store) {
|
|
178
|
-
const getter = descriptor.get.bind(this);
|
|
179
|
-
const scope = new observableScope_1.ObservableScope(getter);
|
|
180
|
-
store = new Store_1.StoreSync(scope.Value);
|
|
181
|
-
scope.Watch(scope => {
|
|
182
|
-
if (!this.Destroyed)
|
|
183
|
-
store.Write(scope.Value);
|
|
184
|
-
});
|
|
185
|
-
map.set(scopeKey, scope);
|
|
186
|
-
map.set(storeKey, store);
|
|
187
|
-
}
|
|
188
|
-
return store.Root.Value;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function ComputedAsync(idFunc) {
|
|
193
|
-
return ComputedAsyncDecorator.bind(null, idFunc);
|
|
194
|
-
}
|
|
195
|
-
function ComputedAsyncDecorator(idFunc, target, propertyKey, descriptor) {
|
|
196
|
-
if (!(descriptor && descriptor.get))
|
|
197
|
-
throw "ComputedAsync decorator requires a getter";
|
|
198
|
-
if (descriptor && descriptor.set)
|
|
199
|
-
throw "ComputedAsync decorator does not support setters";
|
|
200
|
-
const scopeKey = `ComputedDecorator_Scope_${propertyKey}`;
|
|
201
|
-
const storeKey = `ComputedDecorator_Store_${propertyKey}`;
|
|
202
|
-
const storeScopeKey = `ComputedDecorator_StoreScope_${propertyKey}`;
|
|
203
|
-
DestroyDecorator(target, scopeKey);
|
|
204
|
-
DestroyDecorator(target, storeKey);
|
|
205
|
-
DestroyDecorator(target, storeScopeKey);
|
|
206
|
-
return {
|
|
207
|
-
configurable: false,
|
|
208
|
-
enumerable: true,
|
|
209
|
-
get: function () {
|
|
210
|
-
var map = this.DecoratorMap;
|
|
211
|
-
var storeScope = map.get(storeScopeKey);
|
|
212
|
-
if (!storeScope) {
|
|
213
|
-
const getter = descriptor.get.bind(this);
|
|
214
|
-
const scope = new observableScope_1.ObservableScope(() => {
|
|
215
|
-
var value = getter();
|
|
216
|
-
if (value && typeof value.toJSON === 'function')
|
|
217
|
-
value = value.toJSON();
|
|
218
|
-
return value;
|
|
219
|
-
});
|
|
220
|
-
const store = new Store_1.StoreAsync((val) => val._id, { _id: "ROOT", data: scope.Value });
|
|
221
|
-
scope.Watch(scope => {
|
|
222
|
-
if (!this.Destroyed)
|
|
223
|
-
store.Write({ _id: "ROOT", data: scope.Value });
|
|
224
|
-
});
|
|
225
|
-
storeScope = store.Scope("ROOT", (val) => val.data);
|
|
226
|
-
map.set(storeScopeKey, storeScope);
|
|
227
|
-
map.set(scopeKey, scope);
|
|
228
|
-
map.set(storeKey, store);
|
|
229
|
-
}
|
|
230
|
-
return storeScope.Value;
|
|
231
|
-
}
|
|
146
|
+
},
|
|
232
147
|
};
|
|
233
148
|
}
|
|
234
149
|
function Inject(type) {
|
|
@@ -243,7 +158,7 @@ function InjectorDecorator(type, target, propertyKey, descriptor) {
|
|
|
243
158
|
},
|
|
244
159
|
set: function (val) {
|
|
245
160
|
this.Injector.Set(type, val);
|
|
246
|
-
}
|
|
161
|
+
},
|
|
247
162
|
};
|
|
248
163
|
}
|
|
249
164
|
function Destroy() {
|
|
@@ -251,13 +166,9 @@ function Destroy() {
|
|
|
251
166
|
}
|
|
252
167
|
(function (Destroy) {
|
|
253
168
|
function Get(value) {
|
|
254
|
-
return value && value.DestroyDecorator_Destroys || [];
|
|
169
|
+
return (value && value.DestroyDecorator_Destroys) || [];
|
|
255
170
|
}
|
|
256
171
|
function All(value) {
|
|
257
|
-
var arr = Get(value);
|
|
258
|
-
arr.map(prop => (value[prop] || value.DecoratorMap.get(prop)))
|
|
259
|
-
.filter(o => !!o)
|
|
260
|
-
.forEach(o => o.Destroy());
|
|
261
172
|
}
|
|
262
173
|
Destroy.All = All;
|
|
263
174
|
})(Destroy || (exports.Destroy = Destroy = {}));
|
|
@@ -288,10 +199,11 @@ function PreReq() {
|
|
|
288
199
|
}
|
|
289
200
|
(function (PreReq) {
|
|
290
201
|
function Get(value) {
|
|
291
|
-
return value && value.PreReqDecorator_PreReqs || [];
|
|
202
|
+
return (value && value.PreReqDecorator_PreReqs) || [];
|
|
292
203
|
}
|
|
293
204
|
function All(value) {
|
|
294
|
-
var arr = Get(value).map((prop) => (value[prop] && value[prop].Init) ||
|
|
205
|
+
var arr = Get(value).map((prop) => (value[prop] && value[prop].Init) ||
|
|
206
|
+
Promise.resolve());
|
|
295
207
|
return Promise.all(arr);
|
|
296
208
|
}
|
|
297
209
|
PreReq.All = All;
|
package/Utils/emitter.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export type EmitterCallback<T extends readonly any[] = any[]> = (...args: T) => boolean | void;
|
|
2
|
-
export type Emitter =
|
|
2
|
+
export type Emitter = Array<EmitterCallback>;
|
|
3
3
|
export declare namespace Emitter {
|
|
4
4
|
function Create(): Emitter;
|
|
5
5
|
function On(emitter: Emitter, callback: EmitterCallback): void;
|
|
6
6
|
function Emit(emitter: Emitter, ...args: any[]): void;
|
|
7
7
|
function Remove(emitter: Emitter, callback: EmitterCallback): void;
|
|
8
|
+
function Clear(emitter: Emitter): void;
|
|
8
9
|
}
|
package/Utils/emitter.js
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Emitter = void 0;
|
|
4
|
+
const array_1 = require("./array");
|
|
4
5
|
var Emitter;
|
|
5
6
|
(function (Emitter) {
|
|
6
7
|
function Create() {
|
|
7
|
-
return
|
|
8
|
+
return [];
|
|
8
9
|
}
|
|
9
10
|
Emitter.Create = Create;
|
|
10
11
|
function On(emitter, callback) {
|
|
11
|
-
emitter.
|
|
12
|
+
emitter.push(callback);
|
|
12
13
|
}
|
|
13
14
|
Emitter.On = On;
|
|
14
15
|
function Emit(emitter, ...args) {
|
|
15
|
-
let
|
|
16
|
-
emitter.
|
|
17
|
-
const result =
|
|
16
|
+
let removed = false;
|
|
17
|
+
for (let x = 0; x < emitter.length; x++) {
|
|
18
|
+
const result = emitter[x]?.(...args);
|
|
18
19
|
if (result === true) {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
removed = true;
|
|
21
|
+
emitter[x] = null;
|
|
21
22
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
if (removed)
|
|
25
|
+
(0, array_1.RemoveNulls)(emitter);
|
|
25
26
|
}
|
|
26
27
|
Emitter.Emit = Emit;
|
|
27
28
|
function Remove(emitter, callback) {
|
|
28
|
-
emitter.
|
|
29
|
+
const index = emitter.indexOf(callback);
|
|
30
|
+
if (index >= 0) {
|
|
31
|
+
emitter[index] = null;
|
|
32
|
+
(0, array_1.RemoveNulls)(emitter, index);
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
Emitter.Remove = Remove;
|
|
36
|
+
function Clear(emitter) {
|
|
37
|
+
emitter.splice(0);
|
|
38
|
+
}
|
|
39
|
+
Emitter.Clear = Clear;
|
|
31
40
|
})(Emitter || (exports.Emitter = Emitter = {}));
|
package/Utils/json.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ export type JsonDiffResult<T = unknown> = {
|
|
|
2
2
|
path: (string | number)[];
|
|
3
3
|
value: unknown;
|
|
4
4
|
}[];
|
|
5
|
-
export
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
5
|
+
export type JsonDiffFactoryResult = ReturnType<typeof JsonDiffFactory>;
|
|
6
|
+
export declare function ApplyDiff(root: any, diffResult: JsonDiffResult): void;
|
|
7
|
+
export declare function JsonDiffFactory(): {
|
|
8
|
+
JsonType: (value: any) => "value" | "array" | "object";
|
|
9
|
+
JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>;
|
|
10
|
+
};
|
|
11
|
+
export declare const JsonDiff: <T>(newValue: T, oldValue: T, rootPath?: string, initResult?: JsonDiffResult<T>) => JsonDiffResult<T>;
|
|
12
|
+
export declare const JsonType: (value: any) => "value" | "array" | "object";
|