Skip to content

Conversation

dmethvin
Copy link
Member

@dmethvin dmethvin commented Mar 8, 2018

Fixes gh-3986

This avoids filling jQuery.cssProps by introducing a second internal
prop cache. It allows jQuery Migrate to detect external usage.

@mgol
Copy link
Member

mgol commented Mar 8, 2018

What's the size difference?

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments.

For posterity, this currently adds 18 bytes. Maybe it'd go down if the styleElem property gets removed back from jQuery.Tween?

@@ -0,0 +1,38 @@
define( [ "../var/document" ], function( document ) {

"use strict";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line below this one; I think that's what we do elsewhere.

@@ -14,6 +16,8 @@ Tween.prototype = {
constructor: Tween,
init: function( elem, options, prop, end, easing, unit ) {
this.elem = elem;
this.styleElem = elem.nodeType === 1 && ( jQuery.cssHooks[ prop ] ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change? We're now unit-testing jQuery.Tween, in particular the behavior of its properties so it's kind of a public API now. I'd rather not expose internal properties on Tween objects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly I was trying to avoid doing this calculation each time and just do it once in the init. It's no problem to move it back though.

@mgol
Copy link
Member

mgol commented Mar 8, 2018

Unit tests are failing in Travis.

@dmethvin
Copy link
Member Author

dmethvin commented Mar 9, 2018

Not sure why I didn't see those failures. Moving the test back out of the init fixed the issue, I guess if all props in the Tween are considered fair game at any time that's not a good optimization.

I did notice that in the tween.js tests we're mocking jQuery.style() which isn't a public interface.

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's +4 bytes instead of +18, good job!

LGTM.

Fixes jquerygh-3986
Closes jquerygh-4005

Avoids filling jQuery.cssProps by introducing a second internal
prop cache. This allows jQuery Migrate to detect external usage.
@dmethvin
Copy link
Member Author

@mgol was there something else you wanted to review before I landed this? I noticed the tag.

@mgol mgol removed the Needs review label Mar 20, 2018
Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What tag? ;)

(I just wanted others to look at it as well at the meeting)

@dmethvin dmethvin merged commit 2b5f5d5 into jquery:master Mar 21, 2018

// Return a potentially-mapped jQuery.cssProps or vendor prefixed property
function finalPropName( name ) {
var final = jQuery.cssProps[ name ] || vendorProps[ name ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I don't think this resolved the concern from jquery/jquery-migrate#291.

The jquery-migrate pull proposes a warning for getting (and theoretically, setting) of jQuery.cssProps itself. That may seem odd, but is actually fine, given that detecting the setting of sub-properties is hard, and, in order to set a sub-property, one has to get the cssProps object first, which will trigger the warning. All good.

However, the code here in core/css.js, still gets the jQuery.cssProps object the same way as before, so it seems that would trigger the warning?

The only thing that changed is it now gets the object once instead of twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous code, we set a property on jQuery.cssProps. Now we no longer do that, so Migrate can look for situations where external code sets values here.

Copy link
Member

@Krinkle Krinkle Mar 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but the warning added in jquery/jquery-migrate#291 is not for getting/setting of properties on jQuery.cssProps (of which this commit removes 1/2 instances), it warns for the getting of the cssProps property of jQuery - which it still does.

Let's continue at jquery/jquery-migrate#291 :)

@lock lock bot locked as resolved and limited conversation to collaborators Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Don't fill jQuery.cssProps if mapping isn't needed
3 participants