Last active
August 29, 2015 14:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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