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

Commit 7c24282

Browse files
committed
chore($route): rename events
BREAKING CHANGE rename $beforeRouteChange to $routeChangeStart rename $afterRouteChange to $routeChangeSuccess
1 parent 885fb0d commit 7c24282

File tree

5 files changed

+39
-34
lines changed

5 files changed

+39
-34
lines changed

docs/content/guide/dev_guide.services.managing_dependencies.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ provided by Angular's web framework:
7676
$provide.factory('routeTemplateMonitor',
7777
['$route', 'batchLog', '$rootScope',
7878
function($route, batchLog, $rootScope) {
79-
$rootScope.$on('$afterRouteChange', function() {
79+
$rootScope.$on('$routeChangeSuccess', function() {
8080
batchLog($route.current ? $route.current.template : null);
8181
});
8282
}]);

src/ng/directive/ngView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c
115115
var lastScope,
116116
onloadExp = attr.onload || '';
117117

118-
scope.$on('$afterRouteChange', update);
118+
scope.$on('$routeChangeSuccess', update);
119119
update();
120120

121121

src/ng/route.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,23 @@ function $RouteProvider(){
230230

231231
/**
232232
* @ngdoc event
233-
* @name angular.module.ng.$route#$beforeRouteChange
233+
* @name angular.module.ng.$route#$routeChangeStart
234234
* @eventOf angular.module.ng.$route
235235
* @eventType broadcast on root scope
236236
* @description
237237
* Broadcasted before a route change. At this point the route services starts
238238
* resolving all of the dependencies needed for the route change to occurs.
239239
* Typically this involves fetching the view template as well as any dependencies
240240
* defined in `resolve` route property. Once all of the dependencies are resolved
241-
* `$afterRouteChange` is fired.
241+
* `$routeChangeSuccess` is fired.
242242
*
243243
* @param {Route} next Future route information.
244244
* @param {Route} current Current route information.
245245
*/
246246

247247
/**
248248
* @ngdoc event
249-
* @name angular.module.ng.$route#$afterRouteChange
249+
* @name angular.module.ng.$route#$routeChangeSuccess
250250
* @eventOf angular.module.ng.$route
251251
* @eventType broadcast on root scope
252252
* @description
@@ -347,7 +347,7 @@ function $RouteProvider(){
347347
$rootScope.$broadcast('$routeUpdate', last);
348348
} else if (next || last) {
349349
forceReload = false;
350-
$rootScope.$broadcast('$beforeRouteChange', next, last);
350+
$rootScope.$broadcast('$routeChangeStart', next, last);
351351
$route.current = next;
352352
if (next) {
353353
if (next.redirectTo) {
@@ -393,7 +393,7 @@ function $RouteProvider(){
393393
next.locals = locals;
394394
copy(next.params, $routeParams);
395395
}
396-
$rootScope.$broadcast('$afterRouteChange', next, last);
396+
$rootScope.$broadcast('$routeChangeSuccess', next, last);
397397
}
398398
}, function(error) {
399399
if (next == $route.current) {

test/ng/directive/ngViewSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ describe('ngView', function() {
266266
});
267267

268268
inject(function($templateCache, $rootScope, $location) {
269-
$rootScope.$on('$beforeRouteChange', logger('$beforeRouteChange'));
270-
$rootScope.$on('$afterRouteChange', logger('$afterRouteChange'));
269+
$rootScope.$on('$routeChangeStart', logger('$routeChangeStart'));
270+
$rootScope.$on('$routeChangeSuccess', logger('$routeChangeSuccess'));
271271
$rootScope.$on('$viewContentLoaded', logger('$viewContentLoaded'));
272272

273273
$templateCache.put('tpl.html', [200, '{{value}}', {}]);
@@ -276,7 +276,7 @@ describe('ngView', function() {
276276

277277
expect(element.text()).toBe('bound-value');
278278
expect(log).toEqual([
279-
'$beforeRouteChange', 'init-ctrl', '$viewContentLoaded', '$afterRouteChange' ]);
279+
'$routeChangeStart', 'init-ctrl', '$viewContentLoaded', '$routeChangeSuccess' ]);
280280
});
281281
});
282282

test/ng/routeSpec.js

+29-24
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ describe('$route', function() {
2626
$routeProvider.when('/Blank', {});
2727
});
2828
inject(function($route, $location, $rootScope) {
29-
$rootScope.$on('$beforeRouteChange', function(event, next, current) {
29+
$rootScope.$on('$routeChangeStart', function(event, next, current) {
3030
log += 'before();';
3131
expect(current).toBe($route.current);
3232
lastRoute = current;
3333
nextRoute = next;
3434
});
35-
$rootScope.$on('$afterRouteChange', function(event, current, last) {
35+
$rootScope.$on('$routeChangeSuccess', function(event, current, last) {
3636
log += 'after();';
3737
expect(current).toBe($route.current);
3838
expect(lastRoute).toBe(last);
@@ -93,7 +93,7 @@ describe('$route', function() {
9393
inject(function($route, $location, $rootScope) {
9494
var callback = jasmine.createSpy('onRouteChange');
9595

96-
$rootScope.$on('$beforeRouteChange', callback);
96+
$rootScope.$on('$routeChangeStart', callback);
9797
$location.path('/test');
9898
$rootScope.$digest();
9999
callback.reset();
@@ -114,7 +114,7 @@ describe('$route', function() {
114114
inject(function($route, $location, $rootScope) {
115115
var onChangeSpy = jasmine.createSpy('onChange');
116116

117-
$rootScope.$on('$beforeRouteChange', onChangeSpy);
117+
$rootScope.$on('$routeChangeStart', onChangeSpy);
118118
expect($route.current).toBeUndefined();
119119
expect(onChangeSpy).not.toHaveBeenCalled();
120120

@@ -139,7 +139,7 @@ describe('$route', function() {
139139
inject(function($route, $location, $rootScope) {
140140
var onChangeSpy = jasmine.createSpy('onChange');
141141

142-
$rootScope.$on('$beforeRouteChange', onChangeSpy);
142+
$rootScope.$on('$routeChangeStart', onChangeSpy);
143143
expect($route.current).toBeUndefined();
144144
expect(onChangeSpy).not.toHaveBeenCalled();
145145

@@ -188,8 +188,8 @@ describe('$route', function() {
188188
});
189189

190190
inject(function($rootScope, $route, $location) {
191-
$rootScope.$on('$beforeRouteChange', routeChangeSpy);
192-
$rootScope.$on('$afterRouteChange', routeChangeSpy);
191+
$rootScope.$on('$routeChangeStart', routeChangeSpy);
192+
$rootScope.$on('$routeChangeSuccess', routeChangeSpy);
193193

194194
$rootScope.$digest();
195195
expect(routeChangeSpy).not.toHaveBeenCalled();
@@ -200,7 +200,7 @@ describe('$route', function() {
200200
});
201201
});
202202

203-
it('should fire $beforeRouteChange and resolve promises', function() {
203+
it('should fire $routeChangeStart and resolve promises', function() {
204204
var deferA,
205205
deferB;
206206

@@ -253,8 +253,13 @@ describe('$route', function() {
253253
inject(function($location, $route, $rootScope) {
254254
var log = '';
255255

256+
<<<<<<< HEAD
256257
$rootScope.$on('$beforeRouteChange', function() { log += 'before();'; });
257258
$rootScope.$on('$routeChangeError', function(e, n, l, reason) { log += 'failed(' + reason + ');'; });
259+
=======
260+
$rootScope.$on('$routeChangeStart', function() { log += 'before();'; });
261+
$rootScope.$on('$routeChangeFailed', function(e, n, l, reason) { log += 'failed(' + reason + ');'; });
262+
>>>>>>> ebebe46... chore($route): rename events
258263

259264
$location.path('/path');
260265
$rootScope.$digest();
@@ -276,8 +281,8 @@ describe('$route', function() {
276281

277282
inject(function($route, $httpBackend, $location, $rootScope) {
278283
var log = '';
279-
$rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.template + ');'});
280-
$rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.template + ');'});
284+
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'});
285+
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'});
281286

282287
$httpBackend.expectGET('r1.html').respond('R1');
283288
$httpBackend.expectGET('r2.html').respond('R2');
@@ -297,7 +302,7 @@ describe('$route', function() {
297302
});
298303

299304

300-
it('should not update $routeParams until $afterRouteChange', function() {
305+
it('should not update $routeParams until $routeChangeSuccess', function() {
301306
module(function($routeProvider) {
302307
$routeProvider.
303308
when('/r1/:id', { template: 'r1.html' }).
@@ -306,8 +311,8 @@ describe('$route', function() {
306311

307312
inject(function($route, $httpBackend, $location, $rootScope, $routeParams) {
308313
var log = '';
309-
$rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before' + toJson($routeParams) + ';'});
310-
$rootScope.$on('$afterRouteChange', function(e, next) { log += '$after' + toJson($routeParams) + ';'});
314+
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before' + toJson($routeParams) + ';'});
315+
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after' + toJson($routeParams) + ';'});
311316

312317
$httpBackend.whenGET('r1.html').respond('R1');
313318
$httpBackend.whenGET('r2.html').respond('R2');
@@ -338,8 +343,8 @@ describe('$route', function() {
338343

339344
inject(function($route, $httpBackend, $location, $rootScope) {
340345
var log = '';
341-
$rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.template + ');'});
342-
$rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.template + ');'});
346+
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.template + ');'});
347+
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.template + ');'});
343348

344349
$httpBackend.expectGET('r1.html').respond('R1');
345350
$httpBackend.expectGET('r2.html').respond('R2');
@@ -371,8 +376,8 @@ describe('$route', function() {
371376
$rootScope.$on('$routeChangeError', function(e, next, last, error) {
372377
log += '$failed(' + next.templateUrl + ', ' + error.status + ');';
373378
});
374-
$rootScope.$on('$beforeRouteChange', function(e, next) { log += '$before(' + next.templateUrl + ');'});
375-
$rootScope.$on('$afterRouteChange', function(e, next) { log += '$after(' + next.templateUrl + ');'});
379+
$rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.templateUrl + ');'});
380+
$rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.templateUrl + ');'});
376381

377382
$httpBackend.expectGET('r1.html').respond(404, 'R1');
378383
$httpBackend.expectGET('r2.html').respond('R2');
@@ -457,7 +462,7 @@ describe('$route', function() {
457462
inject(function($route, $location, $rootScope) {
458463
var onChangeSpy = jasmine.createSpy('onChange');
459464

460-
$rootScope.$on('$beforeRouteChange', onChangeSpy);
465+
$rootScope.$on('$routeChangeStart', onChangeSpy);
461466
expect($route.current).toBeUndefined();
462467
expect(onChangeSpy).not.toHaveBeenCalled();
463468

@@ -563,7 +568,7 @@ describe('$route', function() {
563568
});
564569

565570
inject(function($route, $location, $rootScope, $routeParams) {
566-
$rootScope.$on('$beforeRouteChange', reloaded);
571+
$rootScope.$on('$routeChangeStart', reloaded);
567572
$location.path('/foo');
568573
$rootScope.$digest();
569574
expect(reloaded).toHaveBeenCalled();
@@ -588,8 +593,8 @@ describe('$route', function() {
588593
});
589594

590595
inject(function($route, $location, $rootScope) {
591-
$rootScope.$on('$beforeRouteChange', routeChange);
592-
$rootScope.$on('$afterRouteChange', routeChange);
596+
$rootScope.$on('$routeChangeStart', routeChange);
597+
$rootScope.$on('$routeChangeSuccess', routeChange);
593598
$rootScope.$on('$routeUpdate', routeUpdate);
594599

595600
expect(routeChange).not.toHaveBeenCalled();
@@ -618,8 +623,8 @@ describe('$route', function() {
618623
});
619624

620625
inject(function($route, $location, $rootScope) {
621-
$rootScope.$on('$beforeRouteChange', routeChange);
622-
$rootScope.$on('$afterRouteChange', routeChange);
626+
$rootScope.$on('$routeChangeStart', routeChange);
627+
$rootScope.$on('$routeChangeSuccess', routeChange);
623628

624629
expect(routeChange).not.toHaveBeenCalled();
625630

@@ -693,7 +698,7 @@ describe('$route', function() {
693698
});
694699

695700
inject(function($route, $location, $rootScope, $routeParams) {
696-
$rootScope.$on('$afterRouteChange', routeChangeSpy);
701+
$rootScope.$on('$routeChangeSuccess', routeChangeSpy);
697702

698703
$location.path('/bar/123');
699704
$rootScope.$digest();

0 commit comments

Comments
 (0)