Skip to content
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

Add fix for $.fn.data calls #437

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add fix for $.fn.data calls #437

wants to merge 6 commits into from

Conversation

liady
Copy link

@liady liady commented Jun 24, 2021

When calling $(el).data(), the received object contains camel-cased keys, this fixes issue #436

liady and others added 3 commits June 24, 2021 20:52
When calling `$(el).data()`, the received object contains camel-cased keys, this fixes issue jquery#436
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.

Thanks for the PR! I haven't tested it yet but it looks like a valid concern & a fix. I added a few comments; also:

  1. Please use only tabs for indentation.
  2. Please add detailed tests for this new patch.

var args, result;
if ( arguments.length === 0 && typeof Proxy !== "undefined" ) {
result = oldFnData.call( this );
// eslint-disable-next-line no-undef
Copy link
Member

Choose a reason for hiding this comment

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

Why is it needed when all variables are used?

Copy link
Author

Choose a reason for hiding this comment

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

I got an eslint error that Proxy is not defined, could it be only for me?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, this. Instead of silencing the whole rule, please add another override entry to src/.eslintrc.json. There's already one for css.js, you can copy it and just include Proxy as we don't use Reflect here.

src/jquery/data.js Outdated Show resolved Hide resolved
Comment on lines 65 to 74
if ( arguments.length > 0 && typeof key === "string" && key !== camelCase( key ) ) {
migrateWarn(
"jQuery.data() always sets/gets camelCased names: " + key
);
args =
arguments.length > 1 ?
[ camelCase( key ), value ] :
[ camelCase( key ) ];
return oldFnData.apply( this, args );
}
Copy link
Member

Choose a reason for hiding this comment

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

$.fn.data('key-name') already normalizes to camelCase, why is this conversion needed?

@mgol
Copy link
Member

mgol commented Aug 25, 2021

Hey @liady, are you interested in finishing this PR?

@mgol
Copy link
Member

mgol commented Dec 2, 2021

@liady are you willing to finish the PR?

@jquery jquery deleted a comment from halimnadergrace Dec 2, 2021
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 3, 2021

CLA Signed

The committers are authorized under a signed CLA.

@halimnadergrace

This comment has been minimized.

@liady
Copy link
Author

liady commented Dec 5, 2021

@mgol this is an important fix so I do want to implement the changes to this PR, however I cannot attend to it in the next 10 days.

@@ -38,3 +39,42 @@ jQuery.data = function( elem, name, value ) {

return oldData.apply( this, arguments );
};

jQuery.fn.extend( {
data: function( key, value ) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use tabs for indentation, not spaces. This applies to most of the added lines.

@@ -1,7 +1,8 @@
import { migrateWarn } from "../main.js";
import { camelCase } from "../utils.js";

var oldData = jQuery.data;
var oldData = jQuery.data,
oldFnData = jQuery.fn.data;
Copy link
Member

Choose a reason for hiding this comment

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

Please use tabs for indentation, e.g. here:

Suggested change
oldFnData = jQuery.fn.data;
oldFnData = jQuery.fn.data;

var args, result;
if ( arguments.length === 0 && typeof Proxy !== "undefined" ) {
result = oldFnData.call( this );
if(!result) {
Copy link
Member

Choose a reason for hiding this comment

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

if needs to be followed by the space. Please have a look at the GitHub Actions output, it shows you all the various ESLint errors of this PR.

var args, result;
if ( arguments.length === 0 && typeof Proxy !== "undefined" ) {
result = oldFnData.call( this );
// eslint-disable-next-line no-undef
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this. Instead of silencing the whole rule, please add another override entry to src/.eslintrc.json. There's already one for css.js, you can copy it and just include Proxy as we don't use Reflect here.

@mgol
Copy link
Member

mgol commented Mar 1, 2022

@liady Hey, could you provide a status update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants