-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor($q): separate Deferred out of Promise implementation #15064
Conversation
I was thinking of something similar to this myself recently! |
|
||
this.$$state.pending = this.$$state.pending || []; | ||
this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]); | ||
if (this.$$state.status > 0) scheduleProcessQueue(this.$$state); | ||
|
||
return result.promise; | ||
return result; | ||
}, | ||
|
||
'catch': function(callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was here before but why are catch
and finally
defined with strings and then
is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are javascript keywords
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I should have realized that with catch.
a25a8ce
to
a04bf03
Compare
I've rebased this. |
So, we are spared creating a I wonder to what extend was this hidden feature utilized. Maybe @lgalfaso has a better idea, since he said this has been explicitly discussed in the past. |
I can revert that part if really wanted, just seemed like something we can simplify along with everything else in this PR. Note that what @lgalfaso is referring to is doing |
Just to be sure about my position. I think that this change is good and that it simplifies some of the existing code at |
(Adding it to the |
LGTM |
a04bf03
to
342e27f
Compare
Rebased again. |
Great. Can you add some information about the BC to the commit message and then we can merge. |
BREAKING CHANGE: The Deferred object returned by $q.defer() previously delegated methods to those on Deferred.prototype. If Deferred.prototype was modified these methods would reflect that. This change removes that delegation and no longer uses methods on Deferred.prototype. Modifying methods on Deferred.prototype will no longer have an effect.
342e27f
to
1ae9ae5
Compare
Adding a BC message. |
Closes angular#15064 BREAKING CHANGE: Previously, the `Deferred` object returned by `$q.defer()` delegated the `resolve()`, `reject()` and `notify()` methods to `Deferred.prototype`. Thus, it was possible to modify `Deferred.prototype` and have the changes reflect to all `Deferred` objects. This commit removes that delegation, so modifying the above three methods on `Deferred.prototype` will no longer have an effect on `Deferred` objects.
Closes angular#15064 BREAKING CHANGE: Previously, the `Deferred` object returned by `$q.defer()` delegated the `resolve()`, `reject()` and `notify()` methods to `Deferred.prototype`. Thus, it was possible to modify `Deferred.prototype` and have the changes reflect to all `Deferred` objects. This commit removes that delegation, so modifying the above three methods on `Deferred.prototype` will no longer have an effect on `Deferred` objects.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
refactor / cleanup, maybe performance gains when creating promises
This makes
Deferred
a simple wrapper ofPromise
.Promise
s can now be constructed, chained etc without creating anyDeferred
objects.Best viewed ignoring whitespace