Commit 37cd6f61 authored by danielgrippi's avatar danielgrippi

refactor stream fetching logic

parent 16223d00
......@@ -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;
self.trigger("fetched", self);
url : url
}).done(_.bind(this.triggerFetchedEvents, this))
},
// 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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment