Skip to content

Deferred: Deprecate deferred.pipe() method #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(grunt) {
"src/manipulation.js",
"src/event.js",
"src/traversing.js",
"src/deferred.js",
"src/outro.js"
],
tests: {
Expand Down
21 changes: 21 additions & 0 deletions src/deferred.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

var oldDeferred = jQuery.Deferred;

jQuery.Deferred = function() {
var deferred = oldDeferred.apply( this, arguments );

// Don't add this method if the current jQuery doesn't provide it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean "only add this method if the current jQuery doesn't provide it"

Edit: Wait, I think I'm confused....shouldn't migrate be adding it always for back-compat in addition to overriding it for the warn?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding it for the warning. I didn't want to add .pipe if, for example, they were using jQuery 1.5 because .pipe wasn't there and maybe they're doing a feature detect or something. I suppose I could always add it but it seemed better to NOT shim it if the original Deferred didn't have it.

But talking to the rubber ducky now I realize that I'm not correctly covering the version 1.6 to 1.8 region where we had .then but it didn't return a new promise. In those cases we should use the existing .pipe which does return a new promise.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was confusing myself; I was making the false assumption that .pipe was being removed in 3.0, but I realize that isn't the case. What you said about older versions is def true though

if ( deferred.pipe ) {

deferred.pipe = function() {
migrateWarn( "deferred.pipe() is deprecated" );
return deferred.then.apply( this, arguments );
};

deferred.promise().pipe = function() {
return deferred.pipe.apply( this, arguments );
};
}

return deferred;
};
34 changes: 34 additions & 0 deletions test/deferred.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

module("deferred");

test( ".pipe()", function() {
expect( 8 );

var d = jQuery.Deferred().resolve( 1 );

// Deferred
expectNoWarning( "then", function() {
d.then(function( v ) {
equal( v, 1, "got correct value" );
}); });

expectWarning( "pipe", function() {
d.pipe(function( v ) {
equal( v, 1, "got correct value" );
});
});

// Deferred's promise object
d = d.promise();
expectNoWarning( "then", function() {
d.then(function( v ) {
equal( v, 1, "got correct value" );
}); });

expectWarning( "pipe", function() {
d.pipe(function( v ) {
equal( v, 1, "got correct value" );
});
});
});

1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<script src="ajax.js"></script>
<script src="event.js"></script>
<script src="traversing.js"></script>
<script src="deferred.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
6 changes: 6 additions & 0 deletions warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ $(document).ajaxStart(function(){ $("#status").text("Ajax started"); });

**Solution**: Boolean properties should generally not be passed to `$().attr` at all; replace with `$().prop` unless you truly intend to update the underlying HTML *attribute*.

### JQMIGRATE: deferred.pipe() is deprecated

**Cause**: The `.pipe()` method on a `jQuery.Deferred` object was deprecated as of jQuery 1.8, when the `.then()` method was changed to perform the same function.

**Solution**: Change all occurrences of `.pipe()` to `.then()`.

### JQMIGRATE: jQuery.clean() is deprecated

**Cause**: `jQuery.buildFragment()` and `jQuery.clean()` are undocumented internal methods. The signature of `jQuery.buildFragment()` was changed in jQuery 1.8 and 1.9, and `jQuery.clean()` was removed in 1.9. However, we are aware of some plugins or other code that may be using them.
Expand Down