-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(cdk/scrolling): virtual list not updating when source array is mutated #14639
base: main
Are you sure you want to change the base?
Conversation
9fd7f78
to
772d621
Compare
* Current differ data source. Needs to be kept in a separate | ||
* property so we can run change detection on it. | ||
*/ | ||
private _differDataSource: DifferDataSource<T> | null = 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.
I don't love this... it seems a little tricky to manage. Would it make sense to change all DataSources to have these new methods? They could just be no-op by default
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 I'm not a fan of it either, but it was cleaner than doing it inside the virtual repeater. An alternative can be to roll this functionality into the ArrayDataSource
.
772d621
to
eb25578
Compare
Why don't we just add the methods to @jelbourn WDYT? |
eb25578
to
e206d12
Compare
Is the issue fixed? |
e206d12
to
2df2b2c
Compare
2df2b2c
to
cc127ab
Compare
can we approve the fix now? even thou it is not "perfect" it seems to me it does not impact other areas. later it could be improved but at the moment we need the functionality which is even in basic ion-list (in ionic). |
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 having this sort of DataSource seems neat - users get confused about how they make a data source emit when its based on an array but they keep mutating the contents of their array.
Could the _iterable
property be changed to public so that users can set a different array, which would trigger a doCheck
?
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.
.
…tated When an array is passed to `cdkVirtualFor`, it falls back to creating an `ArrayDataSource` which won't emit if the array has changed. Since the intention of the `cdkVirtualFor` is to be (more or less) a drop-in alternative for `ngFor`, it is expected that it'll update if the data has changed. These changes add a new type of data source that will allow us to detect changes on the data and to update the view. Fixes angular#14635. Fixes angular#14501.
cc127ab
to
42ed989
Compare
When an array is passed to
cdkVirtualFor
, it falls back to creating anArrayDataSource
which won't emit if the array has changed. Since the intention of thecdkVirtualFor
is to be (more or less) a drop-in alternative forngFor
, it is expected that it'll update if the data has changed. These changes add a new type of data source that will allow us to detect changes on the data and to update the view.Note: I went with adding a new type of data source, rather than using the iterable differ directly, because it would've meant having to maintain two different code paths inside the directive. Furthermore, I can see this being useful in
cdk/tree
andcdk/table
as well.Fixes #14635.
Fixes #14501.