backbone.blazer
backbone.blazer copied to clipboard
Use A+ promises
https://github.com/Betterment/backbone.blazer/blob/master/backbone.blazer.js#L19
It is not unreasonable to tell people to include a Promise polyfill these days, and jQuery promises expose a weird API.
cool. will add this in as a dev dependency https://github.com/jakearchibald/es6-promise
or bluebird... :)
was playing with this today using bluebird and having issues with sinon. will take another look tomorrow. might need some help via gitter :)
Bluebird's utility is most pronounced for more advanced things...I'm sure that any promise implementation will work for these simple tests.
Some tests made and I just realized that the router works with jQuery Deferred and not with others (like RSVP). Usually a Backbone project is using intensively jQuery and it make sens to have this promise implemented. Unfortunately, not always is possible to give such promise. Also, as much as I like Bluebird and Q (this is a good one that converts jQuery promises to standard ones) I think that these libs are way too big. It would be interesting a 2K router with 60K of promisses. And looks like jQuery 3 will have compatible promises :D
In the end I think it will be better to detect which type of promise is given (I mean jQuery vs Promise A+) and act accordingly. Not found a good solution, yet.
Update: Until then
prepare: function() {
var promise = $.Deferred();
normalPromise.then(function(){
promise.resolve();
});
return promise;
}