How are Ember's Promises related to Promises in general, and specifically jQuery's Promises?

StackOverflow https://stackoverflow.com/questions/17499316

Question

Some big-picture questions to help learning about Ember's Promise:

  1. Is Ember's RSVP the same as Tildeio's RSVP? If not, how are they different? How are they related?

  2. Does JavaScript "Promise" come in different flavors, i.e. specifications? If it does, is it true that jQuery Promise uses one set type of Promise specification (what is it?) and Ember's RSVP.Promise uses a different set of Promise specification, namely Promises/A+?

  3. How are Ember RSVP's Promise.then(), Tildeio RSVP's Promise.then(), and jQuery's deferred.then() related? How are Ember's Promise and then() different from jQuery's Promise and then()? It's good to know to avoid mistakes.

Example of Ember's RSVP.Promise being used in Ember's RESTAdapter's updateRecord's ajax call. These are some SO posts about jQuery Promise, then() #1 and then() #2. I'm in a state of confusion right now.

Était-ce utile?

La solution

This is a big topic. We spent a few hours talking about it at last months EmberNYC meetup. If you want to understand promises, a great place to start would be checking out:

  1. Is Ember's RSVP the same as Tildeio's RSVP? If not, how are they different? How are they related?

Basically the same. Tildeio's RSVP is where active development of RSVP can be found. Ember's RSVP is a copy of that library.

  1. Does JavaScript "Promise" come in different flavors, i.e. specifications? If it does, is it true that jQuery Promise uses one set type of Promise specification (what is it?) and Ember's RSVP.Promise uses a different set of Promise specification, namely Promises/A+?

For sure it comes in different flavors, not so much by design but it's how things evolved. Promises/A+ is one of many proposed promise specs and seems to have the most traction. Most promises implementations (including RSVP) are compliant with Promises/A+, meaning that they pass the test-suite.

I don't believe jQuery's Promise implementation has a different spec per-se. It is almost-but-not-quite compliant with Promises/A. For the most part they play nice together. There are a couple of edge cases related to error handling where jQuery promises might not behave as you'd expect. Domenic gets into this in detail in his talk, you can also find info about it in this post: whats so great about js promises

How are Ember RSVP's Promise.then(), Tildeio RSVP's Promise.then(), and jQuery's deferred.then() related?

Ember and Tildeio RSVP are the same thing. jQuery's is mostly the same except that:

"If an error handler returns something other than a promise, most implementations consider the error handled, and don’t propagate it. However, jQuery does not consider the error handled in these cases, and propagates it forward anyway." - whats so great about js promises

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top