Skip to content

Commit

Permalink
fix(Injector): When getting tokens from native injector, only throw o…
Browse files Browse the repository at this point in the history
…n undefined (not on falsey values)

Closes #76
  • Loading branch information
christopherthielen committed Sep 16, 2017
1 parent a50db21 commit ada9ca2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/resolve/resolveContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { PathUtils } from "../path/pathFactory";
import { stringify } from "../common/strings";
import { Transition } from "../transition/transition";
import { UIInjector } from "../interface";
import { isUndefined } from '../common';

const when = resolvePolicies.when;
const ALL_WHENS = [when.EAGER, when.LAZY];
const EAGER_WHENS = [when.EAGER];
const whens = resolvePolicies.when;
const ALL_WHENS = [whens.EAGER, whens.LAZY];
const EAGER_WHENS = [whens.EAGER];

export const NATIVE_INJECTOR_TOKEN: string = "Native Injector";

Expand Down Expand Up @@ -105,7 +106,7 @@ export class ResolveContext {
let keys = newResolvables.map(r => r.token);
node.resolvables = node.resolvables.filter(r => keys.indexOf(r.token) === -1).concat(newResolvables);
}

/**
* Returns a promise for an array of resolved path Element promises
*
Expand All @@ -119,7 +120,7 @@ export class ResolveContext {
// If the caller specified EAGER, only the EAGER Resolvables are fetched.
// if the caller specified LAZY, both EAGER and LAZY Resolvables are fetched.`
let matchedWhens = whenOption === resolvePolicies.when.EAGER ? EAGER_WHENS : ALL_WHENS;

// get the subpath to the state argument, if provided
trace.traceResolvePath(this._path, when, trans);

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

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

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

Expand Down Expand Up @@ -204,7 +205,8 @@ class UIInjectorImpl implements UIInjector {
}
return resolvable.data;
}
return this.native && this.native.get(token);

return this.getNative(token);
}

getAsync(token: any) {
Expand All @@ -216,4 +218,4 @@ class UIInjectorImpl implements UIInjector {
getNative(token: any) {
return this.native && this.native.get(token);
}
}
}
2 changes: 1 addition & 1 deletion test/transitionSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('transition', function () {
});

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

Expand Down

0 comments on commit ada9ca2

Please sign in to comment.