Skip to content

Conversation

@markelog
Copy link
Member

@markelog markelog commented Jul 14, 2016

Summary

Checklist

Mark an [x] for completed items, if you're not sure leave them unchecked and we can assist.

Thanks! Bots and humans will be around shortly to check it out.

@mention-bot
Copy link

@markelog, thanks for your PR! By analyzing the annotation information on this pull request, we identified @timmywil, @dmethvin and @mgol to be potential reviewers

+data + "" === data ? +data :
rbrace.test( data ) ? JSON.parse( data ) :
data;
data = getData( data );
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 size difference after extracting this to a function?

Copy link
Member Author

@markelog markelog Jul 14, 2016

Choose a reason for hiding this comment

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

This pull costs 32 bytes, not sure about this specific case

Copy link
Member

Choose a reason for hiding this comment

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

It seems every other change should be optimizable by UglifyJS so 32 bytes seems to be quite a lot...

Copy link
Member

Choose a reason for hiding this comment

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

Is it weird that I find the ternary more readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mgol switch..case usually not optimized by the engines or the minificators :/, we can try if..else though

Copy link
Member

Choose a reason for hiding this comment

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

We should consider disabling no-nested-ternary... this is getting too aggressive for too little benefit (and even negative benefit, though I know which side of that argument I'm on).

@mgol
Copy link
Member

mgol commented Jul 14, 2016

Related to ESLint configs: the dot-notation rule is duplicated in test/.eslintrc.

@markelog
Copy link
Member Author

Related to ESLint configs: the dot-notation rule is duplicated in test/.eslintrc.

Will fix that

@markelog
Copy link
Member Author

Related to ESLint configs: the dot-notation rule is duplicated in test/.eslintrc.

Wait, what do you mean? This rule used in dist and test folder

@markelog
Copy link
Member Author

ooh, i get it :)

return 2;
}

return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Yet, I find these if statements much more readable than that ternary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not everything could be generalized, but in general nested or in this case deep nested ternaries are less readable.

For me thought, this is much more clearer

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, if you have objections, it would be better to get them from the start - jquery/eslint-config-jquery#2

Copy link
Member

Choose a reason for hiding this comment

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

Sometimes it's hard to know if you like something or not until you see how it affects the code though. I like this rewritten code because it's easy to see the returns and know nothing below it matters for that case. With the ternaries it's much harder (for me at least) to figure that out, even when split across lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sometimes it's hard to know if you like something or not until you see how it affects the code though

yeeeah, i guess i get that

Copy link
Member

@timmywil timmywil Jul 14, 2016

Choose a reason for hiding this comment

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

Was looking into this further. I think this code was only for IE6-8. I noticed that this fallback expects quirksmode behavior (http://www.quirksmode.org/js/events_properties.html#button), not the standard behavior of event.button. I think we can remove this code!

In other words, if the reason for leaving this in was that which might get removed, this code wouldn't work anyway...http://jsbin.com/hureba/edit?html,js,console,output

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, awesome! Let's consider this in the next pr though, let's kill that baby :)

Copy link
Member

Choose a reason for hiding this comment

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

@timmywil I think we still need event.which mapping, see gh-2337, I think a lot of code still depends on it.

Copy link
Member

@timmywil timmywil Jul 14, 2016

Choose a reason for hiding this comment

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

@dmethvin I'm not sure you understood what I meant. Note that the if ( !event.which block is only for IE6-8 and would not work right in modern browsers. We can leave the mapping and still remove that block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh, was about do open ticket about this find and then there is Dave - #3235 :)

@timmywil
Copy link
Member

I am in favor of every change but the data one. The switch statement is overly expansive.

@markelog
Copy link
Member Author

You guys are totally right, it saved 14 bytes, nice

@mgol
Copy link
Member

mgol commented Jul 14, 2016

It'd be interesting to see what causes the +18 bytes increase (maybe sth could be optimized better by us or Uglify). But increased readability is worth 14 bytes anyway.

}

return data;
}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@markelog
Copy link
Member Author

markelog commented Jul 15, 2016

It seems there is a consensus about this pr, as you probably know such prs get stale pretty quickly since they related to code style so the more prs land the harder to support it, so i would like to land it in couple hours

@dmethvin
Copy link
Member

No objections here.

@markelog markelog merged commit e4fd41f into jquery:master Jul 15, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
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.

7 participants