Skip to content

Commit

Permalink
perf(table): cell references not being cleaned up on destroy (#5809)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and kara committed Jul 20, 2017
1 parent 0adb2ab commit df1ddee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/cdk/table/table.spec.ts
Expand Up @@ -155,6 +155,19 @@ describe('CdkTable', () => {
expect(changedRows[2].getAttribute('initialIndex')).toBe(null);
});

it('should clear the row view containers on destroy', () => {
const rowPlaceholder = fixture.componentInstance.table._rowPlaceholder.viewContainer;
const headerPlaceholder = fixture.componentInstance.table._headerRowPlaceholder.viewContainer;

spyOn(rowPlaceholder, 'clear').and.callThrough();
spyOn(headerPlaceholder, 'clear').and.callThrough();

fixture.destroy();

expect(rowPlaceholder.clear).toHaveBeenCalled();
expect(headerPlaceholder.clear).toHaveBeenCalled();
});

describe('with trackBy', () => {

let trackByComponent: TrackByCdkTableApp;
Expand Down
7 changes: 5 additions & 2 deletions src/cdk/table/table.ts
Expand Up @@ -27,7 +27,7 @@ import {
TrackByFunction,
ViewChild,
ViewContainerRef,
ViewEncapsulation
ViewEncapsulation,
} from '@angular/core';
import {CollectionViewer, DataSource} from './data-source';
import {CdkCellOutlet, CdkCellOutletRowContext, CdkHeaderRowDef, CdkRowDef} from './row';
Expand Down Expand Up @@ -175,8 +175,11 @@ export class CdkTable<T> implements CollectionViewer {
}

ngOnDestroy() {
this._rowPlaceholder.viewContainer.clear();
this._headerRowPlaceholder.viewContainer.clear();
this._onDestroy.next();
this._onDestroy.complete();

if (this.dataSource) {
this.dataSource.disconnect(this);
}
Expand Down Expand Up @@ -343,7 +346,7 @@ export class CdkTable<T> implements CollectionViewer {
viewRef.context.first = index === 0;
viewRef.context.last = index === count - 1;
viewRef.context.even = index % 2 === 0;
viewRef.context.odd = index % 2 !== 0;
viewRef.context.odd = !viewRef.context.even;
}
}

Expand Down

0 comments on commit df1ddee

Please sign in to comment.