Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
chore($route): rename events
Browse files Browse the repository at this point in the history
BREAKING CHANGE

rename $beforeRouteChange to $routeChangeStart
rename $afterRouteChange to $routeChangeSuccess
  • Loading branch information
mhevery committed Jun 1, 2012
1 parent 885fb0d commit 7c24282
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}]);
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();


Expand Down
10 changes: 5 additions & 5 deletions src/ng/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,23 @@ 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
* Broadcasted before a route change. At this point the route services starts
* 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.
*/

/**
* @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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/ng/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}', {}]);
Expand All @@ -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' ]);
});
});

Expand Down
53 changes: 29 additions & 24 deletions test/ng/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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');
Expand All @@ -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' }).
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7c24282

Please sign in to comment.