Skip to content

.when() documentation should say it takes Promises, not just Deferreds #906

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

Closed
JonathanAquino opened this issue Apr 5, 2016 · 6 comments
Assignees
Milestone

Comments

@JonathanAquino
Copy link

The documentation for $.when() says that it takes Deferreds. However, it later implies that it can take Deferreds or Promises:

If a single argument is passed to jQuery.when() and it is not a Deferred or a Promise, ...

If so, then the documentation should be updated to say that $.when() takes Promises, not just Deferreds. Promises are more general than Deferreds.

In my testing, $.when() works with Promises, not just Deferreds.

@dmethvin dmethvin added this to the 3.0.0 milestone Apr 5, 2016
@dmethvin
Copy link
Member

dmethvin commented Apr 5, 2016

Yep, that's a feature of version 3.0.0 which hasn't been released yet. I don't see a commit in the 3.0 api docs branch yet though so thanks for the reminder! There is a mention of it in the 3.0 upgrade guide already, which is taking shape here.

If you'd like to help by reviewing the major issues there and creating pull requests for the docs that would be much appreciated. Also you have comment on the upgrade guide draft so any input there is welcome too.

Edit: ref jquery/jquery#1722

@JonathanAquino
Copy link
Author

@dmethvin Actually my comment applies to jQuery 2. You can not only pass Deferreds to .when() - you can also pass promises from Deferred.promise(). Promises are more general than Deferreds.

That is why I think the documentation for $.when() should say that it takes Promises, not just Deferreds.

@dmethvin
Copy link
Member

dmethvin commented Apr 6, 2016

Oh you mean the .promise from our own jQuery.Deferred? Yes. I agree, the type of the incoming args there should be Promise and not Deferred.

@AurelioDeRosa
Copy link
Member

Deferred is a superset of Promise, or to cite our own documentation:

The Promise exposes only the Deferred methods needed to attach additional handlers or determine the state

Said that, $.when() accepts Deferred, Promise, and Promise-like objects. In fact, in the documentation page of $.when(), we show an example where we pass $.ajax( "test.aspx" ) which returns an jqXHR object, which in turn is a Promise-like object.

In conclusion, I think we should specify all these types and not replace Deferred with Promise.

@JonathanAquino
Copy link
Author

@AurelioDeRosa Since Deferred is a superset of Promise, then if you say that $.when accepts Promise-like objects, that includes Deferreds, Promises, and Promise-like objects.

So wouldn't it make more sense to just say that $.when accepts Promise-like objects?

@dmethvin
Copy link
Member

dmethvin commented Apr 7, 2016

For jQuery 1.x/2.x it only accepts jQuery.Deferred or the jQuery.Deferred.promise subset of one.

For jQuery 3.0 it also accepts any "thenable" including an ES6 Promise.

We will probably want to change our use of the type name Promise in Types.html to avoid confusion with the now-standard ES6 Promise. We can also add a "Thenable" type.

@AurelioDeRosa AurelioDeRosa self-assigned this Apr 19, 2016
mgol pushed a commit that referenced this issue Mar 20, 2017
Technically replacing Deferred with Thenable would work, but
mentioning Deferred and Promise directly should make this
easier to understand for new and existing users.

Fixes #906
Closes #1026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants