mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Eliminate redundancy of Deferred.then().
This commit is contained in:
parent
e7fdda9819
commit
412d910697
@ -21,24 +21,19 @@ jQuery.extend({
|
||||
return jQuery.Deferred(function( newDefer ) {
|
||||
jQuery.each( tuples, function( i, tuple ) {
|
||||
var action = tuple[ 0 ],
|
||||
fn = fns[ i ];
|
||||
fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
|
||||
// deferred[ done | fail | progress ] for forwarding actions to newDefer
|
||||
deferred[ tuple[1] ]( jQuery.isFunction( fn ) ?
|
||||
function() {
|
||||
var returned = fn.apply( this, arguments );
|
||||
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
||||
returned.promise()
|
||||
.done( newDefer.resolve )
|
||||
.fail( newDefer.reject )
|
||||
.progress( newDefer.notify );
|
||||
} else {
|
||||
newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, [ returned ] );
|
||||
}
|
||||
} :
|
||||
function() {
|
||||
newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, arguments );
|
||||
deferred[ tuple[1] ](function() {
|
||||
var returned = fn && fn.apply( this, arguments );
|
||||
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
||||
returned.promise()
|
||||
.done( newDefer.resolve )
|
||||
.fail( newDefer.reject )
|
||||
.progress( newDefer.notify );
|
||||
} else {
|
||||
newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
fns = null;
|
||||
}).promise();
|
||||
|
Loading…
Reference in New Issue
Block a user