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

Simplify boolean expressions #9

Merged
merged 1 commit into from
Jul 11, 2019
Merged

Conversation

maacpiash
Copy link
Contributor

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.

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) {

Choose a reason for hiding this comment

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

Suggested change
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;

Choose a reason for hiding this comment

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

Suggested change
const saveInCookies = options && options.saveInCookies;
const saveInCookies = options && !!options.saveInCookies;

to ensure it's a boolean

Copy link
Contributor Author

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)

@maacpiash
Copy link
Contributor Author

@sandoche, what are we going to do about this PR? 🤷‍♂

@sandoche
Copy link
Owner

sandoche commented Jul 9, 2019

Hi @maacpiash, just need to test it before merging ! I'll do it this week!

@sandoche sandoche merged commit da4d8ab into sandoche:master Jul 11, 2019
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

3 participants