smartdi 0.1.0 → 0.2.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/index.d.ts +4 -3
- package/index.js +6 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type Class<T> = {
|
|
2
2
|
new (...args: any[]): T;
|
|
3
3
|
};
|
|
4
|
+
export type AbstractClass<T> = abstract new (...args: any[]) => T;
|
|
4
5
|
declare const $registry: unique symbol;
|
|
5
6
|
export interface InjectableOptions {
|
|
6
7
|
name?: string;
|
|
@@ -18,7 +19,7 @@ export declare abstract class SmartDI {
|
|
|
18
19
|
static readonly [$registry]: {
|
|
19
20
|
[key: string]: RegistryItem;
|
|
20
21
|
};
|
|
21
|
-
static get<T>(clue: Class<T>, ...args: any[]): T;
|
|
22
|
+
static get<T>(clue: Class<T> | AbstractClass<T>, ...args: any[]): T;
|
|
22
23
|
static get<T>(name: string, ...args: any[]): T;
|
|
23
24
|
private static internalGet;
|
|
24
25
|
private static internalGetArray;
|
|
@@ -27,7 +28,7 @@ export declare abstract class SmartDI {
|
|
|
27
28
|
private static resovleOneByConstructor;
|
|
28
29
|
}
|
|
29
30
|
export declare function Injectable(options?: InjectableOptions): ClassDecorator;
|
|
30
|
-
export declare function Inject(constructor: Class<any>, ...args: any[]): PropertyDecorator;
|
|
31
|
+
export declare function Inject(constructor: Class<any> | AbstractClass<any>, ...args: any[]): PropertyDecorator;
|
|
31
32
|
export declare function Inject(name: string, ...args: any[]): PropertyDecorator;
|
|
32
|
-
export declare function InjectArray(constructor: Class<any>, ...args: any[]): PropertyDecorator;
|
|
33
|
+
export declare function InjectArray(constructor: Class<any> | AbstractClass<any>, ...args: any[]): PropertyDecorator;
|
|
33
34
|
export {};
|
package/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.SmartDI = void 0;
|
|
5
|
+
exports.Injectable = Injectable;
|
|
6
|
+
exports.Inject = Inject;
|
|
7
|
+
exports.InjectArray = InjectArray;
|
|
5
8
|
const $registry = Symbol('registry');
|
|
6
9
|
class SmartDI {
|
|
7
10
|
static get(clue, ...args) {
|
|
@@ -57,10 +60,10 @@ class SmartDI {
|
|
|
57
60
|
let matched = [];
|
|
58
61
|
function isSubclass(sub, sup) {
|
|
59
62
|
let proto = Object.getPrototypeOf(sub);
|
|
60
|
-
while (proto
|
|
63
|
+
while (proto) {
|
|
61
64
|
if (proto === sup)
|
|
62
65
|
return true;
|
|
63
|
-
proto = Object.getPrototypeOf(
|
|
66
|
+
proto = Object.getPrototypeOf(proto);
|
|
64
67
|
}
|
|
65
68
|
return false;
|
|
66
69
|
}
|
|
@@ -97,7 +100,6 @@ function Injectable(options) {
|
|
|
97
100
|
};
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
|
-
exports.Injectable = Injectable;
|
|
101
103
|
function Inject(clue, ...args) {
|
|
102
104
|
return function (target, prop) {
|
|
103
105
|
let injects = Reflect.getMetadata('smartdi:injects', target) || {};
|
|
@@ -105,7 +107,6 @@ function Inject(clue, ...args) {
|
|
|
105
107
|
Reflect.defineMetadata('smartdi:injects', injects, target);
|
|
106
108
|
};
|
|
107
109
|
}
|
|
108
|
-
exports.Inject = Inject;
|
|
109
110
|
function InjectArray(clue, ...args) {
|
|
110
111
|
return function (target, prop) {
|
|
111
112
|
let injects = Reflect.getMetadata('smartdi:injects', target) || {};
|
|
@@ -113,4 +114,3 @@ function InjectArray(clue, ...args) {
|
|
|
113
114
|
Reflect.defineMetadata('smartdi:injects', injects, target);
|
|
114
115
|
};
|
|
115
116
|
}
|
|
116
|
-
exports.InjectArray = InjectArray;
|