Hey guys, I found some nice libraries but I'm not sure which one is the best for performing chained ajax requests client-side and having flux actions based on them.
The libraries I found so far:
When it comes to Ajax and promises, React recommends the usage of the new fetch API. Although it's browser support is still not widespread, you could make up for it by using a polyfill as @mayank mentioned.
For our projects, we use a mix of fetch and jQuery's $.get/$.post. The new components use fetch while the existing old ones use jQuery's Ajax API.
I would recommend you to steer clear from other Ajax libraries for new code and use the fetch API as it is very lightweight, has simple syntax which is easy to read, and will be natively available in all major browsers in future.
Bluebird JS by far! Jquey promises are based on an old spec and not the final one. For general promised based code Bluebird js has the best performance and the most features.
Here is a deck I've prepared about Promises for newbies
For Promised based Ajax calls use fetch which is becoming more available on Browsers. If it is not available however - use the Pollyfill...
Enjoy :)
The libraries you mention don't by themselves help you with making AJAX requests. They're just implementations of the Promises/A+ specification. These actually date back to before Promise entered the JavaScript language specification last year.
These days I would generally recommend you use a so-called polyfill like es6-promise or core-js (which polyfills a lot more than just promises). Polyfills are small libraries that implement new language features as close to the standard as possible and can automatically "patch in" the missing behaviour when you are working with environments that don't support these features natively.
The reason I would recommend a polyfill over a promise library like bluebird is that they teach you the actual language feature, meaning they teach you something you can rely on in the future without the polyfill (once you no longer have to deal with environments that are too old). They become redundant over time.
A promise library on the other hand provides features on top of the language feature. This can be incredibly convenient in many cases but especially as a beginner it can be hard to distinguish between idiosyncrasies of the promise library and parts of the API that are actually also in the native implementation. There is no natural "upgrade path" away from them unless you move to a new library that supersedes the old library's API. You can't just substitute it with "the real thing" in the future because the API is not identical (it's actually a superset, i.e. it has more methods which you have likely come to rely on).
Once you feel comfortable with promises, I would recommend either using a fetch polyfill (like whatwg-fetch or fetch-ie8 if you need IE8 support) or building your own wrapper around the XMLHttpRequest API. The reason I'm mentioning both is that promises can not be cancelled: once you make a request using the fetch API (which returns a promise for the result), you have no way of aborting that request (unlike when using XHR directly). Depending on your application that may or may not be a problem.
Mayank Chandola
I would recommend using fetch API. As fetch API is not yet supported in Safari you can use github's fetch polyfill.