Skip to content

Commit

Permalink
Merge pull request #1360 from angular-ui/issue-1317
Browse files Browse the repository at this point in the history
fix($resolve): use resolvefn result,not parent resolved value of same name
  • Loading branch information
christopherthielen committed Sep 12, 2014
2 parents 6940dec + 67f5e00 commit 64b9bea
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function $Resolve( $q, $injector) {
*/
this.study = function (invocables) {
if (!isObject(invocables)) throw new Error("'invocables' must be an object");
var invocableKeys = Object.keys(invocables || {});

// Perform a topological sort of invocables to build an ordered plan
var plan = [], cycle = [], visited = {};
Expand Down Expand Up @@ -101,7 +102,7 @@ function $Resolve( $q, $injector) {
if (!--wait) {
if (!merged) merge(values, parent.$$values);
result.$$values = values;
result.$$promises = true; // keep for isResolve()
result.$$promises = result.$$promises || true; // keep for isResolve()
delete result.$$inheritedValues;
resolution.resolve(values);
}
Expand All @@ -111,28 +112,36 @@ function $Resolve( $q, $injector) {
result.$$failure = reason;
resolution.reject(reason);
}


// TODO: Remove this when we merge in 'new' branch
function omit(obj) {
var copy = {}, keys = angular.isArray(arguments[1]) ? arguments[1] : arguments.slice(1);
for (var key in obj)
if (keys.indexOf(key) == -1) copy[key] = obj[key];
return copy;
}

// Short-circuit if parent has already failed
if (isDefined(parent.$$failure)) {
fail(parent.$$failure);
return result;
}

if (parent.$$inheritedValues) {
merge(values, parent.$$inheritedValues);
merge(values, omit(parent.$$inheritedValues, invocableKeys));
}

// Merge parent values if the parent has already resolved, or merge
// parent promises and wait if the parent resolve is still in progress.
extend(promises, parent.$$promises);
if (parent.$$values) {
merged = merge(values, parent.$$values);
result.$$inheritedValues = parent.$$values;
merged = merge(values, omit(parent.$$values, invocableKeys));
result.$$inheritedValues = omit(parent.$$values, invocableKeys);
done();
} else {
if (parent.$$inheritedValues) {
result.$$inheritedValues = parent.$$inheritedValues;
result.$$inheritedValues = omit(parent.$$inheritedValues, invocableKeys);
}
extend(promises, parent.$$promises);
parent.then(done, fail);
}

Expand Down

0 comments on commit 64b9bea

Please sign in to comment.