From 67f5e00cc9aa006ce3fe6cde9dff261c28eab70a Mon Sep 17 00:00:00 2001 From: christopherthielen Date: Thu, 11 Sep 2014 19:14:56 -0500 Subject: [PATCH] fix($resolve): use resolve fn result, not parent resolved value of same name Made resolve values ignore any keys that we're actively trying to resolve, when they also exist in some parent state. Made $$resolves persist so they can be picked up by a child state in a later digest() fixes #1317 fixes #1353 --- src/resolve.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/resolve.js b/src/resolve.js index ea30680cf..e1d07c8e6 100644 --- a/src/resolve.js +++ b/src/resolve.js @@ -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 = {}; @@ -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); } @@ -111,7 +112,15 @@ 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); @@ -119,20 +128,20 @@ function $Resolve( $q, $injector) { } 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); }