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.

To minimize risk, this only handles APIs still present in jQuery 4.x.
  • Loading branch information
mgol committed Nov 6, 2024
1 parent 95fd84d commit ac75ace
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 53 deletions.
35 changes: 3 additions & 32 deletions src/jquery/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { jQueryVersionSince } from "../compareVersions.js";
import { migratePatchAndWarnFunc } from "../main.js";
import "../disablePatches.js";

var arr = [],
slice = arr.slice,
class2type = {},
var class2type = {},

// Require that the "whitespace run" starts from a non-whitespace
// to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
Expand Down Expand Up @@ -116,34 +114,7 @@ if ( jQueryVersionSince( "3.3.0" ) ) {
// 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 ( !isFunction( fn ) ) {
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", "DEPRECATED: jQuery.proxy()" );

}
33 changes: 12 additions & 21 deletions src/jquery/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,9 @@ 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",
"DEPRECATED: jQuery.fn." + name + "() event shorthand" );

} );

// Trigger "ready" event only once, on document ready
Expand All @@ -118,20 +114,15 @@ jQuery.event.special.ready = {
}
};

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, "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", function( fnOver, fnOut ) {
return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
}, "pre-on-methods", "jQuery.fn.hover() is deprecated" );

0 comments on commit ac75ace

Please sign in to comment.