-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Deprecate accessing jQuery.Event#originalEvent #16690
Conversation
d6a687b
to
707e85a
Compare
Tests failing due to the yarn registry being down... |
707e85a
to
e92ffc4
Compare
63823dc
to
61ebe59
Compare
After making prettier and IE11 (no Proxy) happy, it's finally green now 😀 @rwjblue would love your review here! |
// not trigger a deprecation | ||
|
||
/* global Proxy */ | ||
return new Proxy(jqEvent, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you restructure this slightly, like:
import { DEBUG } from '@glimmer/env';
export default function addJQueryEventDeprecation(jqEvent) {
if (!DEBUG || !HAS_NATIVE_PROXY) {
return jqEvent;
}
return new Proxy(...);
}
This will ensure we always just use the jqEvent in production builds...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that totally makes sense! I was worried a bit about runtime overhead, but somehow didn't think of this... 🙄#dontCodeLateAtNight
I guess uglify (or rollup even before that?) will then strip it away at build time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly!
import { ENV } from 'ember-environment'; | ||
import { HAS_NATIVE_PROXY } from 'ember-utils'; | ||
|
||
function deprecateJQueryEvent() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this function and inline the deprecate()
call directly into addJQueryEventDeprecation
? This will reduce the total byte size impact for production builds (this outer function will be stripped as well).
// 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 | ||
|
||
/* global Proxy */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally like to add these at the top of the file, would you mind moving it up there?
if (typeof target[name] === 'function') { | ||
// for methods jQuery.Event call them with `target` as the `this` context, so they will use access | ||
// `originalEvent` from the original jQuery event, not our proxy, thus not trigger the deprecation | ||
return target[name].bind(target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we cache these?
Something like:
let boundFunctions = new Map();
// ...snip..
if (!boundFunctions.has(name)) {
boundFucntions.set(name, target[name].bind(target));
}
return boundFunctions.get(name);
61ebe59
to
3c94cfe
Compare
@rwjblue two tests in the |
Yes, I think that makes sense. |
Implements the deprecation message for user-land code accessing `originalEvent` on `jQuery.Event` instances, as proposed by RFC#294 (https://github.com/emberjs/rfcs/blob/master/text/0294-optional-jquery.md#introducing-ember-jquery-legacy-and-deprecating-jqueryevent-usage)
3c94cfe
to
e323e74
Compare
Fixed! |
Awesome, thank you! |
Implements the deprecation message for user-land code accessing
originalEvent
onjQuery.Event
instances, as proposed by RFC#294 (https://github.com/emberjs/rfcs/blob/master/text/0294-optional-jquery.md#introducing-ember-jquery-legacy-and-deprecating-jqueryevent-usage)Relates to #16687 introducing the
_JQUERY_INTEGRATION
flag also used here.