Skip to content

Commit 1ac6408

Browse files
committed
Core: Don't reimplement deprecated but not removed APIs
This will save space and avoid potential divergence from Core. Also, simplify the `deferred.pipe` patch.
1 parent 4f86dcc commit 1ac6408

File tree

3 files changed

+18
-96
lines changed

3 files changed

+18
-96
lines changed

src/jquery/core.js

+2-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import "../disablePatches.js";
33

44
var arr = [],
55
push = arr.push,
6-
slice = arr.slice,
76
sort = arr.sort,
87
splice = arr.splice,
98
class2type = {},
@@ -90,35 +89,8 @@ migratePatchAndWarnFunc( jQuery, "isWindow",
9089
// arguments.
9190
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
9291
// However, it is not slated for removal any time soon
93-
migratePatchAndWarnFunc( jQuery, "proxy",
94-
function( fn, context ) {
95-
var tmp, args, proxy;
96-
97-
if ( typeof context === "string" ) {
98-
tmp = fn[ context ];
99-
context = fn;
100-
fn = tmp;
101-
}
102-
103-
// Quick check to determine if target is callable, in the spec
104-
// this throws a TypeError, but we will just return undefined.
105-
if ( typeof fn !== "function" ) {
106-
return undefined;
107-
}
108-
109-
// Simulated bind
110-
args = slice.call( arguments, 2 );
111-
proxy = function() {
112-
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
113-
};
114-
115-
// Set the guid of unique handler to the same of original handler, so it can be removed
116-
proxy.guid = fn.guid = fn.guid || jQuery.guid++;
117-
118-
return proxy;
119-
}, "proxy",
120-
"jQuery.proxy() is deprecated"
121-
);
92+
migratePatchAndWarnFunc( jQuery, "proxy", jQuery.proxy,
93+
"proxy", "jQuery.proxy() is deprecated" );
12294

12395
migrateWarnProp( jQuery.fn, "push", push, "push",
12496
"jQuery.fn.push() is deprecated and removed; use .add or convert to an array" );

src/jquery/deferred.js

+3-42
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,15 @@ import {
88
if ( jQuery.Deferred ) {
99

1010
var unpatchedGetStackHookValue,
11-
oldDeferred = jQuery.Deferred,
12-
tuples = [
13-
14-
// Action, add listener, callbacks, .then handlers, final state
15-
[ "resolve", "done", jQuery.Callbacks( "once memory" ),
16-
jQuery.Callbacks( "once memory" ), "resolved" ],
17-
[ "reject", "fail", jQuery.Callbacks( "once memory" ),
18-
jQuery.Callbacks( "once memory" ), "rejected" ],
19-
[ "notify", "progress", jQuery.Callbacks( "memory" ),
20-
jQuery.Callbacks( "memory" ) ]
21-
];
11+
oldDeferred = jQuery.Deferred;
2212

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

27-
function newDeferredPipe( /* fnDone, fnFail, fnProgress */ ) {
28-
var fns = arguments;
29-
30-
return jQuery.Deferred( function( newDefer ) {
31-
jQuery.each( tuples, function( i, tuple ) {
32-
var fn = typeof fns[ i ] === "function" && fns[ i ];
33-
34-
// Deferred.done(function() { bind to newDefer or newDefer.resolve })
35-
// deferred.fail(function() { bind to newDefer or newDefer.reject })
36-
// deferred.progress(function() { bind to newDefer or newDefer.notify })
37-
deferred[ tuple[ 1 ] ]( function() {
38-
var returned = fn && fn.apply( this, arguments );
39-
if ( returned && typeof returned.promise === "function" ) {
40-
returned.promise()
41-
.done( newDefer.resolve )
42-
.fail( newDefer.reject )
43-
.progress( newDefer.notify );
44-
} else {
45-
newDefer[ tuple[ 0 ] + "With" ](
46-
this === promise ? newDefer.promise() : this,
47-
fn ? [ returned ] : arguments
48-
);
49-
}
50-
} );
51-
} );
52-
fns = null;
53-
} ).promise();
54-
}
55-
56-
migratePatchAndWarnFunc( deferred, "pipe", newDeferredPipe, "deferred-pipe",
17+
migratePatchAndWarnFunc( deferred, "pipe", deferred.pipe, "deferred-pipe",
5718
"deferred.pipe() is deprecated" );
58-
migratePatchAndWarnFunc( promise, "pipe", newDeferredPipe, "deferred-pipe",
19+
migratePatchAndWarnFunc( promise, "pipe", promise.pipe, "deferred-pipe",
5920
"deferred.pipe() is deprecated" );
6021

6122
if ( func ) {

src/jquery/event.js

+13-24
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,18 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
2626
function( _i, name ) {
2727

2828
// Handle event binding
29-
migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
30-
return arguments.length > 0 ?
31-
this.on( name, null, data, fn ) :
32-
this.trigger( name );
33-
},
34-
"shorthand-deprecated-v3",
35-
"jQuery.fn." + name + "() event shorthand is deprecated" );
29+
migratePatchAndWarnFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3",
30+
"jQuery.fn." + name + "() event shorthand is deprecated" );
3631
} );
3732

38-
migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
39-
return this.on( types, null, data, fn );
40-
}, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
41-
migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
42-
return this.off( types, null, fn );
43-
}, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
44-
migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
45-
return this.on( types, selector, data, fn );
46-
}, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
47-
migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
48-
return arguments.length === 1 ?
49-
this.off( selector, "**" ) :
50-
this.off( types, selector || "**", fn );
51-
}, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
52-
migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
53-
return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
54-
}, "hover", "jQuery.fn.hover() is deprecated" );
33+
migratePatchAndWarnFunc( jQuery.fn, "bind", jQuery.fn.bind,
34+
"pre-on-methods", "jQuery.fn.bind() is deprecated" );
35+
migratePatchAndWarnFunc( jQuery.fn, "unbind", jQuery.fn.unbind,
36+
"pre-on-methods", "jQuery.fn.unbind() is deprecated" );
37+
migratePatchAndWarnFunc( jQuery.fn, "delegate", jQuery.fn.delegate,
38+
"pre-on-methods", "jQuery.fn.delegate() is deprecated" );
39+
migratePatchAndWarnFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
40+
"pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
41+
42+
migratePatchAndWarnFunc( jQuery.fn, "hover", jQuery.fn.hover,
43+
"hover", "jQuery.fn.hover() is deprecated" );

0 commit comments

Comments
 (0)