Skip to content

Commit 925474d

Browse files
committed
refactor(cdk/table): change deprecated APIs for v12
Changes the APIs that were marked as deprecated for v12. BREAKING CHANGES: * `_viewRepeater`, `_coalescedStyleScheduler`, `_stickyPositioningListener` and `_viewportRuler` parameters of the `CdkTable` constructor are now required. * `_coalescedStyleScheduler` parameter of the `StickyStyler` constructor is now required.
1 parent aa7dc00 commit 925474d

File tree

4 files changed

+37
-86
lines changed

4 files changed

+37
-86
lines changed

src/cdk/schematics/ng-update/data/constructor-checks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export type ConstructorChecksUpgradeData = string;
1717
* automatically through type checking.
1818
*/
1919
export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
20+
[TargetVersion.V12]: [
21+
{
22+
pr: 'https://github.com/angular/components/pull/21876',
23+
changes: ['CdkTable', 'StickyStyler']
24+
}
25+
],
2026
[TargetVersion.V11]: [
2127
{
2228
pr: 'https://github.com/angular/components/pull/20454',

src/cdk/table/sticky-styler.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ export class StickyStyler {
4848
constructor(private _isNativeHtmlTable: boolean,
4949
private _stickCellCss: string,
5050
public direction: Direction,
51-
/**
52-
* @deprecated `_coalescedStyleScheduler` parameter to become required.
53-
* @breaking-change 11.0.0
54-
*/
55-
private _coalescedStyleScheduler?: _CoalescedStyleScheduler,
51+
private _coalescedStyleScheduler: _CoalescedStyleScheduler,
5652
private _isBrowser = true,
5753
private readonly _needsPositionStickyOnElement = true,
5854
private readonly _positionListener?: StickyPositioningListener) {
@@ -86,7 +82,7 @@ export class StickyStyler {
8682
}
8783

8884
// Coalesce with sticky row/column updates (and potentially other changes like column resize).
89-
this._scheduleStyleChanges(() => {
85+
this._coalescedStyleScheduler.schedule(() => {
9086
for (const element of elementsToClear) {
9187
this._removeStickyStyle(element, stickyDirections);
9288
}
@@ -128,7 +124,7 @@ export class StickyStyler {
128124
const firstStickyEnd = stickyEndStates.indexOf(true);
129125

130126
// Coalesce with sticky row updates (and potentially other changes like column resize).
131-
this._scheduleStyleChanges(() => {
127+
this._coalescedStyleScheduler.schedule(() => {
132128
const isRtl = this.direction === 'rtl';
133129
const start = isRtl ? 'right' : 'left';
134130
const end = isRtl ? 'left' : 'right';
@@ -213,7 +209,7 @@ export class StickyStyler {
213209

214210
// Coalesce with other sticky row updates (top/bottom), sticky columns updates
215211
// (and potentially other changes like column resize).
216-
this._scheduleStyleChanges(() => {
212+
this._coalescedStyleScheduler.schedule(() => {
217213
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
218214
if (!states[rowIndex]) {
219215
continue;
@@ -250,7 +246,7 @@ export class StickyStyler {
250246
const tfoot = tableElement.querySelector('tfoot')!;
251247

252248
// Coalesce with other sticky updates (and potentially other changes like column resize).
253-
this._scheduleStyleChanges(() => {
249+
this._coalescedStyleScheduler.schedule(() => {
254250
if (stickyStates.some(state => !state)) {
255251
this._removeStickyStyle(tfoot, ['bottom']);
256252
} else {
@@ -392,17 +388,4 @@ export class StickyStyler {
392388

393389
return positions;
394390
}
395-
396-
/**
397-
* Schedules styles to be applied when the style scheduler deems appropriate.
398-
* @breaking-change 11.0.0 This method can be removed in favor of calling
399-
* `CoalescedStyleScheduler.schedule` directly once the scheduler is a required parameter.
400-
*/
401-
private _scheduleStyleChanges(changes: () => void) {
402-
if (this._coalescedStyleScheduler) {
403-
this._coalescedStyleScheduler.schedule(changes);
404-
} else {
405-
changes();
406-
}
407-
}
408391
}

src/cdk/table/table.ts

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -500,22 +500,13 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
500500
protected readonly _elementRef: ElementRef, @Attribute('role') role: string,
501501
@Optional() protected readonly _dir: Directionality, @Inject(DOCUMENT) _document: any,
502502
private _platform: Platform,
503-
504-
/**
505-
* @deprecated `_coalescedStyleScheduler`, `_viewRepeater` and `_viewportRuler`
506-
* parameters to become required.
507-
* @breaking-change 11.0.0
508-
*/
509-
@Optional() @Inject(_VIEW_REPEATER_STRATEGY)
510-
protected readonly _viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>>,
511-
@Optional() @Inject(_COALESCED_STYLE_SCHEDULER)
512-
protected readonly _coalescedStyleScheduler?: _CoalescedStyleScheduler,
513-
@Optional() @SkipSelf() @Inject(STICKY_POSITIONING_LISTENER)
514-
protected readonly _stickyPositioningListener?: StickyPositioningListener,
515-
// Optional for backwards compatibility. The viewport ruler is provided in root. Therefore,
516-
// this property will never be null.
517-
// tslint:disable-next-line: lightweight-tokens
518-
@Optional() private readonly _viewportRuler?: ViewportRuler) {
503+
@Inject(_VIEW_REPEATER_STRATEGY)
504+
protected readonly _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>,
505+
@Inject(_COALESCED_STYLE_SCHEDULER)
506+
protected readonly _coalescedStyleScheduler: _CoalescedStyleScheduler,
507+
@SkipSelf() @Inject(STICKY_POSITIONING_LISTENER)
508+
protected readonly _stickyPositioningListener: StickyPositioningListener,
509+
private readonly _viewportRuler: ViewportRuler) {
519510
if (!role) {
520511
this._elementRef.nativeElement.setAttribute('role', 'grid');
521512
}
@@ -538,14 +529,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
538529
return this.trackBy ? this.trackBy(dataRow.dataIndex, dataRow.data) : dataRow;
539530
});
540531

541-
// Table cell dimensions may change after resizing the window. Signal the sticky styler to
542-
// refresh its cache of cell widths the next time sticky styles are updated.
543-
// @breaking-change 11.0.0 Remove null check for _viewportRuler once it's a required parameter.
544-
if (this._viewportRuler) {
545-
this._viewportRuler.change().pipe(takeUntil(this._onDestroy)).subscribe(() => {
546-
this._forceRecalculateCellWidths = true;
547-
});
548-
}
532+
this._viewportRuler.change().pipe(takeUntil(this._onDestroy)).subscribe(() => {
533+
this._forceRecalculateCellWidths = true;
534+
});
549535
}
550536

551537
ngAfterContentChecked() {
@@ -626,38 +612,16 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
626612
}
627613
const viewContainer = this._rowOutlet.viewContainer;
628614

629-
// @breaking-change 11.0.0 Remove null check for `_viewRepeater` and the
630-
// `else` clause once `_viewRepeater` is turned into a required parameter.
631-
if (this._viewRepeater) {
632-
this._viewRepeater.applyChanges(
633-
changes,
634-
viewContainer,
635-
(record: IterableChangeRecord<RenderRow<T>>,
636-
_adjustedPreviousIndex: number|null,
637-
currentIndex: number|null) => this._getEmbeddedViewArgs(record.item, currentIndex!),
638-
(record) => record.item.data,
639-
(change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => {
640-
if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) {
641-
this._renderCellTemplateForItem(change.record.item.rowDef, change.context);
642-
}
643-
});
644-
} else {
645-
changes.forEachOperation(
646-
(record: IterableChangeRecord<RenderRow<T>>, prevIndex: number|null,
647-
currentIndex: number|null) => {
648-
if (record.previousIndex == null) {
649-
const renderRow = record.item;
650-
const rowDef = renderRow.rowDef;
651-
const context: RowContext<T> = {$implicit: renderRow.data};
652-
this._renderRow(this._rowOutlet, rowDef, currentIndex!, context);
653-
} else if (currentIndex == null) {
654-
viewContainer.remove(prevIndex!);
655-
} else {
656-
const view = <RowViewRef<T>>viewContainer.get(prevIndex!);
657-
viewContainer.move(view!, currentIndex);
658-
}
659-
});
660-
}
615+
this._viewRepeater.applyChanges(changes, viewContainer,
616+
(record: IterableChangeRecord<RenderRow<T>>,
617+
_adjustedPreviousIndex: number|null,
618+
currentIndex: number|null) => this._getEmbeddedViewArgs(record.item, currentIndex!),
619+
(record) => record.item.data,
620+
(change: _ViewRepeaterItemChange<RenderRow<T>, RowContext<T>>) => {
621+
if (change.operation === _ViewRepeaterOperation.INSERTED && change.context) {
622+
this._renderCellTemplateForItem(change.record.item.rowDef, change.context);
623+
}
624+
});
661625

662626
// Update the meta context of a row's context data (index, count, first, last, ...)
663627
this._updateRowIndexContext();

tools/public_api_guard/cdk/table.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export declare class CdkRowDef<T> extends BaseRowDef {
193193

194194
export declare class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDestroy, OnInit {
195195
protected readonly _changeDetectorRef: ChangeDetectorRef;
196-
protected readonly _coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined;
196+
protected readonly _coalescedStyleScheduler: _CoalescedStyleScheduler;
197197
_contentColumnDefs: QueryList<CdkColumnDef>;
198198
_contentFooterRowDefs: QueryList<CdkFooterRowDef>;
199199
_contentHeaderRowDefs: QueryList<CdkHeaderRowDef>;
@@ -209,8 +209,8 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
209209
_noDataRow: CdkNoDataRow;
210210
_noDataRowOutlet: NoDataRowOutlet;
211211
_rowOutlet: DataRowOutlet;
212-
protected readonly _stickyPositioningListener?: StickyPositioningListener | undefined;
213-
protected readonly _viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>> | undefined;
212+
protected readonly _stickyPositioningListener: StickyPositioningListener;
213+
protected readonly _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>;
214214
get dataSource(): CdkTableDataSourceInput<T>;
215215
set dataSource(dataSource: CdkTableDataSourceInput<T>);
216216
get fixedLayout(): boolean;
@@ -225,8 +225,7 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
225225
start: number;
226226
end: number;
227227
}>;
228-
constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform,
229-
_viewRepeater?: _ViewRepeater<T, RenderRow<T>, RowContext<T>> | undefined, _coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined, _stickyPositioningListener?: StickyPositioningListener | undefined, _viewportRuler?: ViewportRuler | undefined);
228+
constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform, _viewRepeater: _ViewRepeater<T, RenderRow<T>, RowContext<T>>, _coalescedStyleScheduler: _CoalescedStyleScheduler, _stickyPositioningListener: StickyPositioningListener, _viewportRuler: ViewportRuler);
230229
_getRenderedRows(rowOutlet: RowOutlet): HTMLElement[];
231230
_getRowDefs(data: T, dataIndex: number): CdkRowDef<T>[];
232231
addColumnDef(columnDef: CdkColumnDef): void;
@@ -248,7 +247,7 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
248247
static ngAcceptInputType_fixedLayout: BooleanInput;
249248
static ngAcceptInputType_multiTemplateDataRows: BooleanInput;
250249
static ɵcmp: i0.ɵɵComponentDefWithMeta<CdkTable<any>, "cdk-table, table[cdk-table]", ["cdkTable"], { "trackBy": "trackBy"; "dataSource": "dataSource"; "multiTemplateDataRows": "multiTemplateDataRows"; "fixedLayout": "fixedLayout"; }, {}, ["_noDataRow", "_contentColumnDefs", "_contentRowDefs", "_contentHeaderRowDefs", "_contentFooterRowDefs"], ["caption", "colgroup, col"]>;
251-
static ɵfac: i0.ɵɵFactoryDef<CdkTable<any>, [null, null, null, { attribute: "role"; }, { optional: true; }, null, null, { optional: true; }, { optional: true; }, { optional: true; skipSelf: true; }, { optional: true; }]>;
250+
static ɵfac: i0.ɵɵFactoryDef<CdkTable<any>, [null, null, null, { attribute: "role"; }, { optional: true; }, null, null, null, null, { skipSelf: true; }, null]>;
252251
}
253252

254253
export declare class CdkTableModule {
@@ -344,8 +343,7 @@ export declare type StickySize = number | null | undefined;
344343

345344
export declare class StickyStyler {
346345
direction: Direction;
347-
constructor(_isNativeHtmlTable: boolean, _stickCellCss: string, direction: Direction,
348-
_coalescedStyleScheduler?: _CoalescedStyleScheduler | undefined, _isBrowser?: boolean, _needsPositionStickyOnElement?: boolean, _positionListener?: StickyPositioningListener | undefined);
346+
constructor(_isNativeHtmlTable: boolean, _stickCellCss: string, direction: Direction, _coalescedStyleScheduler: _CoalescedStyleScheduler, _isBrowser?: boolean, _needsPositionStickyOnElement?: boolean, _positionListener?: StickyPositioningListener | undefined);
349347
_addStickyStyle(element: HTMLElement, dir: StickyDirection, dirValue: number, isBorderElement: boolean): void;
350348
_getCalculatedZIndex(element: HTMLElement): string;
351349
_getCellWidths(row: HTMLElement, recalculateCellWidths?: boolean): number[];

0 commit comments

Comments
 (0)