Skip to content

Commit a6126ae

Browse files
committed
Don't resolve deps twice if we've reused a state definition as the default view definition (closes #37)
1 parent 1da5ba0 commit a6126ae

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

build/angular-ui-states.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* State-based routing for AngularJS
3-
* @version v0.0.1 - 2013-02-25
3+
* @version v0.0.1 - 2013-03-01
44
* @link
55
* @license MIT License, http://www.opensource.org/licenses/MIT
66
*/
@@ -199,7 +199,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
199199
// is also a good time to resolve view names to absolute names, so everything is a
200200
// straight lookup at link time.
201201
var views = {};
202-
forEach(!isDefined(state.views) ? { '': state } : state.views, function (view, name) {
202+
forEach(isDefined(state.views) ? state.views : { '': state }, function (view, name) {
203203
if (name.indexOf('@') < 0) name = name + '@' + state.parent.name;
204204
views[name] = view;
205205
});
@@ -388,9 +388,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
388388
resolve(state.resolve, globals);
389389
globals.$$state = state; // Provide access to the state itself for internal use
390390

391-
// Resolve template and dependencies for all views. Each view receives
392-
// its own dependencies, which are set up to inherit from the state's deps,
393-
// and are accessible from the state locals as '$$view$<name>'.
391+
// Resolve template and dependencies for all views.
394392
forEach(state.views, function (view, name) {
395393
// References to the controller (only instantiated at link time)
396394
var $view = dst[name] = {
@@ -404,8 +402,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
404402
$view.$template = result;
405403
}));
406404

407-
// View-local dependencies
408-
resolve(view.resolve, $view);
405+
// View-local dependencies. If we've reused the state definition as the default
406+
// view definition in .state(), we can end up with state.resolve === view.resolve.
407+
// Avoid resolving everything twice in that case.
408+
if (view.resolve !== state.resolve) resolve(view.resolve, $view);
409409
});
410410

411411
// Once we've resolved all the dependencies for this state, merge

0 commit comments

Comments
 (0)