-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(data-table): use iterate differ to optimize rendering #4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
// Swap first and second data in data array | ||
let copiedData = component.dataSource.data.slice(); | ||
let temp = copiedData[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let -> const in both of these
@@ -92,9 +98,13 @@ export class CdkTable implements CollectionViewer { | |||
/** Set of templates that used as the data row containers. */ | |||
@ContentChildren(CdkRowDef) _rowDefinitions: QueryList<CdkRowDef>; | |||
|
|||
constructor(private _changeDetectorRef: ChangeDetectorRef) { | |||
constructor(private _differs: IterableDiffers, | |||
private _changeDetectorRef: ChangeDetectorRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should both of these be readonly as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we've set that precedent, but I can talk with Jeremy about adding it to here and other components as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, they should be readonly
; we started the library before readonly
was a thing and never got in the habit of adding it later
@@ -76,6 +79,9 @@ export class CdkTable implements CollectionViewer { | |||
*/ | |||
private _columnDefinitionsByName = new Map<string, CdkColumnDef>(); | |||
|
|||
/** Differ used to find the changes in the data provided by the data source. */ | |||
private _dataDiffer: IterableDiffer<any> = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we should consider doing before this is released is making it CdkTable<T>
and using the generic throughout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a generic to the CdkTable definition
console.warn('The data table is still in active development ' + | ||
'and should be considered unstable.'); | ||
|
||
// TODO(andrewseguin): Add trackby function input. | ||
this._dataDiffer = this._differs.find([]).create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite follow how this works; why is this find
necessary? Can you not just create an IterableDiffer
directly? Why is the DI system involved?
(probably just needs explanation in comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comment mentioning that we need to find an iterable differ used for array-based iterables. It's the only public API that lets us grab it, no luck instantiating one myself.
097cf5e
to
017a404
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just noticed still needs |
Thanks for catching that, got the readonly in, thought I had changed that already. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.