]> source.dussan.org Git - jquery.git/commitdiff
"then" renamed "complete" and new "then" method defined using "complete" and "fail...
authorjaubourg <j@ubourg.net>
Wed, 5 Jan 2011 03:29:30 +0000 (04:29 +0100)
committerjaubourg <j@ubourg.net>
Wed, 5 Jan 2011 03:29:30 +0000 (04:29 +0100)
src/ajax.js
src/core.js
test/unit/core.js

index 86709005e0a0b7ce720d204acf34c9b140bb4176..32f75f6ebb14b5ff77b2c3add8395fbe5b095aa4 100644 (file)
@@ -496,9 +496,9 @@ jQuery.extend({
                
                // Attach deferreds
                deferred.promise( jXHR );
-               jXHR.success = jXHR.then;
+               jXHR.success = jXHR.complete;
                jXHR.error = jXHR.fail;
-               jXHR.complete = completeDeferred.then;
+               jXHR.complete = completeDeferred.complete;
 
                // Remove hash character (#7531: and string promotion)
                s.url = ( "" + s.url ).replace( rhash , "" );
index 0211808c5b79b054fd3662fac70f2bb66741cb8f..edd2c94d891a76e173f4975521540cf297b57146 100644 (file)
@@ -258,7 +258,7 @@ jQuery.fn = jQuery.prototype = {
                jQuery.bindReady();
                
                // Change ready & apply
-               return ( jQuery.fn.ready = readyList.then ).apply( this , arguments );
+               return ( jQuery.fn.ready = readyList.complete ).apply( this , arguments );
        },
 
        eq: function( i ) {
@@ -815,8 +815,8 @@ jQuery.extend({
                        // the deferred itself
                        deferred  = {
                                
-                               // then( f1, f2, ...)
-                               then: function () {
+                               // complete( f1, f2, ...)
+                               complete: function () {
                                        
                                        if ( ! cancelled ) {
                                                
@@ -836,7 +836,7 @@ jQuery.extend({
                                                        elem = args[ i ];
                                                        type = jQuery.type( elem );
                                                        if ( type === "array" ) {
-                                                               deferred.then.apply( deferred , elem );
+                                                               deferred.complete.apply( deferred , elem );
                                                        } else if ( type === "function" ) {
                                                                callbacks.push( elem );
                                                        }
@@ -901,27 +901,31 @@ jQuery.extend({
                // Add errorDeferred methods and redefine cancel                        
                jQuery.extend( deferred , {
 
-                               fail: failDeferred.then,
-                               fireReject: failDeferred.fire,
-                               reject: failDeferred.resolve,
-                               isRejected: failDeferred.isResolved,
-                               // Get a promise for this deferred
-                               // If obj is provided, the promise aspect is added to the object
-                               promise: function( obj ) {
-                                       obj = obj || {};
-                                       jQuery.each( "then fail isResolved isRejected".split( " " ) , function( _ , method ) {
-                                               obj[ method ] = deferred[ method ];
-                                       });
-                                       obj.promise = function() {
-                                               return obj;
-                                       };
+                   then: function( completeCallbacks , failCallbacks ) {
+                       deferred.complete( completeCallbacks ).fail( failCallbacks );
+                       return this;
+                   },
+                       fail: failDeferred.complete,
+                       fireReject: failDeferred.fire,
+                       reject: failDeferred.resolve,
+                       isRejected: failDeferred.isResolved,
+                       // Get a promise for this deferred
+                       // If obj is provided, the promise aspect is added to the object
+                       promise: function( obj ) {
+                               obj = obj || {};
+                               jQuery.each( "then complete fail isResolved isRejected".split( " " ) , function( _ , method ) {
+                                       obj[ method ] = deferred[ method ];
+                               });
+                               obj.promise = function() {
                                        return obj;
-                               }
+                               };
+                               return obj;
+                       }
 
                } );
                
                // Make sure only one callback list will be used
-               deferred.then( failDeferred.cancel ).fail( deferred.cancel );
+               deferred.then( failDeferred.cancel , deferred.cancel );
                
                // Unexpose cancel
                delete deferred.cancel;
index 9367ab10d93c0203f0cfbbaff235da9f89c04805..1fc2a4ac67da396c836aec9c41d6b8c8d66f33e0 100644 (file)
@@ -917,7 +917,7 @@ test("jQuery._Deferred()", function() {
                
        test = false;
                
-       deferred.then( function( value ) {
+       deferred.complete( function( value ) {
                equals( value , "value" , "Test pre-resolve callback" );
                test = true;
        } );
@@ -928,7 +928,7 @@ test("jQuery._Deferred()", function() {
 
        test = false;
        
-       deferred.then( function( value ) {
+       deferred.complete( function( value ) {
                equals( value , "value" , "Test post-resolve callback" );
                test = true;
        } );
@@ -939,7 +939,7 @@ test("jQuery._Deferred()", function() {
        
        test = true;
        
-       deferred.then( function() {
+       deferred.complete( function() {
                ok( false , "Cancel was ignored" );
                test = false;
        } );
@@ -949,18 +949,18 @@ test("jQuery._Deferred()", function() {
        deferred = jQuery._Deferred().resolve();
        
        try {
-               deferred.then( function() {
+               deferred.complete( function() {
                        throw "Error";
                } , function() {
                        ok( true , "Test deferred do not cancel on exception" );
                } );
        } catch( e ) {
                strictEqual( e , "Error" , "Test deferred propagates exceptions");
-               deferred.then();
+               deferred.complete();
        }
        
        test = "";
-       deferred = jQuery._Deferred().then( function() {
+       deferred = jQuery._Deferred().complete( function() {
                
                test += "A";
                
@@ -970,13 +970,13 @@ test("jQuery._Deferred()", function() {
                
        } ).resolve();
        
-       strictEqual( test , "AB" , "Test multiple then parameters" );
+       strictEqual( test , "AB" , "Test multiple complete parameters" );
        
        test = "";
        
-       deferred.then( function() {
+       deferred.complete( function() {
                
-               deferred.then( function() {
+               deferred.complete( function() {
                        
                        test += "C";
                        
@@ -989,11 +989,11 @@ test("jQuery._Deferred()", function() {
                test += "B";
        } );
        
-       strictEqual( test , "ABC" , "Test then callbacks order" );
+       strictEqual( test , "ABC" , "Test complete callbacks order" );
        
        deferred = jQuery._Deferred();
        
-       deferred.fire( jQuery , [ document ] ).then( function( doc ) {
+       deferred.fire( jQuery , [ document ] ).complete( function( doc ) {
                ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
        });
 });
@@ -1011,13 +1011,13 @@ test("jQuery.Deferred()", function() {
        
        jQuery.Deferred().resolve().then( function() {
                ok( true , "Success on resolve" );
-       }).fail( function() {
+       }, function() {
                ok( false , "Error on resolve" );
        });
        
        jQuery.Deferred().reject().then( function() {
                ok( false , "Success on reject" );
-       }).fail( function() {
+       }, function() {
                ok( true , "Error on reject" );
        });
 });
@@ -1055,7 +1055,7 @@ test("jQuery.when()", function() {
                }) ).then( function( value ) {
                        strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
                        cache = value;
-               }).fail( function() {
+               }, function() {
                        ok( false , "Fail called" );
                });
        }