From ff23527b47aaafa44e7ed73434d647eb40b6a676 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 2 Oct 2018 22:29:01 +0200 Subject: [PATCH] refactor(table): allow readonly array in data source input (#13137) Adds `ReadonlyArray` and `Observable` to the list of accepted types for the `CdkTable.dataSource` input. Fixes #13126. --- src/cdk/table/table.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cdk/table/table.ts b/src/cdk/table/table.ts index 4ce0f934551..b5f2aa7019b 100644 --- a/src/cdk/table/table.ts +++ b/src/cdk/table/table.ts @@ -64,6 +64,13 @@ export interface RowOutlet { viewContainer: ViewContainerRef; } +/** + * Union of the types that can be set as the data source for a `CdkTable`. + * @docs-private + */ +type CdkTableDataSourceInput = DataSource | Observable | T[]> | + ReadonlyArray | T[]; + /** * Provides a handle for the table to grab the view container's ng-container to insert data rows. * @docs-private @@ -310,13 +317,13 @@ export class CdkTable implements AfterContentChecked, CollectionViewer, OnDes * subscriptions registered during the connect process). */ @Input() - get dataSource(): DataSource | Observable | T[] { return this._dataSource; } - set dataSource(dataSource: DataSource | Observable | T[]) { + get dataSource(): CdkTableDataSourceInput { return this._dataSource; } + set dataSource(dataSource: CdkTableDataSourceInput) { if (this._dataSource !== dataSource) { this._switchDataSource(dataSource); } } - private _dataSource: DataSource | Observable | T[] | T[]; + private _dataSource: CdkTableDataSourceInput; /** * Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when' @@ -759,7 +766,7 @@ export class CdkTable implements AfterContentChecked, CollectionViewer, OnDes * render change subscription if one exists. If the data source is null, interpret this by * clearing the row outlet. Otherwise start listening for new data. */ - private _switchDataSource(dataSource: DataSource | Observable | T[]) { + private _switchDataSource(dataSource: CdkTableDataSourceInput) { this._data = []; if (this.dataSource instanceof DataSource) {