don't fetch more posts from the stream if only one post has been returned
This commit is contained in:
parent
e928cc805a
commit
c9c7cff479
2 changed files with 17 additions and 7 deletions
|
|
@ -58,7 +58,7 @@ app.views.Stream = Backbone.View.extend({
|
|||
collectionFetched: function(collection, response) {
|
||||
this.$("#paginate").remove();
|
||||
|
||||
if(collection.parse(response).length == 0) {
|
||||
if(!collection.parse(response).length || collection.parse(response).length == 0) {
|
||||
this.allContentLoaded = true;
|
||||
$(window).unbind('scroll')
|
||||
return
|
||||
|
|
|
|||
|
|
@ -87,18 +87,28 @@ describe("app.views.Stream", function(){
|
|||
})
|
||||
|
||||
describe("collectionFetched", function(){
|
||||
context("unbinding scroll", function(){
|
||||
beforeEach(function(){
|
||||
spyOn($.fn, "unbind")
|
||||
})
|
||||
|
||||
it("unbinds scroll if there are no more posts left to load", function(){
|
||||
this.view.collectionFetched(this.collection, {posts : []})
|
||||
expect($.fn.unbind).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("does not fetch new content when the user is fetching one post", function(){
|
||||
this.view.collectionFetched(this.collection, {posts : {}})
|
||||
expect($.fn.unbind).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it("sets this.allContentLoaded if there are no more posts left to load", function(){
|
||||
expect(this.view.allContentLoaded).toBe(false)
|
||||
this.view.collectionFetched(this.collection, {posts : []})
|
||||
expect(this.view.allContentLoaded).toBe(true)
|
||||
})
|
||||
|
||||
it("unbinds scroll if there are no more posts left to load", function(){
|
||||
spyOn($.fn, "unbind")
|
||||
this.view.collectionFetched(this.collection, {posts : []})
|
||||
expect($.fn.unbind).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("does not set this.allContentLoaded if there was a non-empty response from the server", function(){
|
||||
expect(this.view.allContentLoaded).toBe(false)
|
||||
this.view.collectionFetched(this.collection, {posts : this.posts})
|
||||
|
|
|
|||
Loading…
Reference in a new issue