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

Commit 1013423

Browse files
kseamonjelbourn
authored andcommitted
fix(virtualRepeat): Broken demos relating to size computation
Fix test timeouts (something about the way I spied on debounce). Closes #6167
1 parent 36b03f2 commit 1013423

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/components/virtualRepeat/virtual-repeater.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,26 @@ function VirtualRepeatContainerController(
132132
// make a best effort at re-measuring as it changes.
133133
var boundUpdateSize = angular.bind(this, this.updateSize);
134134

135-
$$rAF(function() {
135+
$$rAF(angular.bind(this, function() {
136136
boundUpdateSize();
137137

138138
var debouncedUpdateSize = $mdUtil.debounce(boundUpdateSize, 10, null, false);
139139
var jWindow = angular.element($window);
140140

141+
// Make one more attempt to get the size if it is 0.
142+
// This is not by any means a perfect approach, but there's really no
143+
// silver bullet here.
144+
if (!this.size) {
145+
debouncedUpdateSize();
146+
}
147+
141148
jWindow.on('resize', debouncedUpdateSize);
142149
$scope.$on('$destroy', function() {
143150
jWindow.off('resize', debouncedUpdateSize);
144151
});
145152

146153
$scope.$on('$md-resize', boundUpdateSize);
147-
});
154+
}));
148155
}
149156

150157

@@ -187,6 +194,7 @@ VirtualRepeatContainerController.prototype.updateSize = function() {
187194
this.size = this.isHorizontal()
188195
? this.$element[0].clientWidth
189196
: this.$element[0].clientHeight;
197+
190198
this.repeater && this.repeater.containerUpdated();
191199
};
192200

src/components/virtualRepeat/virtual-repeater.spec.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('<md-virtual-repeat>', function() {
2222
ITEM_SIZE = 10;
2323

2424
beforeEach(inject(function(
25-
_$$rAF_, _$compile_, _$document_, _$mdUtil_, $rootScope, _$window_, _$material_) {
25+
_$$rAF_, _$compile_, _$document_, _$mdUtil_, $rootScope, _$timeout_, _$window_, _$material_) {
2626
repeater = angular.element(REPEATER_HTML);
2727
container = angular.element(CONTAINER_HTML).append(repeater);
2828
component = null;
@@ -31,6 +31,7 @@ describe('<md-virtual-repeat>', function() {
3131
$mdUtil = _$mdUtil_;
3232
$compile = _$compile_;
3333
$document = _$document_;
34+
$timeout = _$timeout_;
3435
$window = _$window_;
3536
scope = $rootScope.$new();
3637
scope.startIndex = 0;
@@ -582,13 +583,30 @@ describe('<md-virtual-repeat>', function() {
582583
expect(offsetter.children().length).toBe(43);
583584
});
584585

586+
it('makes a second attempt to measure the size if it starts out at 0',
587+
function() {
588+
// Create the repeater before appending it to the body.
589+
scope.items = createItems(100);
590+
component = $compile(container)(scope);
591+
$material.flushOutstandingAnimations();
592+
angular.element($document[0].body).append(container);
593+
offsetter = angular.element(component[0].querySelector('.md-virtual-repeat-offsetter'));
594+
595+
// Expect 3 children (0 + 3 extra).
596+
expect(offsetter.children().length).toBe(3);
597+
598+
// Expect it to remeasure using debounce.
599+
$timeout.flush();
600+
601+
// Expect 13 children (10 + 3 extra).
602+
expect(offsetter.children().length).toBe(13);
603+
});
604+
585605
/**
586606
* Facade to access transform properly even when jQuery is used;
587607
* since jQuery's css function is obtaining the computed style (not wanted)
588608
*/
589609
function getTransform(target) {
590610
return target[0].style.webkitTransform || target.css('transform');
591611
}
592-
593-
594612
});

0 commit comments

Comments
 (0)