Renames chain as pipe.

This commit is contained in:
jaubourg 2011-04-08 17:35:08 +02:00
parent 98d83ef85f
commit 7a1c6beab0
2 changed files with 18 additions and 19 deletions

View file

@ -1,7 +1,7 @@
(function( jQuery ) { (function( jQuery ) {
var // Promise methods var // Promise methods
promiseMethods = "done fail isResolved isRejected promise then always chain".split( " " ), promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
// Static reference to slice // Static reference to slice
sliceDeferred = [].slice; sliceDeferred = [].slice;
@ -107,8 +107,7 @@ jQuery.extend({
rejectWith: failDeferred.resolveWith, rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve, reject: failDeferred.resolve,
isRejected: failDeferred.isResolved, isRejected: failDeferred.isResolved,
// Chain pipe: function( fnDone, fnFail ) {
chain: function( fnDone, fnFail ) {
return jQuery.Deferred(function( newDefer ) { return jQuery.Deferred(function( newDefer ) {
jQuery.each( { jQuery.each( {
done: [ fnDone, "resolve" ], done: [ fnDone, "resolve" ],

View file

@ -143,19 +143,19 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
}); });
} ); } );
test( "jQuery.Deferred.chain - filtering (done)", function() { test( "jQuery.Deferred.pipe - filtering (done)", function() {
expect(3); expect(3);
var defer = jQuery.Deferred(), var defer = jQuery.Deferred(),
chained = defer.chain(function( a, b ) { piped = defer.pipe(function( a, b ) {
return a * b; return a * b;
}), }),
value1, value1,
value2, value2,
value3; value3;
chained.done(function( result ) { piped.done(function( result ) {
value3 = result; value3 = result;
}); });
@ -170,24 +170,24 @@ test( "jQuery.Deferred.chain - filtering (done)", function() {
strictEqual( value2, 3, "second resolve value ok" ); strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" ); strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().reject().chain(function() { jQuery.Deferred().reject().pipe(function() {
ok( false, "chain should not be called on reject" ); ok( false, "pipe should not be called on reject" );
}); });
}); });
test( "jQuery.Deferred.chain - filtering (fail)", function() { test( "jQuery.Deferred.pipe - filtering (fail)", function() {
expect(3); expect(3);
var defer = jQuery.Deferred(), var defer = jQuery.Deferred(),
chained = defer.chain( null, function( a, b ) { piped = defer.pipe( null, function( a, b ) {
return a * b; return a * b;
} ), } ),
value1, value1,
value2, value2,
value3; value3;
chained.fail(function( result ) { piped.fail(function( result ) {
value3 = result; value3 = result;
}); });
@ -202,17 +202,17 @@ test( "jQuery.Deferred.chain - filtering (fail)", function() {
strictEqual( value2, 3, "second reject value ok" ); strictEqual( value2, 3, "second reject value ok" );
strictEqual( value3, 6, "result of filter ok" ); strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().resolve().chain( null, function() { jQuery.Deferred().resolve().pipe( null, function() {
ok( false, "chain should not be called on resolve" ); ok( false, "pipe should not be called on resolve" );
} ); } );
}); });
test( "jQuery.Deferred.chain - deferred (done)", function() { test( "jQuery.Deferred.pipe - deferred (done)", function() {
expect(3); expect(3);
var defer = jQuery.Deferred(), var defer = jQuery.Deferred(),
chained = defer.chain(function( a, b ) { piped = defer.pipe(function( a, b ) {
return jQuery.Deferred(function( defer ) { return jQuery.Deferred(function( defer ) {
defer.reject( a * b ); defer.reject( a * b );
}); });
@ -221,7 +221,7 @@ test( "jQuery.Deferred.chain - deferred (done)", function() {
value2, value2,
value3; value3;
chained.fail(function( result ) { piped.fail(function( result ) {
value3 = result; value3 = result;
}); });
@ -237,12 +237,12 @@ test( "jQuery.Deferred.chain - deferred (done)", function() {
strictEqual( value3, 6, "result of filter ok" ); strictEqual( value3, 6, "result of filter ok" );
}); });
test( "jQuery.Deferred.chain - deferred (fail)", function() { test( "jQuery.Deferred.pipe - deferred (fail)", function() {
expect(3); expect(3);
var defer = jQuery.Deferred(), var defer = jQuery.Deferred(),
chained = defer.chain( null, function( a, b ) { piped = defer.pipe( null, function( a, b ) {
return jQuery.Deferred(function( defer ) { return jQuery.Deferred(function( defer ) {
defer.resolve( a * b ); defer.resolve( a * b );
}); });
@ -251,7 +251,7 @@ test( "jQuery.Deferred.chain - deferred (fail)", function() {
value2, value2,
value3; value3;
chained.done(function( result ) { piped.done(function( result ) {
value3 = result; value3 = result;
}); });