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()
|
return _.any(this.posts.models) ? this.timeFilteredPath() : this.basePath()
|
||||||
},
|
},
|
||||||
|
|
||||||
_fetching : false,
|
|
||||||
|
|
||||||
fetch: function() {
|
fetch: function() {
|
||||||
if(this._fetching) { return false; }
|
if(this.deferred && !this.deferred.isResolved()){ return false }
|
||||||
var self = this
|
var url = this.url()
|
||||||
|
this.deferred = this.posts.fetch({
|
||||||
// we're fetching the collection... there is probably a better way to do this
|
|
||||||
self._fetching = true;
|
|
||||||
|
|
||||||
this.posts
|
|
||||||
.fetch({
|
|
||||||
add : true,
|
add : true,
|
||||||
url : self.url()
|
url : url
|
||||||
})
|
}).done(_.bind(this.triggerFetchedEvents, this))
|
||||||
.done(
|
},
|
||||||
function(resp){
|
|
||||||
// we're done fetching... there is probably a better way to handle this
|
|
||||||
self._fetching = false;
|
|
||||||
|
|
||||||
self.trigger("fetched", self);
|
triggerFetchedEvents : function(resp){
|
||||||
|
this.trigger("fetched", this);
|
||||||
// all loaded?
|
// all loaded?
|
||||||
if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
|
if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
|
||||||
self.trigger("allPostsLoaded", self);
|
this.trigger("allPostsLoaded", this);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
basePath : function(){
|
basePath : function(){
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ describe("app.views.Stream", function() {
|
||||||
|
|
||||||
this.view = new app.views.Stream({model : this.stream});
|
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??
|
// do this manually because we've moved loadMore into render??
|
||||||
this.view.render();
|
this.view.render();
|
||||||
_.each(this.view.collection.models, function(post) {
|
_.each(this.view.collection.models, function(post) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue