…n(). Context is an array containing the original contexts in order. When non-observable value is given, associated context is undefined. In case only a single non-observable value is given, context is the global object (thanks so much Function.prototype.apply!). Fixes #11749.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -97,35 +97,39 @@ jQuery.extend({ | ||
var i = 0, | ||
resolveValues = sliceDeferred.call( arguments ), | ||
length = resolveValues.length, | ||
progressValues = new Array( length ), | ||
|
||
// the count of uncompleted subordinates | ||
remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0, | ||
|
||
// the master Deferred. If resolveValues consist of only a single Deferred, just use that. | ||
deferred = remaining === 1 ? subordinate : jQuery.Deferred(), | ||
promise = deferred.promise(), | ||
|
||
// Update function for both resolve and progress values | ||
updateFunc = function( i, arr ) { | ||
updateFunc = function( i, contexts, values ) { | ||
return function( value ) { | ||
arr[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments ) : value; | ||
if( arr === progressValues ) { | ||
deferred.notifyWith( promise, arr ); | ||
contexts[ i ] = this; | ||
values[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments ) : value; | ||
if( values === progressValues ) { | ||
deferred.notifyWith( contexts, values ); | ||
} else if ( !( --remaining ) ) { | ||
deferred.resolveWith( promise, arr ); | ||
deferred.resolveWith( contexts, values ); | ||
} | ||
}; | ||
}; | ||
}, | ||
|
||
progressValues, progressContexts, resolveContexts; | ||
|
||
// add listeners to Deferred subordinates; treat others as resolved | ||
if ( length > 1 ) { | ||
progressValues = new Array( length ); | ||
progressContexts = new Array( length ); | ||
resolveContexts = new Array( length ); | ||
for ( ; i < length; i++ ) { | ||
if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) { | ||
resolveValues[ i ].promise() | ||
.done( updateFunc( i, resolveValues ) ) | ||
.done( updateFunc( i, resolveContexts, resolveValues ) ) | ||
.fail( deferred.reject ) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jaubourg
Author
Member
|
||
.progress( updateFunc( i, progressValues ) ); | ||
.progress( updateFunc( i, progressContexts, progressValues ) ); | ||
} else { | ||
--remaining; | ||
} | ||
@@ -134,10 +138,10 @@ jQuery.extend({ | ||
|
||
// if we're not waiting on anything, resolve the master | ||
if ( !remaining ) { | ||
deferred.resolveWith( deferred, resolveValues ); | ||
deferred.resolveWith( resolveContexts, resolveValues ); | ||
} | ||
|
||
return promise; | ||
return deferred.promise(); | ||
} | ||
}); | ||
|
||
1 comment
on commit f93a2f5
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.
@gibson042 you may wanna look at this one. Unit tests are thorough enough so you can try and go wild.
We were previously providing the same context on resolution and rejection (well, plus or minus a
.promise()
). Shouldn't we continue to do so? For similar reasons, I'd also like to provide arrays on L141 instead ofundefined
.