Skip to content

Commit d14a391

Browse files
fix(virtual-repeat): Correctly handle items array smaller than elements in view
this._first becomes negative if this.items.length is smaller than this.elementsInView. This negative index creates problems retrieving data This closes issue #111. Also the test 'VirtualRepeat Integration infinite scroll handles getting next data set with small page size' is changed because it wrongfully expected scrolling when the number of items were less than the elements in the view.
1 parent 9dda64f commit d14a391

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/virtual-repeat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class VirtualRepeat extends AbstractRepeater {
262262
this._first = this._first < 0 ? 0 : this._first;
263263
if (this._first > this.items.length - this.elementsInView) {
264264
this._first = this.items.length - this.elementsInView;
265+
this._first = this._first < 0 ? 0 : this._first;
265266
}
266267
this._checkScrolling();
267268
// TODO if and else paths do almost same thing, refactor?

test/virtual-repeat-integration.spec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,26 @@ describe('VirtualRepeat Integration', () => {
613613
});
614614
it('handles getting next data set with small page size', done => {
615615
vm.items = [];
616-
for(let i = 0; i < 5; ++i) {
616+
for(let i = 0; i < 7; ++i) {
617617
vm.items.push('item' + i);
618618
}
619619
create.then(() => {
620620
validateScroll(virtualRepeat, viewModel, () => {
621621
expect(vm.getNextPage).toHaveBeenCalled();
622622
done();
623-
})
623+
});
624+
});
625+
});
626+
it('handles not scrolling if number of items less than elements in view', done => {
627+
vm.items = [];
628+
for(let i = 0; i < 5; ++i) {
629+
vm.items.push('item' + i);
630+
}
631+
create.then(() => {
632+
validateScroll(virtualRepeat, viewModel, () => {
633+
expect(vm.getNextPage).not.toHaveBeenCalled();
634+
done();
635+
});
624636
});
625637
});
626638
it('passes the current index and location state', done => {

0 commit comments

Comments
 (0)