mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(table): allow readonly array in data source input (#13137)
Adds `ReadonlyArray` and `Observable<ReadonlyArray>` to the list of accepted types for the `CdkTable.dataSource` input. Fixes #13126.
This commit is contained in:
committed by
vivian-hu
parent
f5dd24aab5
commit
ff23527b47
+11
-4
@@ -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<T> = DataSource<T> | Observable<ReadonlyArray<T> | T[]> |
|
||||
ReadonlyArray<T> | 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<T> implements AfterContentChecked, CollectionViewer, OnDes
|
||||
* subscriptions registered during the connect process).
|
||||
*/
|
||||
@Input()
|
||||
get dataSource(): DataSource<T> | Observable<T[]> | T[] { return this._dataSource; }
|
||||
set dataSource(dataSource: DataSource<T> | Observable<T[]> | T[]) {
|
||||
get dataSource(): CdkTableDataSourceInput<T> { return this._dataSource; }
|
||||
set dataSource(dataSource: CdkTableDataSourceInput<T>) {
|
||||
if (this._dataSource !== dataSource) {
|
||||
this._switchDataSource(dataSource);
|
||||
}
|
||||
}
|
||||
private _dataSource: DataSource<T> | Observable<T[]> | T[] | T[];
|
||||
private _dataSource: CdkTableDataSourceInput<T>;
|
||||
|
||||
/**
|
||||
* Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when'
|
||||
@@ -759,7 +766,7 @@ export class CdkTable<T> 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<T> | Observable<T[]> | T[]) {
|
||||
private _switchDataSource(dataSource: CdkTableDataSourceInput<T>) {
|
||||
this._data = [];
|
||||
|
||||
if (this.dataSource instanceof DataSource) {
|
||||
|
||||
Reference in New Issue
Block a user