Skip to content

Commit ada9ca2

Browse files
fix(Injector): When getting tokens from native injector, only throw on undefined (not on falsey values)
Closes #76
1 parent a50db21 commit ada9ca2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/resolve/resolveContext.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import { PathUtils } from "../path/pathFactory";
1212
import { stringify } from "../common/strings";
1313
import { Transition } from "../transition/transition";
1414
import { UIInjector } from "../interface";
15+
import { isUndefined } from '../common';
1516

16-
const when = resolvePolicies.when;
17-
const ALL_WHENS = [when.EAGER, when.LAZY];
18-
const EAGER_WHENS = [when.EAGER];
17+
const whens = resolvePolicies.when;
18+
const ALL_WHENS = [whens.EAGER, whens.LAZY];
19+
const EAGER_WHENS = [whens.EAGER];
1920

2021
export const NATIVE_INJECTOR_TOKEN: string = "Native Injector";
2122

@@ -105,7 +106,7 @@ export class ResolveContext {
105106
let keys = newResolvables.map(r => r.token);
106107
node.resolvables = node.resolvables.filter(r => keys.indexOf(r.token) === -1).concat(newResolvables);
107108
}
108-
109+
109110
/**
110111
* Returns a promise for an array of resolved path Element promises
111112
*
@@ -119,7 +120,7 @@ export class ResolveContext {
119120
// If the caller specified EAGER, only the EAGER Resolvables are fetched.
120121
// if the caller specified LAZY, both EAGER and LAZY Resolvables are fetched.`
121122
let matchedWhens = whenOption === resolvePolicies.when.EAGER ? EAGER_WHENS : ALL_WHENS;
122-
123+
123124
// get the subpath to the state argument, if provided
124125
trace.traceResolvePath(this._path, when, trans);
125126

@@ -166,15 +167,15 @@ export class ResolveContext {
166167
// subpath stopping at resolvable's node, or the whole path (if the resolvable isn't in the path)
167168
let subPath: PathNode[] = PathUtils.subPath(this._path, x => x === node) || this._path;
168169
let availableResolvables: Resolvable[] = subPath
169-
.reduce((acc, node) => acc.concat(node.resolvables), []) //all of subpath's resolvables
170+
.reduce((acc, _node) => acc.concat(_node.resolvables), []) //all of subpath's resolvables
170171
.filter(res => res !== resolvable); // filter out the `resolvable` argument
171172

172173
const getDependency = (token: any) => {
173174
let matching = availableResolvables.filter(r => r.token === token);
174175
if (matching.length) return tail(matching);
175176

176177
let fromInjector = this.injector().getNative(token);
177-
if (!fromInjector) {
178+
if (isUndefined(fromInjector)) {
178179
throw new Error("Could not find Dependency Injection token: " + stringify(token));
179180
}
180181

@@ -204,7 +205,8 @@ class UIInjectorImpl implements UIInjector {
204205
}
205206
return resolvable.data;
206207
}
207-
return this.native && this.native.get(token);
208+
209+
return this.getNative(token);
208210
}
209211

210212
getAsync(token: any) {
@@ -216,4 +218,4 @@ class UIInjectorImpl implements UIInjector {
216218
getNative(token: any) {
217219
return this.native && this.native.get(token);
218220
}
219-
}
221+
}

test/transitionSpec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe('transition', function () {
348348
});
349349

350350
describe('.onExit()', function() {
351-
it('should get Transition, the state being exited, and Injector as arguments', ((done) => {
351+
it('should get Transition and the state being exited as arguments', ((done) => {
352352
let args = { trans: undefined, state: undefined, third: undefined };
353353
let states = [];
354354

0 commit comments

Comments
 (0)