-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Deferred: synchronize single and multiple target handling in $.when #2707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 is a behavior difference. For $.when( 1 ), window is the context instead of undefined, but this is closer to $.when( 1, 1 ), which has historically resolved with a context of [ window, window ].
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.
Not since at least jQuery 1.8.3: http://jsfiddle.net/av4shtg8/ . I complained about the cast/all mixing in #2018, but lost.
This test code should not be altered, and the behavior change should be reverted. If anything, the problem is that the Callbacks apply converts our undefined context into the global object, but there's nothing we can do about that language-level operation.
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.
But, why? What's the point of returning undefined instead of window, or vice versa? I imagine neither is being used very often. And why are we continuing to do different things for $.when( 1 ) and $.when( 1, 1 )? jQuery 1.8.3 looks just as bad, only swapped. Time to get them to do the same thing.
I can't revert this change without doing ugly things or dumping this PR and closing #2018 wontfix. The point is to make single arguments and multiple arguments do the same thing. We can either do that or we can't. I don't really care if we do undefined or window, but let's choose one or the other for all cases, not a mixture.
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.
Either context seems sufficiently useless that it does seem unlikely anyone is using them.
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.
I'm inclined to leave it. Returning window and [ window, window ] seems better than undefined and [ window, window ]. However, I agree that getting window out of passing undefined is an odd language quirk, but I think all the windows will be undefineds in global strict mode.
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.
I'm inclined to leave it. Returning
windowand[ window, window ]seems better thanundefinedand[ window, window ]
Meh.
I think all the windows will be undefineds in global strict mode.
Correct.
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.
And why are we continuing to do different things for
$.when( 1 )and$.when( 1, 1 )… Time to get them to do the same thing.`
Look, I made the same argument, but lost. And the differences go beyond context—jQuery.when( value ) and jQuery.when( value1, …, valueN ) are actually different operations, with different signatures.
334b9ea to
246d263
Compare
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.
I see what you did there!
|
This logic could be simplified a lot further if we got rid of the special case handling for Deferred and just used the thenables path. It would mean we'd lose progress notification on Deferreds but I'm not even sure how aggregated and interspersed progress info from several Deferreds would be used effectively by a caller. In any case the behavior of progress notifications with |
Perhaps a user could have a progress bar for each request along with a progress bar for all of them? |
|
While I'm not opposed to doing this, isn't removing progress handling from |
|
We can make it a separate thing and land this PR first. It seems that |
test/unit/deferred.js
Outdated
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.
var done = assert.async(). We don't need QUnit.stop anymore. 😺
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.
Yea, I started with that. I went with QUnit.stop given how prevalent it is in our code, but I'll switch it back.
|
Where are the tests for #2018? |
|
I didn't realize there are tests needed for #2018. Is there a behavior difference that I'm not accounting for? It seemed like just a refactor that would be covered by existing tests. |
You're returning a new Deferred instead of reusing the old one; that's a behavior change; the new bahavior is one that many promise libs are careful about. This definitely needs to be tested. |
|
@gibson042 Now that I think about it, I could add tests that explicitly address the fact that we're not returning the original Deferred anymore. Is that what you mean? |
Yup, silly me. |
test/unit/deferred.js
Outdated
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.
notEqual → notStrictEqual
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.
Thanks.
Fixes gh-2546
Fixes gh-2018