Skip to content

Commit

Permalink
refactor($route): use $q#all hash signature 2 simplify 'resolve' impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtuchkin authored and IgorMinar committed Feb 25, 2013
1 parent e27bb6e commit 7d18d0a
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/ng/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,13 @@ function $RouteProvider(){
$q.when(next).
then(function() {
if (next) {
var keys = [],
values = [],
var locals = extend({}, next.resolve),
template;

forEach(next.resolve || {}, function(value, key) {
keys.push(key);
values.push(isString(value) ? $injector.get(value) : $injector.invoke(value));
forEach(locals, function(value, key) {
locals[key] = isString(value) ? $injector.get(value) : $injector.invoke(value);
});

if (isDefined(template = next.template)) {
if (isFunction(template)) {
template = template(next.params);
Expand All @@ -437,16 +436,9 @@ function $RouteProvider(){
}
}
if (isDefined(template)) {
keys.push('$template');
values.push(template);
locals['$template'] = template;
}
return $q.all(values).then(function(values) {
var locals = {};
forEach(values, function(value, index) {
locals[keys[index]] = value;
});
return locals;
});
return $q.all(locals);
}
}).
// after route change
Expand Down

0 comments on commit 7d18d0a

Please sign in to comment.