refactor(di): simplify Injector API
This commit is contained in:
parent
f0870791f6
commit
c3d9b5c91e
|
@ -30,19 +30,11 @@ export class Injector {
|
||||||
}
|
}
|
||||||
|
|
||||||
get(token) {
|
get(token) {
|
||||||
return this.getByKey(Key.get(token));
|
return this._getByKey(Key.get(token), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
asyncGet(token) {
|
asyncGet(token) {
|
||||||
return this.asyncGetByKey(Key.get(token));
|
return this._getByKey(Key.get(token), true, false);
|
||||||
}
|
|
||||||
|
|
||||||
getByKey(key:Key) {
|
|
||||||
return this._getByKey(key, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
asyncGetByKey(key:Key) {
|
|
||||||
return this._getByKey(key, true, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createChild(bindings:List):Injector {
|
createChild(bindings:List):Injector {
|
||||||
|
|
|
@ -13,6 +13,8 @@ export class Key {
|
||||||
}
|
}
|
||||||
|
|
||||||
static get(token) {
|
static get(token) {
|
||||||
|
if (token instanceof Key) return token;
|
||||||
|
|
||||||
if (MapWrapper.contains(_allKeys, token)) {
|
if (MapWrapper.contains(_allKeys, token)) {
|
||||||
return MapWrapper.get(_allKeys, token)
|
return MapWrapper.get(_allKeys, token)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,9 @@ export function main() {
|
||||||
it('should not be equal to another key if types are different', function () {
|
it('should not be equal to another key if types are different', function () {
|
||||||
expect(Key.get('car')).not.toBe(Key.get('porsche'));
|
expect(Key.get('car')).not.toBe(Key.get('porsche'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the passed in key', function () {
|
||||||
|
expect(Key.get(Key.get('car'))).toBe(Key.get('car'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue