refactor($route): use $q#all hash signature 2 simplify 'resolve' impl

This commit is contained in:
Alexander Shtuchkin 2013-02-24 12:11:25 +04:00 committed by Igor Minar
parent e27bb6eb13
commit 7d18d0ae26

View file

@ -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);
@ -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