Skip to content

Commit 835d9a8

Browse files
authored
Revert "fix(cdk/table): ensure CdkTable updates view with OnPush and trackBy (angular#31451)" (angular#31716)
This reverts commit 5b45df3.
1 parent 5b45df3 commit 835d9a8

File tree

2 files changed

+1
-45
lines changed

2 files changed

+1
-45
lines changed

src/cdk/table/table.spec.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
Type,
1414
ViewChild,
1515
inject,
16-
TrackByFunction,
1716
} from '@angular/core';
1817
import {By} from '@angular/platform-browser';
1918
import {ComponentFixture, TestBed, fakeAsync, flush, waitForAsync} from '@angular/core/testing';
@@ -1996,35 +1995,6 @@ describe('CdkTable', () => {
19961995
expect(noDataRow).toBeTruthy();
19971996
expect(noDataRow.getAttribute('colspan')).toEqual('3');
19981997
});
1999-
2000-
it('should properly update table content when data changes in OnPush component with track by instance', () => {
2001-
setupTableTestApp(WrapNativeTrackByHtmlTableAppOnPush);
2002-
2003-
const data = component.dataSource.data;
2004-
2005-
expectTableToMatchContent(tableElement, [
2006-
['Column A', 'Column B', 'Column C'],
2007-
[data[0].a, data[0].b, data[0].c],
2008-
[data[1].a, data[1].b, data[1].c],
2009-
[data[2].a, data[2].b, data[2].c],
2010-
]);
2011-
2012-
component.dataSource.data = component.dataSource.data.map((data: TestData) => ({
2013-
...data,
2014-
b: `${data.b}-updated`,
2015-
}));
2016-
2017-
fixture.detectChanges();
2018-
2019-
const newData = component.dataSource.data;
2020-
2021-
expectTableToMatchContent(tableElement, [
2022-
['Column A', 'Column B', 'Column C'],
2023-
[newData[0].a, newData[0].b, newData[0].c],
2024-
[newData[1].a, newData[1].b, newData[1].c],
2025-
[newData[2].a, newData[2].b, newData[2].c],
2026-
]);
2027-
});
20281998
});
20291999

20302000
interface TestData {
@@ -3165,7 +3135,7 @@ class TableWithIndirectDescendantDefs {
31653135
@Component({
31663136
selector: 'cdk-table-change-detection-on-push',
31673137
template: `
3168-
<table cdk-table [dataSource]="dataSource" [trackBy]="trackBy">
3138+
<table cdk-table [dataSource]="dataSource">
31693139
<ng-container cdkColumnDef="column_a">
31703140
<th cdk-header-cell *cdkHeaderCellDef> Column A</th>
31713141
<td cdk-cell *cdkCellDef="let row"> {{row.a}}</td>
@@ -3193,7 +3163,6 @@ class TableWithIndirectDescendantDefs {
31933163
})
31943164
class NativeHtmlTableAppOnPush {
31953165
@Input() dataSource: Observable<TestData[]> | null = null;
3196-
@Input() trackBy: TrackByFunction<TestData> | undefined;
31973166
columnsToRender = ['column_a', 'column_b', 'column_c'];
31983167
}
31993168

@@ -3207,17 +3176,6 @@ class WrapNativeHtmlTableAppOnPush {
32073176
dataSource: FakeDataSource = new FakeDataSource();
32083177
}
32093178

3210-
@Component({
3211-
template: `
3212-
<cdk-table-change-detection-on-push [dataSource]="dataSource" [trackBy]="trackBy"></cdk-table-change-detection-on-push>
3213-
`,
3214-
imports: [NativeHtmlTableAppOnPush],
3215-
})
3216-
class WrapNativeTrackByHtmlTableAppOnPush {
3217-
dataSource: FakeDataSource = new FakeDataSource();
3218-
trackBy: TrackByFunction<TestData> = (index: number, data: TestData) => data.a;
3219-
}
3220-
32213179
function getElements(element: Element, query: string): HTMLElement[] {
32223180
return [].slice.call(element.querySelectorAll(query));
32233181
}

src/cdk/table/table.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ export class CdkTable<T>
682682
if (!changes) {
683683
this._updateNoDataRow();
684684
this.contentChanged.next();
685-
this._changeDetectorRef.markForCheck();
686685
return;
687686
}
688687
const viewContainer = this._rowOutlet.viewContainer;
@@ -717,7 +716,6 @@ export class CdkTable<T>
717716

718717
this.contentChanged.next();
719718
this.updateStickyColumnStyles();
720-
this._changeDetectorRef.markForCheck();
721719
}
722720

723721
/** Adds a column definition that was not included as part of the content children. */

0 commit comments

Comments
 (0)