Skip to content

Instantly share code, notes, and snippets.

@toranb
Last active August 29, 2015 14:05
Show Gist options
  • Save toranb/98abc9616f2abecde0d4 to your computer and use it in GitHub Desktop.
Save toranb/98abc9616f2abecde0d4 to your computer and use it in GitHub Desktop.
a simple promise mixin helper class for ember apps that use vanilla jquery ajax
var PromiseMixin = Ember.Object.create({
xhr: function(url, type, hash) {
hash = hash || {};
hash.url = url;
hash.type = type;
hash.dataType = "json";
hash.cache = false;
return new Ember.RSVP.Promise(function(resolve, reject) {
hash.success = function(json) {
return Ember.run(null, resolve, json);
};
hash.error = function(json) {
if (json && json.then) {
json.then = null;
}
return Ember.run(null, reject, json);
};
$.ajax(hash);
});
}
});
export default PromiseMixin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment