Side navigation
#10307 closed enhancement (duplicate)
Opened September 19, 2011 10:51AM UTC
Closed September 19, 2011 01:53PM UTC
Last modified February 04, 2013 11:48PM UTC
$.when should accept array of deferreds
Reported by: | gondo@webdesigners.sk | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | deferred | Version: | 1.6.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$.when should accept array of deferreds as parameter.
currently, it accepts just 1 deferred object or more arguments (more deferreds separated by comma)
Attachments (0)
Change History (6)
Changed September 19, 2011 01:53PM UTC by comment:1
component: | unfiled → deferred |
---|---|
priority: | undecided → low |
resolution: | → duplicate |
status: | new → closed |
Changed September 19, 2011 01:53PM UTC by comment:3
Changed September 28, 2011 05:49PM UTC by comment:5
We don't intend to add this because the values that are passed to jQuery.when are not required to be observable - an array, like anything else besides a deferred or promise, is treated as something that has already been resolved. Another option like introspecting an array to check for the existence of deferreds is overly invasive and brittle, so I believe we'll continue to recommend using $.when.apply(null, arrayOfDeferreds). If you like, you can duckpunch it into your jQuery with something like
var oldWhen = jQuery.when; jQuery.when = function( arg ) { if ( jQuery.isArray( arg ) ) { return oldWhen.apply( null, arg ); } else { return oldWhen.apply( Array.prototype.slice.call( arguments ) ); } };
Changed February 04, 2013 11:48PM UTC by comment:6
Not having a way to wait for an array of promises in jQuery is a huge drawback IMHO. In all the time I used $.when in almost all of them I have to use the apply invocation.
Only in the simplest of cases you will store your jqXHR in variables, because doing it that way does not scale for more than 3 or 4 instances and makes for hard to maintian/evolve code.
Both https://github.com/kriskowal/q https://github.com/cujojs/when and https://github.com/kriszyp/node-promise support that syntax, and it is hard for me to see why jQuery does not.