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

Improve triggerKeyEvent() warnings #379

Merged
merged 6 commits into from
May 25, 2018
Merged

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented May 24, 2018

Resolves #368

/cc @mydea

@returns {boolean} whether the input string consists only of numeric characters
*/
export function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Keycodes are only integers. I think you should use parseInt

Copy link
Member Author

Choose a reason for hiding this comment

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

this seems to be the accepted solution for a lot of these questions on StackOverflow with lots of people mentioning that parseInt() should not be used for some reason.

ultimately this is only used to catch the case where someone used '13' instead of 13. if someone would put in '13.0' in the current state it would also warn, but if we changed it to only allow integers it would no longer show that warning, so I think it is actually better this way

@@ -22,7 +22,7 @@ const keyFromKeyCode = {
18: 'Alt',
20: 'CapsLock',
27: 'Escape',
32: '',
32: 'Space',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? I think I remember getting those values myself and being surprised by the empty string, but it was the value I saw when debugging

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@cibernox cibernox May 24, 2018

Choose a reason for hiding this comment

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

I created this which to test it and it seems to say otherwise: https://jsbin.com/qizayecoqe/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.

that is ' ', not '' though, so also something different. I'm fine with using ' ' instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought I had a space, not an empty string. My bad.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use ' ' now

@cibernox cibernox merged commit bdbc943 into emberjs:master May 25, 2018
@Turbo87 Turbo87 deleted the key-warnings branch May 25, 2018 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants