Skip to content

Commit

Permalink
[BUGFIX beta] remove jQuery deprecation code from production builds
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Feb 3, 2019
1 parent d59b4f6 commit cb555ef
Showing 1 changed file with 51 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,58 @@ import { DEBUG } from '@glimmer/env';
import { JQUERY_INTEGRATION } from '@ember/deprecated-features';

export default function addJQueryEventDeprecation(jqEvent) {
if (!JQUERY_INTEGRATION || !DEBUG || !HAS_NATIVE_PROXY) {
return jqEvent;
}
if (DEBUG && JQUERY_INTEGRATION && HAS_NATIVE_PROXY) {
let boundFunctions = new Map();

let boundFunctions = new Map();

// wrap the jQuery event in a Proxy to add the deprecation message for originalEvent, according to RFC#294
// we need a native Proxy here, so we can make sure that the internal use of originalEvent in jQuery itself does
// not trigger a deprecation
return new Proxy(jqEvent, {
get(target, name) {
switch (name) {
case 'originalEvent':
deprecate(
'Accessing jQuery.Event specific properties is deprecated. Either use the ember-jquery-legacy addon to normalize events to native events, or explicitly opt into jQuery integration using @ember/optional-features.',
(EmberENV => {
// this deprecation is intentionally checking `global.EmberENV` /
// `global.ENV` so that we can ensure we _only_ deprecate in the
// case where jQuery integration is enabled implicitly (e.g.
// "defaulted" to enabled) as opposed to when the user explicitly
// opts in to using jQuery
if (typeof EmberENV !== 'object' || EmberENV === null) return false;

return EmberENV._JQUERY_INTEGRATION === true;
})(global.EmberENV || global.ENV),
{
id: 'ember-views.event-dispatcher.jquery-event',
until: '4.0.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_jquery-event',
}
);
return target[name];

// provide an escape hatch for ember-jquery-legacy to access originalEvent without a deprecation
case '__originalEvent':
return target.originalEvent;

default:
if (typeof target[name] === 'function') {
// cache functions for reuse
if (!boundFunctions.has(name)) {
// for jQuery.Event methods call them with `target` as the `this` context, so they will access
// `originalEvent` from the original jQuery event, not our proxy, thus not trigger the deprecation
boundFunctions.set(name, target[name].bind(target));
// wrap the jQuery event in a Proxy to add the deprecation message for originalEvent, according to RFC#294
// we need a native Proxy here, so we can make sure that the internal use of originalEvent in jQuery itself does
// not trigger a deprecation
return new Proxy(jqEvent, {
get(target, name) {
switch (name) {
case 'originalEvent':
deprecate(
'Accessing jQuery.Event specific properties is deprecated. Either use the ember-jquery-legacy addon to normalize events to native events, or explicitly opt into jQuery integration using @ember/optional-features.',
(EmberENV => {
// this deprecation is intentionally checking `global.EmberENV` /
// `global.ENV` so that we can ensure we _only_ deprecate in the
// case where jQuery integration is enabled implicitly (e.g.
// "defaulted" to enabled) as opposed to when the user explicitly
// opts in to using jQuery
if (typeof EmberENV !== 'object' || EmberENV === null) return false;

return EmberENV._JQUERY_INTEGRATION === true;
})(global.EmberENV || global.ENV),
{
id: 'ember-views.event-dispatcher.jquery-event',
until: '4.0.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_jquery-event',
}
);
return target[name];

// provide an escape hatch for ember-jquery-legacy to access originalEvent without a deprecation
case '__originalEvent':
return target.originalEvent;

default:
if (typeof target[name] === 'function') {
// cache functions for reuse
if (!boundFunctions.has(name)) {
// for jQuery.Event methods call them with `target` as the `this` context, so they will access
// `originalEvent` from the original jQuery event, not our proxy, thus not trigger the deprecation
boundFunctions.set(name, target[name].bind(target));
}

return boundFunctions.get(name);
}
// same for jQuery's getter functions for simple properties
return target[name];
}
},
});

}

return boundFunctions.get(name);
}
// same for jQuery's getter functions for simple properties
return target[name];
}
},
});
return jqEvent;
}

0 comments on commit cb555ef

Please sign in to comment.