Skip to content

Commit

Permalink
Merge pull request #44 from kellyselden/load-more-til-out-of-view
Browse files Browse the repository at this point in the history
keep loading until you are out of view, closes #10
  • Loading branch information
hhff committed Jun 21, 2015
2 parents d367cd1 + 63c81b5 commit 3870720
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions addon/components/infinity-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ export default Ember.Component.extend({
if (this.get('infinityModel.reachedInfinity') && this.get('destroyOnInfinity')) {
this.destroy();
}
}),

infinityModelPushed: Ember.observer('infinityModel.length', function() {
Ember.run.scheduleOnce('afterRender', this, this._checkIfInView);
})
});
33 changes: 29 additions & 4 deletions tests/unit/components/infinity-loader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ test('it will not destroy on load unless set', function(assert) {
{id: 2, name: 'Potato'}
];

var component = this.subject();
component.set('infinityModel', infinityModelStub);
var component = this.subject({ infinityModel: infinityModelStub });
this.render();

assert.equal(component.get('destroyOnInfinity'), false);
Expand All @@ -53,8 +52,7 @@ test('it changes text property', function(assert) {
];

var componentText;
var component = this.subject();
component.set('infinityModel', infinityModelStub);
var component = this.subject({ infinityModel: infinityModelStub });
this.render();

componentText = $.trim(component.$().text());
Expand Down Expand Up @@ -101,3 +99,30 @@ test('it throws error when multiple scrollable elements are found', function(ass
this.render();
}, Error, "Should raise error");
});

test('it checks if in view after model is pushed', function(assert) {
assert.expect(4);

var infinityModelStub = Ember.A();
function pushModel() {
infinityModelStub.pushObject({});
}
pushModel();

var component = this.subject({ infinityModel: infinityModelStub });
component.set('_checkIfInView', function() {
assert.ok(true);
});
this.render();

var done = assert.async();
var count = 3;
for (var i = 0; i < 3; i++) {
setTimeout(() => {
Ember.run(pushModel);
if (!--count) {
done();
}
});
}
});

0 comments on commit 3870720

Please sign in to comment.