Skip to content

DRY entry point#370

Open
TheJaredWilcurt wants to merge 1 commit intomikaelbr:masterfrom
TheJaredWilcurt:patch-1
Open

DRY entry point#370
TheJaredWilcurt wants to merge 1 commit intomikaelbr:masterfrom
TheJaredWilcurt:patch-1

Conversation

@TheJaredWilcurt
Copy link
Copy Markdown

There was a simple repeating pattern that could be made more DRY with a map.

There was a simple repeating pattern that could be made more DRY with a map.
Comment thread index.js
osType = 'WSL';
}

return osType.toLowerCase();
Copy link
Copy Markdown
Author

@TheJaredWilcurt TheJaredWilcurt Apr 8, 2021

Choose a reason for hiding this comment

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

Store all of the logic for determining the OS in one function. Keeps all the related code together. Also easier for unit testing if you ever decide to do that. May want to move this to the utils file.

Comment thread index.js
windows_7_and_below: WindowsBalloon,
windows_nt: WindowsToaster,
wsl: WindowsToaster
};
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Convert the giant Switch block over to a simple object that maps the the only two unique pieces of information, the OS and the notifier to use.

Comment thread index.js
wsl: WindowsToaster
};

var osNotifier = osMap[getOsType()] || Growl;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Get the correct OS, use that to get the correct notifier, or default to Growl.

Comment thread index.js

// Set the notifier specific to the current OS
module.exports = new osNotifier(options);
module.exports.Notification = osNotifier;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No longer repeated 7 times

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.

1 participant