From 7c2428218893f59c6a4499667488009ca67f3385 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 1 Jun 2012 11:31:10 -0700 Subject: [PATCH] chore($route): rename events BREAKING CHANGE rename $beforeRouteChange to $routeChangeStart rename $afterRouteChange to $routeChangeSuccess --- ...guide.services.managing_dependencies.ngdoc | 2 +- src/ng/directive/ngView.js | 2 +- src/ng/route.js | 10 ++-- test/ng/directive/ngViewSpec.js | 6 +-- test/ng/routeSpec.js | 53 ++++++++++--------- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc index bccc653930a5..01c261469a57 100644 --- a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc +++ b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc @@ -76,7 +76,7 @@ provided by Angular's web framework: $provide.factory('routeTemplateMonitor', ['$route', 'batchLog', '$rootScope', function($route, batchLog, $rootScope) { - $rootScope.$on('$afterRouteChange', function() { + $rootScope.$on('$routeChangeSuccess', function() { batchLog($route.current ? $route.current.template : null); }); }]); diff --git a/src/ng/directive/ngView.js b/src/ng/directive/ngView.js index 4924ed1aa3e7..1d2a5d29c6ce 100644 --- a/src/ng/directive/ngView.js +++ b/src/ng/directive/ngView.js @@ -115,7 +115,7 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c var lastScope, onloadExp = attr.onload || ''; - scope.$on('$afterRouteChange', update); + scope.$on('$routeChangeSuccess', update); update(); diff --git a/src/ng/route.js b/src/ng/route.js index 5386e12a1feb..ab19818877f4 100644 --- a/src/ng/route.js +++ b/src/ng/route.js @@ -230,7 +230,7 @@ function $RouteProvider(){ /** * @ngdoc event - * @name angular.module.ng.$route#$beforeRouteChange + * @name angular.module.ng.$route#$routeChangeStart * @eventOf angular.module.ng.$route * @eventType broadcast on root scope * @description @@ -238,7 +238,7 @@ function $RouteProvider(){ * resolving all of the dependencies needed for the route change to occurs. * Typically this involves fetching the view template as well as any dependencies * defined in `resolve` route property. Once all of the dependencies are resolved - * `$afterRouteChange` is fired. + * `$routeChangeSuccess` is fired. * * @param {Route} next Future route information. * @param {Route} current Current route information. @@ -246,7 +246,7 @@ function $RouteProvider(){ /** * @ngdoc event - * @name angular.module.ng.$route#$afterRouteChange + * @name angular.module.ng.$route#$routeChangeSuccess * @eventOf angular.module.ng.$route * @eventType broadcast on root scope * @description @@ -347,7 +347,7 @@ function $RouteProvider(){ $rootScope.$broadcast('$routeUpdate', last); } else if (next || last) { forceReload = false; - $rootScope.$broadcast('$beforeRouteChange', next, last); + $rootScope.$broadcast('$routeChangeStart', next, last); $route.current = next; if (next) { if (next.redirectTo) { @@ -393,7 +393,7 @@ function $RouteProvider(){ next.locals = locals; copy(next.params, $routeParams); } - $rootScope.$broadcast('$afterRouteChange', next, last); + $rootScope.$broadcast('$routeChangeSuccess', next, last); } }, function(error) { if (next == $route.current) { diff --git a/test/ng/directive/ngViewSpec.js b/test/ng/directive/ngViewSpec.js index 7524884fcd03..efdefae882ef 100644 --- a/test/ng/directive/ngViewSpec.js +++ b/test/ng/directive/ngViewSpec.js @@ -266,8 +266,8 @@ describe('ngView', function() { }); inject(function($templateCache, $rootScope, $location) { - $rootScope.$on('$beforeRouteChange', logger('$beforeRouteChange')); - $rootScope.$on('$afterRouteChange', logger('$afterRouteChange')); + $rootScope.$on('$routeChangeStart', logger('$routeChangeStart')); + $rootScope.$on('$routeChangeSuccess', logger('$routeChangeSuccess')); $rootScope.$on('$viewContentLoaded', logger('$viewContentLoaded')); $templateCache.put('tpl.html', [200, '{{value}}', {}]); @@ -276,7 +276,7 @@ describe('ngView', function() { expect(element.text()).toBe('bound-value'); expect(log).toEqual([ - '$beforeRouteChange', 'init-ctrl', '$viewContentLoaded', '$afterRouteChange' ]); + '$routeChangeStart', 'init-ctrl', '$viewContentLoaded', '$routeChangeSuccess' ]); }); }); diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js index 3097d72dcfb4..c3f7b357eea5 100644 --- a/test/ng/routeSpec.js +++ b/test/ng/routeSpec.js @@ -26,13 +26,13 @@ describe('$route', function() { $routeProvider.when('/Blank', {}); }); inject(function($route, $location, $rootScope) { - $rootScope.$on('$beforeRouteChange', function(event, next, current) { + $rootScope.$on('$routeChangeStart', function(event, next, current) { log += 'before();'; expect(current).toBe($route.current); lastRoute = current; nextRoute = next; }); - $rootScope.$on('$afterRouteChange', function(event, current, last) { + $rootScope.$on('$routeChangeSuccess', function(event, current, last) { log += 'after();'; expect(current).toBe($route.current); expect(lastRoute).toBe(last); @@ -93,7 +93,7 @@ describe('$route', function() { inject(function($route, $location, $rootScope) { var callback = jasmine.createSpy('onRouteChange'); - $rootScope.$on('$beforeRouteChange', callback); + $rootScope.$on('$routeChangeStart', callback); $location.path('/test'); $rootScope.$digest(); callback.reset(); @@ -114,7 +114,7 @@ describe('$route', function() { inject(function($route, $location, $rootScope) { var onChangeSpy = jasmine.createSpy('onChange'); - $rootScope.$on('$beforeRouteChange', onChangeSpy); + $rootScope.$on('$routeChangeStart', onChangeSpy); expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); @@ -139,7 +139,7 @@ describe('$route', function() { inject(function($route, $location, $rootScope) { var onChangeSpy = jasmine.createSpy('onChange'); - $rootScope.$on('$beforeRouteChange', onChangeSpy); + $rootScope.$on('$routeChangeStart', onChangeSpy); expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); @@ -188,8 +188,8 @@ describe('$route', function() { }); inject(function($rootScope, $route, $location) { - $rootScope.$on('$beforeRouteChange', routeChangeSpy); - $rootScope.$on('$afterRouteChange', routeChangeSpy); + $rootScope.$on('$routeChangeStart', routeChangeSpy); + $rootScope.$on('$routeChangeSuccess', routeChangeSpy); $rootScope.$digest(); expect(routeChangeSpy).not.toHaveBeenCalled(); @@ -200,7 +200,7 @@ describe('$route', function() { }); }); - it('should fire $beforeRouteChange and resolve promises', function() { + it('should fire $routeChangeStart and resolve promises', function() { var deferA, deferB; @@ -253,8 +253,13 @@ describe('$route', function() { inject(function($location, $route, $rootScope) { var log = ''; +<<<<<<< HEAD $rootScope.$on('$beforeRouteChange', function() { log += 'before();'; }); $rootScope.$on('$routeChangeError', function(e, n, l, reason) { log += 'failed(' + reason + ');'; }); +======= + $rootScope.$on('$routeChangeStart', function() { log += 'before();'; }); + $rootScope.$on('$routeChangeFailed', function(e, n, l, reason) { log += 'failed(' + reason + ');'; }); +>>>>>>> ebebe46... chore($route): rename events $location.path('/path'); $rootScope.$digest(); @@ -276,8 +281,8 @@ describe('$route', function() { inject(function($route, $httpBackend, $location, $rootScope) { var log = ''; - $rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.template + ');'}); - $rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.template + ');'}); + $rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'}); + $rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'}); $httpBackend.expectGET('r1.html').respond('R1'); $httpBackend.expectGET('r2.html').respond('R2'); @@ -297,7 +302,7 @@ describe('$route', function() { }); - it('should not update $routeParams until $afterRouteChange', function() { + it('should not update $routeParams until $routeChangeSuccess', function() { module(function($routeProvider) { $routeProvider. when('/r1/:id', { template: 'r1.html' }). @@ -306,8 +311,8 @@ describe('$route', function() { inject(function($route, $httpBackend, $location, $rootScope, $routeParams) { var log = ''; - $rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before' + toJson($routeParams) + ';'}); - $rootScope.$on('$afterRouteChange', function(e, next) { log += '$after' + toJson($routeParams) + ';'}); + $rootScope.$on('$routeChangeStart', function(e, next) { log += '$before' + toJson($routeParams) + ';'}); + $rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after' + toJson($routeParams) + ';'}); $httpBackend.whenGET('r1.html').respond('R1'); $httpBackend.whenGET('r2.html').respond('R2'); @@ -338,8 +343,8 @@ describe('$route', function() { inject(function($route, $httpBackend, $location, $rootScope) { var log = ''; - $rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.template + ');'}); - $rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.template + ');'}); + $rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'}); + $rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'}); $httpBackend.expectGET('r1.html').respond('R1'); $httpBackend.expectGET('r2.html').respond('R2'); @@ -371,8 +376,8 @@ describe('$route', function() { $rootScope.$on('$routeChangeError', function(e, next, last, error) { log += '$failed(' + next.templateUrl + ', ' + error.status + ');'; }); - $rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.templateUrl + ');'}); - $rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.templateUrl + ');'}); + $rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.templateUrl + ');'}); + $rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.templateUrl + ');'}); $httpBackend.expectGET('r1.html').respond(404, 'R1'); $httpBackend.expectGET('r2.html').respond('R2'); @@ -457,7 +462,7 @@ describe('$route', function() { inject(function($route, $location, $rootScope) { var onChangeSpy = jasmine.createSpy('onChange'); - $rootScope.$on('$beforeRouteChange', onChangeSpy); + $rootScope.$on('$routeChangeStart', onChangeSpy); expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); @@ -563,7 +568,7 @@ describe('$route', function() { }); inject(function($route, $location, $rootScope, $routeParams) { - $rootScope.$on('$beforeRouteChange', reloaded); + $rootScope.$on('$routeChangeStart', reloaded); $location.path('/foo'); $rootScope.$digest(); expect(reloaded).toHaveBeenCalled(); @@ -588,8 +593,8 @@ describe('$route', function() { }); inject(function($route, $location, $rootScope) { - $rootScope.$on('$beforeRouteChange', routeChange); - $rootScope.$on('$afterRouteChange', routeChange); + $rootScope.$on('$routeChangeStart', routeChange); + $rootScope.$on('$routeChangeSuccess', routeChange); $rootScope.$on('$routeUpdate', routeUpdate); expect(routeChange).not.toHaveBeenCalled(); @@ -618,8 +623,8 @@ describe('$route', function() { }); inject(function($route, $location, $rootScope) { - $rootScope.$on('$beforeRouteChange', routeChange); - $rootScope.$on('$afterRouteChange', routeChange); + $rootScope.$on('$routeChangeStart', routeChange); + $rootScope.$on('$routeChangeSuccess', routeChange); expect(routeChange).not.toHaveBeenCalled(); @@ -693,7 +698,7 @@ describe('$route', function() { }); inject(function($route, $location, $rootScope, $routeParams) { - $rootScope.$on('$afterRouteChange', routeChangeSpy); + $rootScope.$on('$routeChangeSuccess', routeChangeSpy); $location.path('/bar/123'); $rootScope.$digest();