-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($q) allow $q to work well with decorators #3670
Conversation
Decorators are used to intercept, extend, or modify service behaviors. Do such to a Promise/Future seems fundamentally wrong. What is your use case for decorator $q Futures ? |
At the time this was filed, my use case was that a recent breaking change ( promise.always -> promise.finally ) was causing us a lot of pain between browsers, linting, and always having to use bracket notation as a result. The goal was to restore the .always method as an alias of .finally to avoid all of that pain. |
I could see an argument for adding bits of the original Q that were omitted from Angular. I sure do wish that Angular's |
Simply use a decorator to add/inject the spread functionality to $q On Thursday, March 20, 2014, Andrew Schmadel notifications@github.com
Thomas Burleson http://www.gridlinked.info |
+1 A |
You asked... so here is the code for a $q decorator |
I may not have explained this very well...it’s easy to modify the $q service using a decorator, but the main draw of .spread() is that you can utilize it like .then() - on promise instances. Currently, $q hides the creation of promise instances within .defer(), making it difficult to add convenience methods such as .spread() without resorting to hackery. |
@ToucheSir |
@ThomasBurleson If you look at the unit test that was added in this PR, it should be fairly straightforward. The implementation at the time this PR was made used method references that are stored in the closure rather than invoking the ones on the returned interface which makes it impossible to decorate them ( in this case, adding a new method to whatever is returned from .defer ) |
@lgalfaso I remember seeing that pr a little while ago, looking forward to 1.3 :) |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
|
Re-work the $q service a bit so that rather than invoking functions stored in a closure internally ( defer, reject, etc.. ), it uses the methods of the object that's returned so that when it's overridden or modified in a decorator, the desired behavior is maintained throughout
Fixes #3659