Skip to content

Commit c3d9b5c

Browse files
committed
refactor(di): simplify Injector API
1 parent f087079 commit c3d9b5c

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

modules/di/src/injector.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,11 @@ export class Injector {
3030
}
3131

3232
get(token) {
33-
return this.getByKey(Key.get(token));
33+
return this._getByKey(Key.get(token), false, false);
3434
}
3535

3636
asyncGet(token) {
37-
return this.asyncGetByKey(Key.get(token));
38-
}
39-
40-
getByKey(key:Key) {
41-
return this._getByKey(key, false, false);
42-
}
43-
44-
asyncGetByKey(key:Key) {
45-
return this._getByKey(key, true, false);
37+
return this._getByKey(Key.get(token), true, false);
4638
}
4739

4840
createChild(bindings:List):Injector {

modules/di/src/key.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class Key {
1313
}
1414

1515
static get(token) {
16+
if (token instanceof Key) return token;
17+
1618
if (MapWrapper.contains(_allKeys, token)) {
1719
return MapWrapper.get(_allKeys, token)
1820
}

modules/di/test/di/key_spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ export function main() {
1010
it('should not be equal to another key if types are different', function () {
1111
expect(Key.get('car')).not.toBe(Key.get('porsche'));
1212
});
13+
14+
it('should return the passed in key', function () {
15+
expect(Key.get(Key.get('car'))).toBe(Key.get('car'));
16+
});
1317
});
1418
}

0 commit comments

Comments
 (0)