Betterment / backbone.blazer

[UNSUPPORTED] A better router for Backbone and Marionette applications
MIT License
70 stars 9 forks source link

Use A+ promises #13

Open jamesplease opened 9 years ago

jamesplease commented 9 years ago

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.

samandmoore commented 9 years ago

cool. will add this in as a dev dependency https://github.com/jakearchibald/es6-promise

samccone commented 9 years ago

or bluebird... :)

samandmoore commented 9 years ago

was playing with this today using bluebird and having issues with sinon. will take another look tomorrow. might need some help via gitter :)

jamesplease commented 9 years ago

Bluebird's utility is most pronounced for more advanced things...I'm sure that any promise implementation will work for these simple tests.

devel-pa commented 9 years ago

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;
        }