ts-ioc-container 35.6.0 → 35.6.2
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/cjm/TypedEvent.js +21 -1
- package/cjm/container/Container.js +0 -4
- package/cjm/container/EmptyContainer.js +6 -1
- package/cjm/registration/IRegistration.js +1 -1
- package/esm/TypedEvent.js +19 -0
- package/esm/container/Container.js +0 -4
- package/esm/container/EmptyContainer.js +6 -1
- package/esm/registration/IRegistration.js +1 -1
- package/package.json +2 -2
- package/typings/TypedEvent.d.ts +5 -0
package/cjm/TypedEvent.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypedEvent = void 0;
|
|
3
|
+
exports.TypedEvent = exports.EventDisposedError = void 0;
|
|
4
|
+
class EventDisposedError extends Error {
|
|
5
|
+
static assert(condition, message) {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new EventDisposedError(message);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.EventDisposedError = EventDisposedError;
|
|
4
12
|
class TypedEvent {
|
|
5
13
|
constructor() {
|
|
6
14
|
this.observerStorage = [];
|
|
15
|
+
this.isDisposed = false;
|
|
7
16
|
}
|
|
8
17
|
static fromPromise(promise) {
|
|
9
18
|
const event = new TypedEvent();
|
|
@@ -14,10 +23,12 @@ class TypedEvent {
|
|
|
14
23
|
return event;
|
|
15
24
|
}
|
|
16
25
|
on(observer) {
|
|
26
|
+
this.validate();
|
|
17
27
|
this.observerStorage.push(observer);
|
|
18
28
|
return () => this.off(observer);
|
|
19
29
|
}
|
|
20
30
|
once(observer) {
|
|
31
|
+
this.validate();
|
|
21
32
|
const onceObserver = (data) => {
|
|
22
33
|
observer(data);
|
|
23
34
|
this.off(onceObserver);
|
|
@@ -26,16 +37,25 @@ class TypedEvent {
|
|
|
26
37
|
return () => this.off(onceObserver);
|
|
27
38
|
}
|
|
28
39
|
off(observer) {
|
|
40
|
+
this.validate();
|
|
29
41
|
this.observerStorage = this.observerStorage.filter((o) => o !== observer);
|
|
30
42
|
}
|
|
31
43
|
emit(data) {
|
|
44
|
+
this.validate();
|
|
32
45
|
this.observerStorage.forEach((o) => o(data));
|
|
33
46
|
}
|
|
34
47
|
toPromise() {
|
|
35
48
|
return new Promise((resolve) => this.once(resolve));
|
|
36
49
|
}
|
|
37
50
|
dispose() {
|
|
51
|
+
this.validate();
|
|
52
|
+
this.isDisposed = true;
|
|
38
53
|
this.observerStorage = [];
|
|
39
54
|
}
|
|
55
|
+
validate() {
|
|
56
|
+
if (this.isDisposed) {
|
|
57
|
+
throw new EventDisposedError('Event is disposed');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
40
60
|
}
|
|
41
61
|
exports.TypedEvent = TypedEvent;
|
|
@@ -74,11 +74,7 @@ class Container {
|
|
|
74
74
|
}
|
|
75
75
|
dispose() {
|
|
76
76
|
this.validateContainer();
|
|
77
|
-
this.onConstruct.dispose();
|
|
78
77
|
this.onDispose.emit(this);
|
|
79
|
-
this.onDispose.dispose();
|
|
80
|
-
this.onScopeCreated.dispose();
|
|
81
|
-
this.onScopeRemoved.dispose();
|
|
82
78
|
this.isDisposed = true;
|
|
83
79
|
this.parent.removeScope(this);
|
|
84
80
|
this.parent = new EmptyContainer_1.EmptyContainer();
|
|
@@ -54,7 +54,12 @@ class EmptyContainer {
|
|
|
54
54
|
getOwnInstances() {
|
|
55
55
|
return [];
|
|
56
56
|
}
|
|
57
|
-
removeScope() {
|
|
57
|
+
removeScope() {
|
|
58
|
+
this.onConstruct.dispose();
|
|
59
|
+
this.onDispose.dispose();
|
|
60
|
+
this.onScopeCreated.dispose();
|
|
61
|
+
this.onScopeRemoved.dispose();
|
|
62
|
+
}
|
|
58
63
|
use(module) {
|
|
59
64
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
60
65
|
}
|
|
@@ -18,7 +18,7 @@ const getTransformers = (Target) => (0, metadata_1.getMetadata)(Target, METADATA
|
|
|
18
18
|
exports.getTransformers = getTransformers;
|
|
19
19
|
const register = (...mappers) => (0, metadata_1.setMetadata)(METADATA_KEY, mappers.map((m, index) => {
|
|
20
20
|
if ((0, by_1.isDepKey)(m)) {
|
|
21
|
-
return index === 0 ? m.
|
|
21
|
+
return index === 0 ? m.assignTo.bind(m) : m.redirectFrom.bind(m);
|
|
22
22
|
}
|
|
23
23
|
if ((0, IContainer_1.isDependencyKey)(m)) {
|
|
24
24
|
return (r) => (index === 0 ? r.fromKey(m) : r.redirectFrom(m));
|
package/esm/TypedEvent.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
export class EventDisposedError extends Error {
|
|
2
|
+
static assert(condition, message) {
|
|
3
|
+
if (!condition) {
|
|
4
|
+
throw new EventDisposedError(message);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
}
|
|
1
8
|
export class TypedEvent {
|
|
2
9
|
constructor() {
|
|
3
10
|
this.observerStorage = [];
|
|
11
|
+
this.isDisposed = false;
|
|
4
12
|
}
|
|
5
13
|
static fromPromise(promise) {
|
|
6
14
|
const event = new TypedEvent();
|
|
@@ -11,10 +19,12 @@ export class TypedEvent {
|
|
|
11
19
|
return event;
|
|
12
20
|
}
|
|
13
21
|
on(observer) {
|
|
22
|
+
this.validate();
|
|
14
23
|
this.observerStorage.push(observer);
|
|
15
24
|
return () => this.off(observer);
|
|
16
25
|
}
|
|
17
26
|
once(observer) {
|
|
27
|
+
this.validate();
|
|
18
28
|
const onceObserver = (data) => {
|
|
19
29
|
observer(data);
|
|
20
30
|
this.off(onceObserver);
|
|
@@ -23,15 +33,24 @@ export class TypedEvent {
|
|
|
23
33
|
return () => this.off(onceObserver);
|
|
24
34
|
}
|
|
25
35
|
off(observer) {
|
|
36
|
+
this.validate();
|
|
26
37
|
this.observerStorage = this.observerStorage.filter((o) => o !== observer);
|
|
27
38
|
}
|
|
28
39
|
emit(data) {
|
|
40
|
+
this.validate();
|
|
29
41
|
this.observerStorage.forEach((o) => o(data));
|
|
30
42
|
}
|
|
31
43
|
toPromise() {
|
|
32
44
|
return new Promise((resolve) => this.once(resolve));
|
|
33
45
|
}
|
|
34
46
|
dispose() {
|
|
47
|
+
this.validate();
|
|
48
|
+
this.isDisposed = true;
|
|
35
49
|
this.observerStorage = [];
|
|
36
50
|
}
|
|
51
|
+
validate() {
|
|
52
|
+
if (this.isDisposed) {
|
|
53
|
+
throw new EventDisposedError('Event is disposed');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
37
56
|
}
|
|
@@ -71,11 +71,7 @@ export class Container {
|
|
|
71
71
|
}
|
|
72
72
|
dispose() {
|
|
73
73
|
this.validateContainer();
|
|
74
|
-
this.onConstruct.dispose();
|
|
75
74
|
this.onDispose.emit(this);
|
|
76
|
-
this.onDispose.dispose();
|
|
77
|
-
this.onScopeCreated.dispose();
|
|
78
|
-
this.onScopeRemoved.dispose();
|
|
79
75
|
this.isDisposed = true;
|
|
80
76
|
this.parent.removeScope(this);
|
|
81
77
|
this.parent = new EmptyContainer();
|
|
@@ -51,7 +51,12 @@ export class EmptyContainer {
|
|
|
51
51
|
getOwnInstances() {
|
|
52
52
|
return [];
|
|
53
53
|
}
|
|
54
|
-
removeScope() {
|
|
54
|
+
removeScope() {
|
|
55
|
+
this.onConstruct.dispose();
|
|
56
|
+
this.onDispose.dispose();
|
|
57
|
+
this.onScopeCreated.dispose();
|
|
58
|
+
this.onScopeRemoved.dispose();
|
|
59
|
+
}
|
|
55
60
|
use(module) {
|
|
56
61
|
throw new MethodNotImplementedError();
|
|
57
62
|
}
|
|
@@ -11,7 +11,7 @@ const METADATA_KEY = 'registration';
|
|
|
11
11
|
export const getTransformers = (Target) => getMetadata(Target, METADATA_KEY) ?? [];
|
|
12
12
|
export const register = (...mappers) => setMetadata(METADATA_KEY, mappers.map((m, index) => {
|
|
13
13
|
if (isDepKey(m)) {
|
|
14
|
-
return index === 0 ? m.
|
|
14
|
+
return index === 0 ? m.assignTo.bind(m) : m.redirectFrom.bind(m);
|
|
15
15
|
}
|
|
16
16
|
if (isDependencyKey(m)) {
|
|
17
17
|
return (r) => (index === 0 ? r.fromKey(m) : r.redirectFrom(m));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "35.6.
|
|
3
|
+
"version": "35.6.2",
|
|
4
4
|
"description": "Typescript IoC container",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"ts-node": "^10.9.1",
|
|
60
60
|
"typescript": "5.4.3"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "ad0b8fd07c4deeb317db9876ab77b0672b62a802"
|
|
63
63
|
}
|
package/typings/TypedEvent.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
export type IObserver<T> = (data: T) => void;
|
|
2
2
|
export type IUnsubscribe = () => void;
|
|
3
|
+
export declare class EventDisposedError extends Error {
|
|
4
|
+
static assert(condition: boolean, message: string): void;
|
|
5
|
+
}
|
|
3
6
|
export declare class TypedEvent<T> {
|
|
4
7
|
static fromPromise<T>(promise: Promise<T>): TypedEvent<unknown>;
|
|
5
8
|
private observerStorage;
|
|
9
|
+
private isDisposed;
|
|
6
10
|
on(observer: IObserver<T>): IUnsubscribe;
|
|
7
11
|
once(observer: IObserver<T>): IUnsubscribe;
|
|
8
12
|
off(observer: IObserver<T>): void;
|
|
9
13
|
emit(data: T): void;
|
|
10
14
|
toPromise(): Promise<T>;
|
|
11
15
|
dispose(): void;
|
|
16
|
+
private validate;
|
|
12
17
|
}
|