Skip to content

Commit

Permalink
Core: Don't reimplement deprecated but not removed APIs
Browse files Browse the repository at this point in the history
This will save space and avoid potential divergence from Core.

Also, simplify the `deferred.pipe` patch.
  • Loading branch information
mgol committed Nov 19, 2024
1 parent 415e26e commit f2c12bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 96 deletions.
32 changes: 2 additions & 30 deletions src/jquery/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "../disablePatches.js";

var arr = [],
push = arr.push,
slice = arr.slice,
sort = arr.sort,
splice = arr.splice,
class2type = {},
Expand Down Expand Up @@ -90,35 +89,8 @@ migratePatchAndWarnFunc( jQuery, "isWindow",
// arguments.
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
// However, it is not slated for removal any time soon
migratePatchAndWarnFunc( jQuery, "proxy",
function( fn, context ) {
var tmp, args, proxy;

if ( typeof context === "string" ) {
tmp = fn[ context ];
context = fn;
fn = tmp;
}

// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( typeof fn !== "function" ) {
return undefined;
}

// Simulated bind
args = slice.call( arguments, 2 );
proxy = function() {
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
};

// Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || jQuery.guid++;

return proxy;
}, "proxy",
"jQuery.proxy() is deprecated"
);
migratePatchAndWarnFunc( jQuery, "proxy", jQuery.proxy,
"proxy", "jQuery.proxy() is deprecated" );

migrateWarnProp( jQuery.fn, "push", push, "push",
"jQuery.fn.push() is deprecated and removed; use .add or convert to an array" );
Expand Down
45 changes: 3 additions & 42 deletions src/jquery/deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,15 @@ import {
if ( jQuery.Deferred ) {

var unpatchedGetStackHookValue,
oldDeferred = jQuery.Deferred,
tuples = [

// Action, add listener, callbacks, .then handlers, final state
[ "resolve", "done", jQuery.Callbacks( "once memory" ),
jQuery.Callbacks( "once memory" ), "resolved" ],
[ "reject", "fail", jQuery.Callbacks( "once memory" ),
jQuery.Callbacks( "once memory" ), "rejected" ],
[ "notify", "progress", jQuery.Callbacks( "memory" ),
jQuery.Callbacks( "memory" ) ]
];
oldDeferred = jQuery.Deferred;

migratePatchFunc( jQuery, "Deferred", function( func ) {
var deferred = oldDeferred(),
promise = deferred.promise();

function newDeferredPipe( /* fnDone, fnFail, fnProgress */ ) {
var fns = arguments;

return jQuery.Deferred( function( newDefer ) {
jQuery.each( tuples, function( i, tuple ) {
var fn = typeof fns[ i ] === "function" && fns[ i ];

// Deferred.done(function() { bind to newDefer or newDefer.resolve })
// deferred.fail(function() { bind to newDefer or newDefer.reject })
// deferred.progress(function() { bind to newDefer or newDefer.notify })
deferred[ tuple[ 1 ] ]( function() {
var returned = fn && fn.apply( this, arguments );
if ( returned && typeof returned.promise === "function" ) {
returned.promise()
.done( newDefer.resolve )
.fail( newDefer.reject )
.progress( newDefer.notify );
} else {
newDefer[ tuple[ 0 ] + "With" ](
this === promise ? newDefer.promise() : this,
fn ? [ returned ] : arguments
);
}
} );
} );
fns = null;
} ).promise();
}

migratePatchAndWarnFunc( deferred, "pipe", newDeferredPipe, "deferred-pipe",
migratePatchAndWarnFunc( deferred, "pipe", deferred.pipe, "deferred-pipe",
"deferred.pipe() is deprecated" );
migratePatchAndWarnFunc( promise, "pipe", newDeferredPipe, "deferred-pipe",
migratePatchAndWarnFunc( promise, "pipe", promise.pipe, "deferred-pipe",
"deferred.pipe() is deprecated" );

if ( func ) {
Expand Down
37 changes: 13 additions & 24 deletions src/jquery/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,18 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
function( _i, name ) {

// Handle event binding
migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
return arguments.length > 0 ?
this.on( name, null, data, fn ) :
this.trigger( name );
},
"shorthand-deprecated-v3",
"jQuery.fn." + name + "() event shorthand is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3",
"jQuery.fn." + name + "() event shorthand is deprecated" );
} );

migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
return this.on( types, null, data, fn );
}, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
return this.off( types, null, fn );
}, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
return this.on( types, selector, data, fn );
}, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
return arguments.length === 1 ?
this.off( selector, "**" ) :
this.off( types, selector || "**", fn );
}, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
}, "hover", "jQuery.fn.hover() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "bind", jQuery.fn.bind,
"pre-on-methods", "jQuery.fn.bind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "unbind", jQuery.fn.unbind,
"pre-on-methods", "jQuery.fn.unbind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "delegate", jQuery.fn.delegate,
"pre-on-methods", "jQuery.fn.delegate() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
"pre-on-methods", "jQuery.fn.undelegate() is deprecated" );

migratePatchAndWarnFunc( jQuery.fn, "hover", jQuery.fn.hover,
"hover", "jQuery.fn.hover() is deprecated" );

0 comments on commit f2c12bd

Please sign in to comment.