-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(table): update implicit when using trackby #7893
Conversation
src/cdk/table/table.ts
Outdated
@@ -68,6 +68,14 @@ export const CDK_TABLE_TEMPLATE = ` | |||
<ng-container headerRowPlaceholder></ng-container> | |||
<ng-container rowPlaceholder></ng-container>`; | |||
|
|||
/** Class used to conveniently type the embedded view ref for rows with a context. */ | |||
abstract class RowViewRef<T> extends EmbeddedViewRef<CdkCellOutletRowContext<T>> { } |
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 this be @docs-private
?
src/cdk/table/table.ts
Outdated
abstract class RowViewRef<T> extends EmbeddedViewRef<CdkCellOutletRowContext<T>> { } | ||
|
||
/** Tuple used to pair together an iterable differ change record with the view it affects. */ | ||
class RowRecordViewTuple<T> { |
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.
@docs-private
?
src/cdk/table/table.ts
Outdated
|
||
/** Tuple used to pair together an iterable differ change record with the view it affects. */ | ||
class RowRecordViewTuple<T> { | ||
constructor(public record: IterableChangeRecord<T>, public view: RowViewRef<T>) {} |
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 record
and view
be public, documented properties?
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.
Also neither seem to be the most descriptive names
src/cdk/table/table.ts
Outdated
private _renderRowChanges() { | ||
const changes = this._dataDiffer.diff(this._data); | ||
if (!changes) { return; } | ||
|
||
const insertOrMovedRowTuples: RowRecordViewTuple<T>[] = []; |
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.
Add comment that explains why you keep track of the inserted or moved tuples?
src/cdk/table/table.ts
Outdated
|
||
// Update rows that did not get added/removed/moved but may have had their identity changed, | ||
// e.g. if trackBy matched data on the property 'id' but the property 'name' was changed. | ||
changes.forEachIdentityChange((record: any) => { |
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.
Why any
?
src/cdk/table/table.ts
Outdated
} | ||
|
||
/** | ||
* Updates the context for each row to reflect any data changes that may have caused | ||
* Updates the meta context for each row to reflect any data changes that may have caused |
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.
"Meta context"?
src/cdk/table/table.ts
Outdated
} | ||
|
||
/** Updates the row view ref with the implicit data assigned to the row. */ | ||
private _updateRowImplicitContext(view: RowViewRef<T>, record: IterableChangeRecord<any>) { |
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 think the code would be easier to read without this method (just having the assignment inline). Any reason to keep it a method?
src/cdk/table/table.ts
Outdated
} | ||
}); | ||
|
||
this._updateRowContext(); | ||
// Update the row's implicit context for each inserted or moved row. |
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.
"Update the $implicit property for the binding context for inserted and moved rows"
36257d8
to
3d09957
Compare
3d09957
to
c2e9469
Compare
tl;dr: Took out logic about insertions and moves. Just updating for identity changes since it addresses the issue. Reducing the scope of this PR - was looking at Angular's If another issue comes in about bad |
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, one syntax comment
Add the "merge-ready" label when done
src/cdk/table/table.spec.ts
Outdated
// Change each item reference to show that the trackby is checking the index. | ||
// Otherwise this would cause them all to be removed/added. | ||
trackByComponent.dataSource.data = trackByComponent.dataSource.data | ||
.map(item => { return {a: item.a, b: item.b, c: item.c}; }); |
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.
.map(item => ({a: item.a, b: item.b, c: item.c}));
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. |
The table should make sure that if it wants to re-use a row, then it's implicit data should be accurate. It's possible that a row's data is entirely changed but the row was re-used due to a loose
trackBy
.Fixes #7877