@@ -61,16 +61,11 @@ function middlewareFactory($injector, $q) {
6161
6262 // If we are bypassing everything,
6363 // then go ahead and resolve now
64- if ( bypassAll ) {
65- middleware . resolution . resolve ( ) ;
66- }
64+ if ( bypassAll ) middleware . resolution . resolve ( ) ;
6765
6866 // We're not bypassing it,
6967 // so process that first middleware!
70- else {
71- // Process the first middleware
72- middleware . next ( ) ;
73- }
68+ else middleware . next ( ) ;
7469
7570 // Return the promise
7671 return middleware . resolution . promise ;
@@ -194,41 +189,34 @@ var $middleware = function middlewareProvider() {
194189
195190angular . module ( 'ngRoute.middleware' , [ ] ) . provider ( '$middleware' , $middleware )
196191
197- . config ( [ '$routeProvider' , '$provide' ,
198- function ( $routeProvider , $provide ) {
192+ . config ( [ '$provide' , function configureRouteProvider ( $provide ) {
199193 // Init resolve:{} to all routes
200- $provide . decorator ( '$route' , function ( $delegate ) {
201- // Go through each route
202- angular . forEach ( $delegate . routes , function ( route ) {
203- // Skip all redirects
204- if ( typeof route . redirectTo !== 'undefined' ) return ;
205-
206- // If resolve is not yet set, set it!
207- if ( typeof route . resolve === 'undefined' ) {
208- route . resolve = { } ;
209- }
194+ $provide . decorator ( '$route' , [ '$delegate' , function decorateRoute ( $delegate ) {
195+ // Go through each route & make sure resolve is set on all children
196+ angular . forEach ( $delegate . routes , function addResolveObject ( route ) {
197+ route . resolve = route . resolve || { } ;
210198 } ) ;
211199
212200 // Return the delegate
213201 return $delegate ;
214- } ) ;
202+ } ] ) ;
215203} ] )
216204
217205. run ( [ '$rootScope' , '$route' , '$location' , '$middleware' ,
218- function ( $rootScope , $route , $location , $middleware ) {
206+ function handleMiddleware ( $rootScope , $route , $location , $middleware ) {
219207 /**
220208 * Handle middleware
221209 */
222- $rootScope . $on ( '$routeChangeStart' , function ( event , next , current ) {
223- next . resolve . middleware = function ( ) {
210+ $rootScope . $on ( '$routeChangeStart' , function routeChangeStarted ( event , next , current ) {
211+ next . resolve . middleware = function resolveNextMiddleware ( ) {
224212 return $middleware ( next , next . params ) ;
225213 } ;
226214 } ) ;
227215
228216 /**
229217 * Handle redirects from middleware
230218 */
231- $rootScope . $on ( '$routeChangeError' , function ( event , current , previous , rejection ) {
219+ $rootScope . $on ( '$routeChangeError' , function handleMiddlewareRedirects ( event , current , previous , rejection ) {
232220 var pattern = / r e d i r e c t T o \: ( .* ) / ;
233221 var match ;
234222
@@ -250,8 +238,7 @@ function($rootScope, $route, $location, $middleware) {
250238
251239angular . module ( 'ui.router.middleware' , [ ] ) . provider ( '$middleware' , $middleware )
252240
253- . config ( [ '$stateProvider' ,
254- function ( $stateProvider ) {
241+ . config ( [ '$stateProvider' , function configureStateProvider ( $stateProvider ) {
255242 // Init resolve:{} to all states
256243 // https://github.com/angular-ui/ui-router/issues/1165
257244 $stateProvider . decorator ( 'path' , function ( state , parentFn ) {
@@ -264,21 +251,21 @@ function($stateProvider) {
264251} ] )
265252
266253. run ( [ '$rootScope' , '$state' , '$middleware' ,
267- function ( $rootScope , $state , $middleware ) {
254+ function handleMiddleware ( $rootScope , $state , $middleware ) {
268255 /**
269256 * Handle middleware
270257 */
271- $rootScope . $on ( '$stateChangeStart' , function ( event , toState , toParams ) {
258+ $rootScope . $on ( '$stateChangeStart' , function stateChangeStarted ( event , toState , toParams ) {
272259 // Force the state to resolve the middleware before loading
273- toState . resolve . middleware = function ( ) {
260+ toState . resolve . middleware = function resolveNextMiddleware ( ) {
274261 return $middleware ( toState , toParams ) ;
275262 } ;
276263 } ) ;
277264
278265 /**
279266 * Handle redirects from middleware
280267 */
281- $rootScope . $on ( '$stateChangeError' , function ( event , toState , toParams , fromState , fromParams , error ) {
268+ $rootScope . $on ( '$stateChangeError' , function handleMiddlewareRedirects ( event , toState , toParams , fromState , fromParams , error ) {
282269 var pattern = / r e d i r e c t T o \: ( .* ) / ;
283270 var match ;
284271
0 commit comments