Skip to content
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(VirtualScroll): initialise differ with trackByFn #11492

Merged
merged 2 commits into from
May 4, 2017
Merged

fix(VirtualScroll): initialise differ with trackByFn #11492

merged 2 commits into from
May 4, 2017

Conversation

masimplo
Copy link
Contributor

@masimplo masimplo commented May 3, 2017

Short description of what this resolves:

VirtualScroll trackByFn has no effect due to the random order that Angular interprets input values.

Changes proposed in this pull request:

Virtual TrackByFn is changed into as setter input, that redefines the change detection mechanism as soon as trackBy is parsed, to take into account the provided function

Ionic Version: 3.x

Fixes: #7531
Related to #11294

if (!isPresent(val)) return;
this._virtualTrackBy = val;
if (isPresent(this._records)) {
this._differ = this._iterableDiffers.find(this._records).create(this.virtualTrackBy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the this._differ creation logic to a new function? maybe _updateDiffer. it is duplicated in here and virtualScroll.

Also, can you add a new-line after @input()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if you prefer I overwrite last commit or add a new one, so I went with the safer choice.

@manucorporat manucorporat merged commit 299a68b into ionic-team:master May 4, 2017
@pluscubed
Copy link
Contributor

The second commit appears to break the fix - the virtualScroll input setter is called first, which calls _updateDiffer and initializes_differ with the default virtualTrackBy function. When the virtualTrackBy input setter is called later, _differ is no longer blank.

@masimplo
Copy link
Contributor Author

Oh yes. You are correct. isBlank(this.differ) check should not be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants