Remove deprecated `Ember.Deferred`

This commit is contained in:
Robin Ward 2014-09-24 14:17:09 -04:00
parent cef3cdff86
commit 98d21ed21f
4 changed files with 28 additions and 29 deletions

View File

@ -229,7 +229,7 @@ Discourse.PostStream = Em.Object.extend({
@param {Object} opts Options for loading the stream
@param {Integer} opts.nearPost The post we want to find other posts near to.
@param {Boolean} opts.track_visit Whether or not to track this as a visit to a topic.
@returns {Ember.Deferred} a promise that is resolved when the posts have been inserted into the stream.
@returns {Promise} a promise that is resolved when the posts have been inserted into the stream.
**/
refresh: function(opts) {
opts = opts || {};
@ -266,7 +266,7 @@ Discourse.PostStream = Em.Object.extend({
@method fillGapBefore
@paaram {Discourse.Post} post beside gap
@paaram {Array} gap array of post ids to load
@returns {Ember.Deferred} a promise that's resolved when the posts have been added.
@returns {Promise} a promise that's resolved when the posts have been added.
**/
fillGapBefore: function(post, gap) {
var postId = post.get('id'),
@ -303,7 +303,7 @@ Discourse.PostStream = Em.Object.extend({
@method fillGapAfter
@paaram {Discourse.Post} post beside gap
@paaram {Array} gap array of post ids to load
@returns {Ember.Deferred} a promise that's resolved when the posts have been added.
@returns {Promise} a promise that's resolved when the posts have been added.
**/
fillGapAfter: function(post, gap) {
var postId = post.get('id'),
@ -324,7 +324,7 @@ Discourse.PostStream = Em.Object.extend({
Appends the next window of posts to the stream. Call it when scrolling downwards.
@method appendMore
@returns {Ember.Deferred} a promise that's resolved when the posts have been added.
@returns {Promise} a promise that's resolved when the posts have been added.
**/
appendMore: function() {
var self = this;
@ -353,7 +353,7 @@ Discourse.PostStream = Em.Object.extend({
Prepend the previous window of posts to the stream. Call it when scrolling upwards.
@method prependMore
@returns {Ember.Deferred} a promise that's resolved when the posts have been added.
@returns {Promise} a promise that's resolved when the posts have been added.
**/
prependMore: function() {
var postStream = this;
@ -798,7 +798,7 @@ Discourse.PostStream = Em.Object.extend({
@method findPostsByIds
@param {Array} postIds The post Ids we want to retrieve, in order.
@returns {Ember.Deferred} a promise that will resolve to the posts in the order requested.
@returns {Promise} a promise that will resolve to the posts in the order requested.
**/
findPostsByIds: function(postIds) {
var unloaded = this.listUnloadedIds(postIds),
@ -819,13 +819,13 @@ Discourse.PostStream = Em.Object.extend({
@method loadIntoIdentityMap
@param {Array} postIds The post Ids we want to insert into the identity map.
@returns {Ember.Deferred} a promise that will resolve to the posts in the order requested.
@returns {Promise} a promise that will resolve to the posts in the order requested.
**/
loadIntoIdentityMap: function(postIds) {
// If we don't want any posts, return a promise that resolves right away
if (Em.isEmpty(postIds)) {
return Ember.Deferred.promise(function (p) { p.resolve(); });
return Ember.RSVP.resolve();
}
var url = "/t/" + this.get('topic.id') + "/posts.json",

View File

@ -123,20 +123,19 @@ Discourse.TopicList = Discourse.Model.extend({
Discourse.TopicList.reopenClass({
loadTopics: function(topic_ids, filter) {
var defer = new Ember.Deferred(),
url = Discourse.getURL("/") + filter + "?topic_ids=" + topic_ids.join(",");
return new Ember.RSVP.Promise(function(resolve, reject) {
var url = Discourse.getURL("/") + filter + "?topic_ids=" + topic_ids.join(",");
Discourse.ajax({url: url}).then(function (result) {
if (result) {
// the new topics loaded from the server
var newTopics = Discourse.TopicList.topicsFrom(result);
defer.resolve(newTopics);
resolve(newTopics);
} else {
defer.reject();
reject();
}
}).then(null, function(){ defer.reject(); });
return defer;
}).catch(reject);
});
},
/**

View File

@ -28,7 +28,7 @@ window.PreloadStore = {
@method getAndRemove
@param {String} key the key to look up the object with
@param {function} finder a function to find the object with
@returns {Ember.Deferred} a promise that will eventually be the object we want.
@returns {Promise} a promise that will eventually be the object we want.
**/
getAndRemove: function(key, finder) {
if (this.data[key]) {
@ -38,23 +38,23 @@ window.PreloadStore = {
}
if (finder) {
return Em.Deferred.promise(function(promise) {
return new Ember.RSVP.Promise(function(resolve, reject) {
var result = finder();
// If the finder returns a promise, we support that too
if (result.then) {
result.then(function(result) {
return promise.resolve(result);
return resolve(result);
}, function(result) {
return promise.reject(result);
return reject(result);
});
} else {
promise.resolve(result);
resolve(result);
}
});
}
return Em.RSVP.resolve(null);
return Ember.RSVP.resolve(null);
},
/**

View File

@ -38,7 +38,7 @@ asyncTestDiscourse("getAndRemove returns a promise that resolves to the result o
expect(1);
var finder = function() {
return Ember.Deferred.promise(function(promise) { promise.resolve('hahahah'); });
return new Ember.RSVP.Promise(function(resolve) { resolve('hahahah'); });
};
PreloadStore.getAndRemove('joker', finder).then(function(result) {
@ -51,7 +51,7 @@ asyncTestDiscourse("returns a promise that rejects with the result of the finder
expect(1);
var finder = function() {
return Ember.Deferred.promise(function(promise) { promise.reject('error'); });
return new Ember.RSVP.Promise(function(resolve, reject) { reject('error'); });
};
PreloadStore.getAndRemove('joker', finder).then(null, function(result) {