Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

fix(virtual-repeat): Prevent nested calls to virtualRepeatUpdate_ #5009

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/virtualRepeat/virtual-repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ function VirtualRepeatController($scope, $element, $attrs, $browser, $document,
/** @type {boolean} Whether this is the first time that items are rendered. */
this.isFirstRender = true;

/**
* @private {boolean} Whether the items in the list are already being updated. Used to prevent
* nested calls to virtualRepeatUpdate_.
*/
this.isVirtualRepeatUpdating_ = false;

/** @type {number} Most recently seen length of items. */
this.itemsLength = 0;

Expand Down Expand Up @@ -543,7 +549,11 @@ VirtualRepeatController.prototype.containerUpdated = function() {
this.unwatchItemSize_();
this.sized = true;
this.$scope.$watchCollection(this.repeatListExpression,
angular.bind(this, this.virtualRepeatUpdate_));
angular.bind(this, function(items, oldItems) {
if (!this.isVirtualRepeatUpdating_) {
this.virtualRepeatUpdate_(items, oldItems);
}
}));
}

this.updateIndexes_();
Expand Down Expand Up @@ -574,6 +584,8 @@ VirtualRepeatController.prototype.getItemSize = function() {
* @private
*/
VirtualRepeatController.prototype.virtualRepeatUpdate_ = function(items, oldItems) {
this.isVirtualRepeatUpdating_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a blank line after this and one before the related line at the bottom of this method.


var itemsLength = items && items.length || 0;
var lengthChanged = false;

Expand Down Expand Up @@ -664,6 +676,8 @@ VirtualRepeatController.prototype.virtualRepeatUpdate_ = function(items, oldItem

this.startIndex = this.newStartIndex;
this.endIndex = this.newEndIndex;

this.isVirtualRepeatUpdating_ = false;
};


Expand Down