Permalink
Browse files

fix(virtual-repeat): Correctly handle items array smaller than elemen…

…ts 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.
  • Loading branch information...
palktonderAtpowelno committed Aug 6, 2017
1 parent 9dda64f commit d14a391128f85ceb6305dff5b9d899af37e0a773
Showing with 15 additions and 2 deletions.
  1. +1 −0 src/virtual-repeat.js
  2. +14 −2 test/virtual-repeat-integration.spec.js
View
@@ -262,6 +262,7 @@ export class VirtualRepeat extends AbstractRepeater {
this._first = this._first < 0 ? 0 : this._first;
if (this._first > this.items.length - this.elementsInView) {
this._first = this.items.length - this.elementsInView;
this._first = this._first < 0 ? 0 : this._first;
}
this._checkScrolling();
// TODO if and else paths do almost same thing, refactor?
@@ -613,14 +613,26 @@ describe('VirtualRepeat Integration', () => {
});
it('handles getting next data set with small page size', done => {
vm.items = [];
for(let i = 0; i < 5; ++i) {
for(let i = 0; i < 7; ++i) {
vm.items.push('item' + i);
}
create.then(() => {
validateScroll(virtualRepeat, viewModel, () => {
expect(vm.getNextPage).toHaveBeenCalled();
done();
})
});
});
});
it('handles not scrolling if number of items less than elements in view', done => {
vm.items = [];
for(let i = 0; i < 5; ++i) {
vm.items.push('item' + i);
}
create.then(() => {
validateScroll(virtualRepeat, viewModel, () => {
expect(vm.getNextPage).not.toHaveBeenCalled();
done();
});
});
});
it('passes the current index and location state', done => {

0 comments on commit d14a391

Please sign in to comment.