RSVP/Promise - is there any difference?


#1

Hello,

Is there any difference between these two Promise under the hood? Are both cases using Ember.RSVP?

 return Ember.$.getJSON('https://apixx.com/mypayload.json').then(function(data) {
      return data.splice(0, 3);  
});
var promise = new Ember.RSVP.Promise(function(resolve) {
  $.getJSON('https://apixx.com/mypayload.json').then(function(data){
   resolve(data);
  });
});

promise.then(function(data) {
  return data.splice(0, 3);  
});


#2

They are not the same. JQuery is a https://api.jquery.com/promise/ and ember is using https://github.com/tildeio/rsvp.js/

I think RSVP.Promise has some extras that the jquery promise implementation doesn’t have. Also it used to be the case that JQuery promises were not really proper promises in the way they handled chaining but that maybe fixed now.


#3

Wrapping a JQuery “promise” in an Ember.RSVP.Promise does not give you the correct error handling of a promise. I recommend you use the ic-ajax library. This is available via the Ember addon ember-cli-ic-ajax.