revert: refactor(router): don't run the change detection every time an outlet is activated

This reverts commit 198edb3109.
This commit is contained in:
Matias Niemelä
2017-05-18 11:28:39 -07:00
parent 6531806996
commit a0a6029915
11 changed files with 232 additions and 299 deletions

View File

@ -120,10 +120,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'parent/:id',
component: Parent,
children: [
{path: 'child1', component: Child1},
{path: 'child2', component: Child2},
]
children:
[{path: 'child1', component: Child1}, {path: 'child2', component: Child2}]
}]);
router.navigateByUrl('/parent/1/child1');
@ -133,18 +131,13 @@ describe('Integration', () => {
advance(fixture);
expect(location.path()).toEqual('/parent/2/child2');
expect(log).toEqual([
{id: '1'},
'child1 destroy',
{id: '2'},
'child2 constructor',
]);
expect(log).toEqual([{id: '1'}, 'child1 destroy', {id: '2'}, 'child2 constructor']);
})));
});
it('should execute navigations serialy',
fakeAsync(inject([Router, Location], (router: Router) => {
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([
@ -209,7 +202,7 @@ describe('Integration', () => {
router.resetConfig([{
path: 'child',
component: OutletInNgIf,
component: LinkInNgIf,
children: [{path: 'simple', component: SimpleCmp}]
}]);
@ -219,10 +212,10 @@ describe('Integration', () => {
expect(location.path()).toEqual('/child/simple');
})));
it('should work when an outlet is added/removed', fakeAsync(() => {
it('should work when an outlet is in an ngIf (and is removed)', fakeAsync(() => {
@Component({
selector: 'someRoot',
template: `[<div *ngIf="cond"><router-outlet></router-outlet></div>]`
template: `<div *ngIf="cond"><router-outlet></router-outlet></div>`
})
class RootCmpWithLink {
cond: boolean = true;
@ -230,25 +223,26 @@ describe('Integration', () => {
TestBed.configureTestingModule({declarations: [RootCmpWithLink]});
const router: Router = TestBed.get(Router);
const location: Location = TestBed.get(Location);
const fixture = createRoot(router, RootCmpWithLink);
router.resetConfig([
{path: 'simple', component: SimpleCmp},
{path: 'blank', component: BlankCmp},
]);
router.resetConfig(
[{path: 'simple', component: SimpleCmp}, {path: 'blank', component: BlankCmp}]);
router.navigateByUrl('/simple');
advance(fixture);
expect(fixture.nativeElement).toHaveText('[simple]');
expect(location.path()).toEqual('/simple');
fixture.componentInstance.cond = false;
const instance = fixture.componentInstance;
instance.cond = false;
advance(fixture);
expect(fixture.nativeElement).toHaveText('[]');
fixture.componentInstance.cond = true;
let recordedError: any = null;
router.navigateByUrl('/blank') !.catch(e => recordedError = e);
advance(fixture);
expect(fixture.nativeElement).toHaveText('[simple]');
expect(recordedError.message).toEqual('Cannot find primary outlet to load \'BlankCmp\'');
}));
it('should update location when navigating', fakeAsync(() => {
@ -3236,17 +3230,15 @@ describe('Integration', () => {
shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null { return null; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null !; }
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
if (future.routeConfig !== curr.routeConfig) {
return false;
}
if (Object.keys(future.params).length !== Object.keys(curr.params).length) {
} else if (Object.keys(future.params).length !== Object.keys(curr.params).length) {
return false;
} else {
return Object.keys(future.params).every(k => future.params[k] === curr.params[k]);
}
return Object.keys(future.params).every(k => future.params[k] === curr.params[k]);
}
}
@ -3257,12 +3249,8 @@ describe('Integration', () => {
router.routeReuseStrategy = new AttachDetachReuseStrategy();
router.resetConfig([
{
path: 'a',
component: TeamCmp,
children: [{path: 'b', component: SimpleCmp}],
},
{path: 'c', component: UserCmp},
{path: 'a', component: TeamCmp, children: [{path: 'b', component: SimpleCmp}]},
{path: 'c', component: UserCmp}
]);
router.navigateByUrl('/a/b');
@ -3471,7 +3459,7 @@ class RelativeLinkInIfCmp {
@Component(
{selector: 'child', template: '<div *ngIf="alwaysTrue"><router-outlet></router-outlet></div>'})
class OutletInNgIf {
class LinkInNgIf {
alwaysTrue = true;
}
@ -3550,7 +3538,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
QueryParamsAndFragmentCmp,
StringLinkButtonCmp,
WrapperCmp,
OutletInNgIf,
LinkInNgIf,
ComponentRecordingRoutePathAndUrl,
RouteCmp,
RootCmp,
@ -3576,7 +3564,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
QueryParamsAndFragmentCmp,
StringLinkButtonCmp,
WrapperCmp,
OutletInNgIf,
LinkInNgIf,
ComponentRecordingRoutePathAndUrl,
RouteCmp,
RootCmp,
@ -3604,7 +3592,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
QueryParamsAndFragmentCmp,
StringLinkButtonCmp,
WrapperCmp,
OutletInNgIf,
LinkInNgIf,
ComponentRecordingRoutePathAndUrl,
RouteCmp,
RootCmp,