FIX: If an error occurs loading posts, revert state correctly

This commit is contained in:
Robin Ward 2013-08-02 18:42:11 -04:00
parent 98b58150bb
commit 91efbc1830
1 changed files with 10 additions and 6 deletions

View File

@ -270,22 +270,26 @@ Discourse.PostStream = Em.Object.extend({
@returns {Ember.Deferred} a promise that's resolved when the posts have been added. @returns {Ember.Deferred} a promise that's resolved when the posts have been added.
**/ **/
appendMore: function() { appendMore: function() {
var postStream = this, var postStream = this;
rejectedPromise = Ember.Deferred.create(function(p) { p.reject(); });
// Make sure we can append more posts // Make sure we can append more posts
if (!postStream.get('canAppendMore')) { return rejectedPromise; } if (!postStream.get('canAppendMore')) { return Ember.RSVP.reject(); }
var postIds = postStream.get('nextWindow'); var postIds = postStream.get('nextWindow');
if (Ember.isEmpty(postIds)) { return rejectedPromise; } if (Ember.isEmpty(postIds)) { return Ember.RSVP.reject(); }
postStream.set('loadingBelow', true); postStream.set('loadingBelow', true);
var stopLoading = function() {
postStream.set('loadingBelow', false);
};
return postStream.findPostsByIds(postIds).then(function(posts) { return postStream.findPostsByIds(postIds).then(function(posts) {
posts.forEach(function(p) { posts.forEach(function(p) {
postStream.appendPost(p); postStream.appendPost(p);
}); });
postStream.set('loadingBelow', false); stopLoading();
}); }, stopLoading);
}, },
/** /**