-
Notifications
You must be signed in to change notification settings - Fork 6
Use switch instead of if #107
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
base: main
Are you sure you want to change the base?
Conversation
| case 'PAD_ENTER': return '↵' | ||
| case 'PAD_PERIOD': return '.' | ||
| } | ||
| if (key.startsWith('PAD_')) return key.slice('PAD_'.length) |
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.
.slice('PAD_'.length)
This approach is harder to understand at first glance, rather than simply splitting by _
| switch (hid) { | ||
| case 'KEY_SPACE': | ||
| icon = 'space_bar' | ||
| break |
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.
This is the reason I try to avoid switch in JS, too much syntax noise for a minimal (negligible) performance gain.
| if (label.startsWith('KEY_')) { | ||
| const key = label.slice('KEY_'.length) | ||
| switch (key) { | ||
| case 'ESCAPE': return 'Esc' |
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 like these (because they do not need break)
| if (this.section instanceof CtrlButton) { | ||
| if (index==1 && this.section.hold) cls += ' hold' | ||
| if (index==2 && this.section.double) cls += ' double' | ||
| if (index == 1 && this.section.hold) cls += ' hold' |
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.
👍
| const icon = this.getIcon(action) | ||
| const cls = this.getClass(0, action, text, icon) | ||
| return {cls, text, icon} | ||
| return { cls, text, icon } |
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.
This flavor of linting is up to personal preference
I found that the
getTextandgetIconmethods inaction_preview.tsuse a lot ofifjudgments. I think changing them toswitchwill make them more efficient.