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 {Object} opts Options for loading the stream
@param {Integer} opts.nearPost The post we want to find other posts near to. @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. @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) { refresh: function(opts) {
opts = opts || {}; opts = opts || {};
@ -266,7 +266,7 @@ Discourse.PostStream = Em.Object.extend({
@method fillGapBefore @method fillGapBefore
@paaram {Discourse.Post} post beside gap @paaram {Discourse.Post} post beside gap
@paaram {Array} gap array of post ids to load @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) { fillGapBefore: function(post, gap) {
var postId = post.get('id'), var postId = post.get('id'),
@ -303,7 +303,7 @@ Discourse.PostStream = Em.Object.extend({
@method fillGapAfter @method fillGapAfter
@paaram {Discourse.Post} post beside gap @paaram {Discourse.Post} post beside gap
@paaram {Array} gap array of post ids to load @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) { fillGapAfter: function(post, gap) {
var postId = post.get('id'), 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. Appends the next window of posts to the stream. Call it when scrolling downwards.
@method appendMore @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() { appendMore: function() {
var self = this; 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. Prepend the previous window of posts to the stream. Call it when scrolling upwards.
@method prependMore @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() { prependMore: function() {
var postStream = this; var postStream = this;
@ -798,7 +798,7 @@ Discourse.PostStream = Em.Object.extend({
@method findPostsByIds @method findPostsByIds
@param {Array} postIds The post Ids we want to retrieve, in order. @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) { findPostsByIds: function(postIds) {
var unloaded = this.listUnloadedIds(postIds), var unloaded = this.listUnloadedIds(postIds),
@ -819,13 +819,13 @@ Discourse.PostStream = Em.Object.extend({
@method loadIntoIdentityMap @method loadIntoIdentityMap
@param {Array} postIds The post Ids we want to insert into the identity map. @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) { loadIntoIdentityMap: function(postIds) {
// If we don't want any posts, return a promise that resolves right away // If we don't want any posts, return a promise that resolves right away
if (Em.isEmpty(postIds)) { 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", var url = "/t/" + this.get('topic.id') + "/posts.json",

View File

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

View File

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