@web-atoms/core 2.6.21 → 2.6.25
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/dist/App.d.ts +1 -1
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js.map +1 -1
- package/dist/core/SingleInvoker.d.ts.map +1 -1
- package/dist/core/SingleInvoker.js.map +1 -1
- package/dist/core/sleep.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist-esm/App.d.ts +1 -1
- package/dist-esm/App.d.ts.map +1 -1
- package/dist-esm/App.js +231 -235
- package/dist-esm/App.js.map +1 -1
- package/dist-esm/Atom.js +93 -96
- package/dist-esm/MockApp.js +17 -18
- package/dist-esm/Pack.js +1 -3
- package/dist-esm/core/AtomBinder.js +189 -187
- package/dist-esm/core/AtomComponent.js +479 -502
- package/dist-esm/core/AtomDispatcher.js +46 -48
- package/dist-esm/core/AtomDisposableList.js +24 -25
- package/dist-esm/core/AtomEnumerator.js +15 -16
- package/dist-esm/core/AtomList.js +193 -192
- package/dist-esm/core/AtomLoader.js +229 -215
- package/dist-esm/core/AtomMap.js +7 -8
- package/dist-esm/core/AtomOnce.js +22 -24
- package/dist-esm/core/AtomSelectableList.js +240 -243
- package/dist-esm/core/AtomUri.js +70 -72
- package/dist-esm/core/AtomWatcher.js +105 -111
- package/dist-esm/core/Bind.js +271 -269
- package/dist-esm/core/BindableProperty.js +26 -27
- package/dist-esm/core/CancelTokenFactory.js +21 -24
- package/dist-esm/core/Color.js +1 -2
- package/dist-esm/core/Colors.js +545 -231
- package/dist-esm/core/Command.js +236 -223
- package/dist-esm/core/Defer.js +21 -22
- package/dist-esm/core/EventScope.js +96 -88
- package/dist-esm/core/ExpressionParser.js +132 -144
- package/dist-esm/core/ExtendControl.js +7 -8
- package/dist-esm/core/FormattedError.js +7 -8
- package/dist-esm/core/FormattedString.js +4 -5
- package/dist-esm/core/Hacks.js +41 -42
- package/dist-esm/core/IFetchEvent.js +1 -2
- package/dist-esm/core/IScreen.js +1 -2
- package/dist-esm/core/IValueConverter.js +1 -2
- package/dist-esm/core/InheritedProperty.js +61 -63
- package/dist-esm/core/InjectProperty.js +12 -13
- package/dist-esm/core/KeyValuePairs.js +1 -2
- package/dist-esm/core/Markdown.js +14 -17
- package/dist-esm/core/MarkdownError.js +6 -7
- package/dist-esm/core/PropertyBinding.js +1 -2
- package/dist-esm/core/PropertyMap.js +28 -27
- package/dist-esm/core/Route.js +149 -148
- package/dist-esm/core/SingleInvoker.d.ts.map +1 -1
- package/dist-esm/core/SingleInvoker.js +32 -35
- package/dist-esm/core/SingleInvoker.js.map +1 -1
- package/dist-esm/core/StringHelper.js +49 -51
- package/dist-esm/core/TransientDisposable.js +14 -16
- package/dist-esm/core/WatchProperty.js +18 -17
- package/dist-esm/core/WebImage.js +7 -8
- package/dist-esm/core/XNode.js +134 -117
- package/dist-esm/core/sleep.js +21 -24
- package/dist-esm/core/sleep.js.map +1 -1
- package/dist-esm/core/types.js +102 -103
- package/dist-esm/di/DISingleton.js +7 -5
- package/dist-esm/di/DITransient.js +7 -5
- package/dist-esm/di/IMockOrInject.js +1 -2
- package/dist-esm/di/IServiceProvider.js +1 -2
- package/dist-esm/di/Inject.js +67 -67
- package/dist-esm/di/Register.js +25 -26
- package/dist-esm/di/RegisterScoped.js +4 -3
- package/dist-esm/di/RegisterSingleton.js +4 -3
- package/dist-esm/di/ServiceCollection.js +38 -37
- package/dist-esm/di/ServiceProvider.js +94 -94
- package/dist-esm/di/TypeKey.js +13 -12
- package/dist-esm/services/BusyIndicatorService.js +7 -11
- package/dist-esm/services/CacheService.js +54 -62
- package/dist-esm/services/FetchBuilder.js +327 -278
- package/dist-esm/services/JsonService.js +118 -116
- package/dist-esm/services/MockNavigationService.js +127 -126
- package/dist-esm/services/NavigationService.js +95 -102
- package/dist-esm/services/ReferenceService.js +30 -33
- package/dist-esm/services/http/AjaxOptions.js +1 -3
- package/dist-esm/services/http/JsonError.js +16 -15
- package/dist-esm/services/http/RestService.js +314 -323
- package/dist-esm/style/StyleRule.js +1 -2
- package/dist-esm/test.js +0 -1
- package/dist-esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist-esm/unit/AtomTest.js +10 -11
- package/dist-esm/view-model/Action.js +258 -223
- package/dist-esm/view-model/AtomViewModel.js +234 -232
- package/dist-esm/view-model/AtomWindowViewModel.js +13 -14
- package/dist-esm/view-model/BindableUrlParameter.js +7 -8
- package/dist-esm/view-model/Delay.js +21 -25
- package/dist-esm/view-model/Disposable.js +28 -29
- package/dist-esm/view-model/Load.js +72 -73
- package/dist-esm/view-model/Once.js +33 -35
- package/dist-esm/view-model/baseTypes.js +4 -5
- package/dist-esm/view-model/bindPromise.js +24 -27
- package/dist-esm/view-model/bindProperty.js +3 -4
- package/dist-esm/view-model/bindUrlParameter.js +39 -43
- package/dist-esm/web/controls/AtomComboBox.js +56 -63
- package/dist-esm/web/controls/AtomControl.js +485 -490
- package/dist-esm/web/controls/AtomGridSplitter.js +57 -50
- package/dist-esm/web/controls/AtomGridView.js +230 -222
- package/dist-esm/web/controls/AtomItemsControl.js +677 -688
- package/dist-esm/web/controls/AtomPage.js +6 -7
- package/dist-esm/web/controls/AtomTemplate.js +1 -3
- package/dist-esm/web/controls/AtomTemplateControl.js +28 -29
- package/dist-esm/web/controls/AtomViewStack.js +19 -20
- package/dist-esm/web/core/AtomUI.js +200 -200
- package/dist-esm/web/core/Encoder.js +142 -152
- package/dist-esm/web/core/HtmlNode.js +141 -139
- package/dist-esm/web/images/Busy.js +1 -2
- package/dist-esm/web/images/BusyDataUrl.js +2 -869
- package/dist-esm/web/images/Button.js +1 -2
- package/dist-esm/web/images/ButtonDataUrl.js +2 -30
- package/dist-esm/web/images/CloseButton.js +1 -2
- package/dist-esm/web/images/CloseButtonDataUrl.js +2 -30
- package/dist-esm/web/images/CloseButtonHover.js +1 -2
- package/dist-esm/web/images/CloseButtonHoverDataUrl.js +2 -24
- package/dist-esm/web/services/LastTarget.js +31 -29
- package/dist-esm/web/services/MarkdownService.js +19 -31
- package/dist-esm/web/services/NotificationPopup.js +28 -21
- package/dist-esm/web/services/PopupService.js +512 -478
- package/dist-esm/web/services/PopupWindow.js +266 -247
- package/dist-esm/web/styles/AtomAlertWindowStyle.js +39 -40
- package/dist-esm/web/styles/AtomFrameStyle.js +15 -16
- package/dist-esm/web/styles/AtomNotificationStyle.js +19 -20
- package/dist-esm/web/styles/AtomPageLinkStyle.js +11 -12
- package/dist-esm/web/styles/AtomPopupStyle.js +9 -10
- package/dist-esm/web/styles/AtomStyle.js +61 -64
- package/dist-esm/web/styles/AtomStyleSheet.js +50 -51
- package/dist-esm/web/styles/AtomWindowStyle.js +116 -117
- package/dist-esm/web/styles/IStyleDeclaration.js +1 -2
- package/dist-esm/web/styles/StyleBuilder.js +79 -80
- package/package.json +3 -1
- package/src/App.ts +1 -1
- package/src/core/SingleInvoker.ts +1 -1
- package/src/core/sleep.ts +1 -1
package/dist-esm/core/types.js
CHANGED
|
@@ -3,128 +3,127 @@ import Map from "./AtomMap.js";
|
|
|
3
3
|
export const ignoreValue = Symbol("ignore");
|
|
4
4
|
export const errorHandled = Symbol("errorHandled");
|
|
5
5
|
export class CancelToken {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
if (/^(cancelled$|canceled$|aborterror\:)/i.test(e.message ?? e.toString().trim())) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
if (e.name === "AbortError") {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
6
|
+
static isCancelled(e) {
|
|
7
|
+
if (e[errorHandled]) {
|
|
8
|
+
return true;
|
|
16
9
|
}
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (/^(cancelled$|canceled$|aborterror\:)/i.test(e.message ?? e.toString().trim())) {
|
|
11
|
+
return true;
|
|
19
12
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.mCancelled = null;
|
|
23
|
-
this.cancelTimeout = null;
|
|
24
|
-
if (timeout > 0) {
|
|
25
|
-
this.cancelTimeout = setTimeout(() => {
|
|
26
|
-
this.cancelTimeout = null;
|
|
27
|
-
this.cancel("timeout");
|
|
28
|
-
}, timeout);
|
|
29
|
-
}
|
|
13
|
+
if (e.name === "AbortError") {
|
|
14
|
+
return true;
|
|
30
15
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
}
|
|
17
|
+
get cancelled() {
|
|
18
|
+
return this.mCancelled;
|
|
19
|
+
}
|
|
20
|
+
constructor(timeout = -1) {
|
|
21
|
+
this.listeners = [];
|
|
22
|
+
this.mCancelled = null;
|
|
23
|
+
this.cancelTimeout = null;
|
|
24
|
+
if (timeout > 0) {
|
|
25
|
+
this.cancelTimeout = setTimeout(() => {
|
|
26
|
+
this.cancelTimeout = null;
|
|
27
|
+
this.cancel("timeout");
|
|
28
|
+
}, timeout);
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
}
|
|
31
|
+
cancel(r = "cancelled") {
|
|
32
|
+
this.mCancelled = r;
|
|
33
|
+
const existing = this.listeners.slice(0);
|
|
34
|
+
this.listeners.length = 0;
|
|
35
|
+
for (const fx of existing) {
|
|
36
|
+
fx(r);
|
|
43
37
|
}
|
|
44
|
-
dispose()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
this.dispose();
|
|
39
|
+
}
|
|
40
|
+
reset() {
|
|
41
|
+
this.mCancelled = null;
|
|
42
|
+
this.dispose();
|
|
43
|
+
}
|
|
44
|
+
dispose() {
|
|
45
|
+
this.listeners.length = 0;
|
|
46
|
+
if (this.cancelTimeout) {
|
|
47
|
+
clearTimeout(this.cancelTimeout);
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.listeners.push(f);
|
|
49
|
+
}
|
|
50
|
+
registerForCancel(f) {
|
|
51
|
+
if (this.mCancelled) {
|
|
52
|
+
f(this.mCancelled);
|
|
53
|
+
this.cancel();
|
|
54
|
+
return;
|
|
57
55
|
}
|
|
56
|
+
this.listeners.push(f);
|
|
57
|
+
}
|
|
58
58
|
}
|
|
59
59
|
export class ArrayHelper {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
60
|
+
static remove(a, filter) {
|
|
61
|
+
for (let i = 0; i < a.length; i++) {
|
|
62
|
+
const item = a[i];
|
|
63
|
+
if (filter(item)) {
|
|
64
|
+
a.splice(i, 1);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
69
67
|
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
70
|
}
|
|
71
71
|
Object.values ??= function (t) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
72
|
+
const r = [];
|
|
73
|
+
for (const key in t) {
|
|
74
|
+
if (Object.prototype.hasOwnProperty.call(t, key)) {
|
|
75
|
+
const element = t[key];
|
|
76
|
+
r.push(element);
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
}
|
|
79
|
+
return r;
|
|
80
80
|
};
|
|
81
81
|
const flat = Array.prototype.flat ?? function (depth = 1) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
r.push(iterator);
|
|
82
|
+
const r = [];
|
|
83
|
+
const flat = depth > 0;
|
|
84
|
+
const nestDepth = depth - 1;
|
|
85
|
+
const nestFlat = nestDepth > 0;
|
|
86
|
+
for (const iterator of this) {
|
|
87
|
+
if (flat && Array.isArray(iterator)) {
|
|
88
|
+
if (nestFlat) {
|
|
89
|
+
r.push(...iterator.flat(nestDepth));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
r.push(...iterator);
|
|
93
|
+
continue;
|
|
96
94
|
}
|
|
97
|
-
|
|
95
|
+
r.push(iterator);
|
|
96
|
+
}
|
|
97
|
+
return r;
|
|
98
98
|
};
|
|
99
99
|
const groupBy = Array.prototype.groupBy ?? function (keySelector) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
g.push(iterator);
|
|
100
|
+
const map = new Map();
|
|
101
|
+
const groups = [];
|
|
102
|
+
for (const iterator of this) {
|
|
103
|
+
const key = keySelector(iterator);
|
|
104
|
+
let g = map.get(key);
|
|
105
|
+
if (!g) {
|
|
106
|
+
g = [];
|
|
107
|
+
g.key = key;
|
|
108
|
+
groups.push(g);
|
|
109
|
+
map.set(key, g);
|
|
112
110
|
}
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
g.push(iterator);
|
|
112
|
+
}
|
|
113
|
+
map.clear();
|
|
114
|
+
return groups;
|
|
115
115
|
};
|
|
116
116
|
Object.defineProperties(Array.prototype, {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
flat: {
|
|
118
|
+
enumerable: false,
|
|
119
|
+
value: flat,
|
|
120
|
+
configurable: true
|
|
121
|
+
},
|
|
122
|
+
groupBy: {
|
|
123
|
+
enumerable: false,
|
|
124
|
+
value: groupBy,
|
|
125
|
+
configurable: true
|
|
126
|
+
}
|
|
127
127
|
});
|
|
128
|
-
const globalNS =
|
|
129
|
-
export const UMD =
|
|
130
|
-
//# sourceMappingURL=types.js.map
|
|
128
|
+
const globalNS = typeof window !== "undefined" ? window : global;
|
|
129
|
+
export const UMD = globalNS.UMD;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Register } from "./Register.js";
|
|
2
2
|
import { Scope } from "./ServiceCollection.js";
|
|
3
3
|
export default function DISingleton(mockOrInject) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
return target => {
|
|
5
|
+
Register({
|
|
6
|
+
scope: Scope.Global,
|
|
7
|
+
mockOrInject
|
|
8
|
+
})(target);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Register } from "./Register.js";
|
|
2
2
|
import { Scope } from "./ServiceCollection.js";
|
|
3
3
|
export default function DITransient(mockOrInject) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
return target => {
|
|
5
|
+
Register({
|
|
6
|
+
scope: Scope.Transient,
|
|
7
|
+
mockOrInject
|
|
8
|
+
})(target);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=IMockOrInject.js.map
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=IServiceProvider.js.map
|
|
1
|
+
export {};
|
package/dist-esm/di/Inject.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
import { TypeKey } from "./TypeKey.js";
|
|
2
2
|
export class InjectedTypes {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
static {
|
|
4
|
+
this.paramList = {};
|
|
5
|
+
}
|
|
6
|
+
static {
|
|
7
|
+
this.propertyList = {};
|
|
8
|
+
}
|
|
9
|
+
static getParamList(key, typeKey1) {
|
|
10
|
+
let plist = InjectedTypes.paramList[typeKey1];
|
|
11
|
+
let type = key;
|
|
12
|
+
while (plist === undefined) {
|
|
13
|
+
type = Object.getPrototypeOf(type);
|
|
14
|
+
if (!type) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
const typeKey = TypeKey.get(type);
|
|
18
|
+
plist = InjectedTypes.paramList[typeKey];
|
|
19
|
+
if (!plist) {
|
|
20
|
+
InjectedTypes.paramList[typeKey] = plist;
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
return plist;
|
|
24
|
+
}
|
|
25
|
+
static getPropertyList(key, typeKey1) {
|
|
26
|
+
let plist = InjectedTypes.propertyList[typeKey1];
|
|
27
|
+
let type = key;
|
|
28
|
+
while (plist === undefined) {
|
|
29
|
+
type = Object.getPrototypeOf(type);
|
|
30
|
+
if (!type) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
const typeKey = TypeKey.get(type);
|
|
34
|
+
plist = InjectedTypes.propertyList[typeKey];
|
|
35
|
+
if (!plist) {
|
|
36
|
+
InjectedTypes.propertyList[typeKey] = plist;
|
|
37
|
+
}
|
|
36
38
|
}
|
|
39
|
+
return plist;
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
export function Inject(target, name, index) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw new Error("Inject can only be applied on constructor" +
|
|
48
|
-
"parameter or a property without get/set methods");
|
|
49
|
-
}
|
|
43
|
+
if (index !== undefined) {
|
|
44
|
+
const key = TypeKey.get(target);
|
|
45
|
+
const plist = Reflect.getMetadata("design:paramtypes", target, name);
|
|
46
|
+
if (typeof index === "number") {
|
|
47
|
+
const pSavedList = InjectedTypes.paramList[key] || (InjectedTypes.paramList[key] = []);
|
|
48
|
+
pSavedList[index] = plist[index];
|
|
49
|
+
} else {
|
|
50
|
+
throw new Error("Inject can only be applied on constructor" + "parameter or a property without get/set methods");
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
52
|
+
} else {
|
|
53
|
+
const key = TypeKey.get(target.constructor);
|
|
54
|
+
const plist = Reflect.getMetadata("design:type", target, name);
|
|
55
|
+
const p = InjectedTypes.propertyList[key] || (InjectedTypes.propertyList[key] = {});
|
|
56
|
+
p[name] = plist;
|
|
57
|
+
let base = target.constructor;
|
|
58
|
+
while (true) {
|
|
59
|
+
base = Object.getPrototypeOf(base);
|
|
60
|
+
if (!base) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
const baseKey = TypeKey.get(base);
|
|
64
|
+
const bp = InjectedTypes.propertyList[baseKey];
|
|
65
|
+
if (bp) {
|
|
66
|
+
for (const pKey in bp) {
|
|
67
|
+
if (bp.hasOwnProperty(pKey)) {
|
|
68
|
+
const element = bp[pKey];
|
|
69
|
+
if (!p[pKey]) {
|
|
70
|
+
p[pKey] = element;
|
|
73
71
|
}
|
|
72
|
+
}
|
|
74
73
|
}
|
|
74
|
+
}
|
|
75
75
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist-esm/di/Register.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { Scope, ServiceCollection } from "./ServiceCollection.js";
|
|
2
|
-
const globalNS =
|
|
2
|
+
const globalNS = typeof global === "undefined" ? window : global;
|
|
3
3
|
function evalGlobal(path) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return r;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
4
|
+
if (typeof path === "string") {
|
|
5
|
+
let r = globalNS;
|
|
6
|
+
for (const iterator of path.split(".")) {
|
|
7
|
+
r = r[iterator];
|
|
8
|
+
if (r === undefined || r === null) {
|
|
12
9
|
return r;
|
|
10
|
+
}
|
|
13
11
|
}
|
|
14
|
-
return
|
|
12
|
+
return r;
|
|
13
|
+
}
|
|
14
|
+
return path;
|
|
15
15
|
}
|
|
16
16
|
export function Register(id, scope) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
17
|
+
return target => {
|
|
18
|
+
if (typeof id === "object") {
|
|
19
|
+
if (scope) {
|
|
20
|
+
id.scope = scope;
|
|
21
|
+
}
|
|
22
|
+
ServiceCollection.instance.register(id.for || target, id.for ? sp => sp.create(target) : null, id.scope || Scope.Transient, id.id);
|
|
23
|
+
if (id.mockOrInject) {
|
|
24
|
+
if (id.mockOrInject.globalVar) {
|
|
25
|
+
ServiceCollection.instance.register(id.for || target, sp => evalGlobal(id.mockOrInject.globalVar), id.scope || Scope.Global, id.id);
|
|
29
26
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
ServiceCollection.instance.register(target, null, scope, id);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Register } from "./Register.js";
|
|
2
2
|
import { Scope } from "./ServiceCollection.js";
|
|
3
3
|
export function RegisterScoped(id) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Register({
|
|
5
|
+
scope: Scope.Scoped
|
|
6
|
+
})(id);
|
|
7
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Register } from "./Register.js";
|
|
2
2
|
import { Scope } from "./ServiceCollection.js";
|
|
3
3
|
export function RegisterSingleton(target) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Register({
|
|
5
|
+
scope: Scope.Global
|
|
6
|
+
})(target);
|
|
7
|
+
}
|
|
@@ -2,45 +2,46 @@ import { ArrayHelper } from "../core/types.js";
|
|
|
2
2
|
import { TypeKey } from "./TypeKey.js";
|
|
3
3
|
export var Scope;
|
|
4
4
|
(function (Scope) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Scope[Scope["Global"] = 1] = "Global";
|
|
6
|
+
Scope[Scope["Scoped"] = 2] = "Scoped";
|
|
7
|
+
Scope[Scope["Transient"] = 3] = "Transient";
|
|
8
8
|
})(Scope || (Scope = {}));
|
|
9
9
|
export class ServiceDescription {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
constructor(id, scope, type, factory) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.scope = scope;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.factory = factory;
|
|
15
|
+
this.factory = this.factory || (sp => {
|
|
16
|
+
return sp.create(type);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
20
|
export class ServiceCollection {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.registrations.push(sd);
|
|
34
|
-
return sd;
|
|
35
|
-
}
|
|
36
|
-
registerScoped(type, factory, id) {
|
|
37
|
-
return this.register(type, factory, Scope.Scoped, id);
|
|
21
|
+
constructor() {
|
|
22
|
+
this.registrations = [];
|
|
23
|
+
this.ids = 1;
|
|
24
|
+
}
|
|
25
|
+
static {
|
|
26
|
+
this.instance = new ServiceCollection();
|
|
27
|
+
}
|
|
28
|
+
register(type, factory, scope = Scope.Transient, id) {
|
|
29
|
+
ArrayHelper.remove(this.registrations, r => id ? r.id === id : r.type === type);
|
|
30
|
+
if (!id) {
|
|
31
|
+
id = TypeKey.get(type);
|
|
32
|
+
this.ids++;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
34
|
+
const sd = new ServiceDescription(id, scope, type, factory);
|
|
35
|
+
this.registrations.push(sd);
|
|
36
|
+
return sd;
|
|
37
|
+
}
|
|
38
|
+
registerScoped(type, factory, id) {
|
|
39
|
+
return this.register(type, factory, Scope.Scoped, id);
|
|
40
|
+
}
|
|
41
|
+
registerSingleton(type, factory, id) {
|
|
42
|
+
return this.register(type, factory, Scope.Global, id);
|
|
43
|
+
}
|
|
44
|
+
get(type) {
|
|
45
|
+
return this.registrations.find(s => s.id === type || s.type === type);
|
|
46
|
+
}
|
|
47
|
+
}
|