-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Simplify boolean expressions #9
Conversation
Prior to this change, the conditional boolean values were being set using the ternary operator. This change removes ternary operators and uses logical operators to simplify the evaluation.
@@ -1,17 +1,15 @@ | |||
export default class Darkmode { | |||
constructor(options) { |
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.
constructor(options) { | |
constructor(options = {}) { |
Then you can leave out all the options &&
checks
const buttonColorDark = options && options.buttonColorDark || '#100f2c'; | ||
const buttonColorLight = options && options.buttonColorLight || '#fff'; | ||
const label = options && options.label || ''; | ||
const saveInCookies = options && options.saveInCookies; |
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 saveInCookies = options && options.saveInCookies; | |
const saveInCookies = options && !!options.saveInCookies; |
to ensure it's a boolean
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.
In that case, I'd prefer options && Boolean(options.saveInCookies)
@sandoche, what are we going to do about this PR? 🤷♂ |
Hi @maacpiash, just need to test it before merging ! I'll do it this week! |
Prior to this change, the conditional Boolean values were being set using the ternary operator.
This change removes ternary operators and uses logical operators to simplify the evaluation.