Skip to content

Commit c779738

Browse files
committed
fix(virtual-repeat): check for infinite-scroll attribute
fixes: #81 Check to make sure that we have the infinite scroll attribute before attempting to do operations with it.
1 parent e6cc7c3 commit c779738

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/virtual-repeat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class VirtualRepeat extends AbstractRepeater {
278278
if (!this._calledGetMore) {
279279
let executeGetMore = () => {
280280
this._calledGetMore = true;
281-
let func = (this.view(0) && this.view(0).firstChild.au) ? this.view(0).firstChild.au['infinite-scroll-next'].instruction.attributes['infinite-scroll-next'] : undefined;
281+
let func = (this.view(0) && this.view(0).firstChild && this.view(0).firstChild.au && this.view(0).firstChild.au['infinite-scroll-next']) ? this.view(0).firstChild.au['infinite-scroll-next'].instruction.attributes['infinite-scroll-next'] : undefined;
282282
let topIndex = this._first;
283283
let isAtBottom = this._bottomBufferHeight === 0;
284284
let isAtTop = this._isAtTop;

test/virtual-repeat-integration.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ describe('VirtualRepeat Integration', () => {
188188
let hiddenVirtualRepeat;
189189
let hiddenViewModel;
190190

191+
let containerComponent;
192+
let containerCreate;
193+
let containerVirtualRepeat;
194+
let containerViewModel;
195+
191196
beforeEach(() => {
192197
items = [];
193198
for(let i = 0; i < 1000; ++i) {
@@ -214,11 +219,25 @@ describe('VirtualRepeat Integration', () => {
214219
hiddenVirtualRepeat = hiddenComponent.sut;
215220
hiddenViewModel = hiddenComponent.viewModel;
216221
});
222+
223+
containerComponent = StageComponent
224+
.withResources('src/virtual-repeat')
225+
.inView(`<div id="scrollContainer2" style="height: 500px; overflow-y: scroll;">
226+
<div style="height: ${itemHeight}px;" virtual-repeat.for="item of items">\${item}</div>
227+
</div>`)
228+
.boundTo({ items: items });
229+
230+
containerCreate = containerComponent.create().then(() => {
231+
containerVirtualRepeat = containerComponent.sut;
232+
containerViewModel = containerComponent.viewModel;
233+
spyOn(containerVirtualRepeat, '_onScroll').and.callThrough();
234+
});
217235
});
218236

219237
afterEach(() => {
220238
component.cleanUp();
221239
hiddenComponent.cleanUp();
240+
containerComponent.cleanUp();
222241
});
223242

224243
describe('handles delete', () => {
@@ -326,6 +345,15 @@ describe('VirtualRepeat Integration', () => {
326345
});
327346
});
328347
});
348+
349+
it('handles scrolling to bottom', done => {
350+
containerCreate.then(() => {
351+
validateScroll(containerVirtualRepeat, containerViewModel, () => {
352+
expect(containerVirtualRepeat._onScroll).toHaveBeenCalled();
353+
done();
354+
}, 'scrollContainer2')
355+
});
356+
});
329357
});
330358

331359
describe('iterating table', () => {

0 commit comments

Comments
 (0)