This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(virtualRepeat): Virtual repeat starting off empty #3807 #4112
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,6 +365,12 @@ function VirtualRepeatController($scope, $element, $attrs, $browser, $document, | |
/** @type {number} Most recently seen length of items. */ | ||
this.itemsLength = 0; | ||
|
||
/** | ||
* @type {!Function} Unwatch callback for item size (when md-items-size is | ||
* not specified), or angular.noop otherwise. | ||
*/ | ||
this.unwatchItemSize_ = angular.noop; | ||
|
||
/** | ||
* Presently rendered blocks by repeat index. | ||
* @type {Object<number, !VirtualRepeatController.Block} | ||
|
@@ -407,6 +413,11 @@ VirtualRepeatController.prototype.link_ = | |
|
||
/** @private Attempts to set itemSize by measuring a repeated element in the dom */ | ||
VirtualRepeatController.prototype.readItemSize_ = function() { | ||
if (this.itemSize) { | ||
// itemSize was successfully read in a different asynchronous call. | ||
return; | ||
} | ||
|
||
this.items = this.repeatListExpression(this.$scope); | ||
this.parentNode = this.$element[0].parentNode; | ||
var block = this.getBlock_(0); | ||
|
@@ -430,14 +441,22 @@ VirtualRepeatController.prototype.readItemSize_ = function() { | |
VirtualRepeatController.prototype.containerUpdated = function() { | ||
// If itemSize is unknown, attempt to measure it. | ||
if (!this.itemSize) { | ||
this.$$rAF(angular.bind(this, this.readItemSize_)); | ||
this.unwatchItemSize_ = this.$scope.$watch( | ||
this.repeatListExpression, | ||
angular.bind(this, function(items) { | ||
if (items && items.length) { | ||
this.$$rAF(angular.bind(this, this.readItemSize_)); | ||
} | ||
})); | ||
this.$scope.$digest(); | ||
|
||
return; | ||
} else if (!this.sized) { | ||
this.items = this.repeatListExpression(this.$scope); | ||
} | ||
|
||
if (!this.sized) { | ||
this.unwatchItemSize_(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think there should be a test for the watcher being deregistered? |
||
this.sized = true; | ||
this.$scope.$watchCollection(this.repeatListExpression, | ||
angular.bind(this, this.virtualRepeatUpdate_)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could be
function(): void