refactor stream fetching logic
This commit is contained in:
parent
16223d003f
commit
37cd6f616e
2 changed files with 12 additions and 27 deletions
|
|
@ -15,34 +15,21 @@ app.models.Stream = Backbone.Collection.extend({
|
|||
return _.any(this.posts.models) ? this.timeFilteredPath() : this.basePath()
|
||||
},
|
||||
|
||||
_fetching : false,
|
||||
|
||||
fetch: function() {
|
||||
if(this._fetching) { return false; }
|
||||
var self = this
|
||||
|
||||
// we're fetching the collection... there is probably a better way to do this
|
||||
self._fetching = true;
|
||||
|
||||
this.posts
|
||||
.fetch({
|
||||
if(this.deferred && !this.deferred.isResolved()){ return false }
|
||||
var url = this.url()
|
||||
this.deferred = this.posts.fetch({
|
||||
add : true,
|
||||
url : self.url()
|
||||
})
|
||||
.done(
|
||||
function(resp){
|
||||
// we're done fetching... there is probably a better way to handle this
|
||||
self._fetching = false;
|
||||
url : url
|
||||
}).done(_.bind(this.triggerFetchedEvents, this))
|
||||
},
|
||||
|
||||
self.trigger("fetched", self);
|
||||
|
||||
// all loaded?
|
||||
if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
|
||||
self.trigger("allPostsLoaded", self);
|
||||
}
|
||||
}
|
||||
)
|
||||
return this;
|
||||
triggerFetchedEvents : function(resp){
|
||||
this.trigger("fetched", this);
|
||||
// all loaded?
|
||||
if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
|
||||
this.trigger("allPostsLoaded", this);
|
||||
}
|
||||
},
|
||||
|
||||
basePath : function(){
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ describe("app.views.Stream", function() {
|
|||
|
||||
this.view = new app.views.Stream({model : this.stream});
|
||||
|
||||
app.stream.bind("fetched", this.collectionFetched, this); //untested
|
||||
|
||||
// do this manually because we've moved loadMore into render??
|
||||
this.view.render();
|
||||
_.each(this.view.collection.models, function(post) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue