diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2016-01-11 19:10:28 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2016-01-13 12:21:17 -0500 |
commit | bdf1b8f317d793d8ebbbe7787955edabf201a685 (patch) | |
tree | 0bc93297874f9c38d3891199336ae2738b36c3e3 /src | |
parent | f5fb8d71cb20bdbe1b536d05a0b40b503e4e1a43 (diff) | |
download | jquery-bdf1b8f317d793d8ebbbe7787955edabf201a685.tar.gz jquery-bdf1b8f317d793d8ebbbe7787955edabf201a685.zip |
Deferred: Remove undocumented progress notifications in $.when
Fixes gh-2710
Closes gh-2816
Diffstat (limited to 'src')
-rw-r--r-- | src/deferred.js | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/deferred.js b/src/deferred.js index 846528e79..ff12ac3e0 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -295,7 +295,7 @@ jQuery.extend( { // Deferred helper when: function() { - var method, + var method, resolveContexts, i = 0, resolveValues = slice.call( arguments ), length = resolveValues.length, @@ -306,47 +306,44 @@ jQuery.extend( { // the master Deferred. master = jQuery.Deferred(), - // Update function for both resolve and progress values - updateFunc = function( i, contexts, values ) { + // Update function for both resolving subordinates + updateFunc = function( i ) { return function( value ) { - contexts[ i ] = this; - values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value; - if ( values === progressValues ) { - master.notifyWith( contexts, values ); - } else if ( !( --remaining ) ) { + resolveContexts[ i ] = this; + resolveValues[ i ] = arguments.length > 1 ? slice.call( arguments ) : value; + if ( !( --remaining ) ) { master.resolveWith( - contexts.length === 1 ? contexts[ 0 ] : contexts, - values + resolveContexts.length === 1 ? resolveContexts[ 0 ] : resolveContexts, + resolveValues ); } }; - }, - progressValues, progressContexts, resolveContexts; + }; - // Add listeners to Deferred subordinates; treat others as resolved + // Add listeners to promise-like subordinates; treat others as resolved if ( length > 0 ) { - progressValues = new Array( length ); - progressContexts = new Array( length ); resolveContexts = new Array( length ); for ( ; i < length; i++ ) { + + // jQuery.Deferred - treated specially to get resolve-sync behavior if ( resolveValues[ i ] && jQuery.isFunction( ( method = resolveValues[ i ].promise ) ) ) { method.call( resolveValues[ i ] ) - .progress( updateFunc( i, progressContexts, progressValues ) ) - .done( updateFunc( i, resolveContexts, resolveValues ) ) + .done( updateFunc( i ) ) .fail( master.reject ); + + // Other thenables } else if ( resolveValues[ i ] && jQuery.isFunction( ( method = resolveValues[ i ].then ) ) ) { method.call( resolveValues[ i ], - updateFunc( i, resolveContexts, resolveValues ), - master.reject, - updateFunc( i, progressContexts, progressValues ) + updateFunc( i ), + master.reject ); } else { - updateFunc( i, resolveContexts, resolveValues )( resolveValues[ i ] ); + updateFunc( i )( resolveValues[ i ] ); } } |