clean falsy statements

This commit is contained in:
Shelley Vohr 2017-10-24 18:52:12 -04:00
parent 75f32afcd5
commit e8935232b1
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -18,19 +18,19 @@ Menu.prototype._init = function () {
this.groupsMap = {} this.groupsMap = {}
this.items = [] this.items = []
this.delegate = { this.delegate = {
isCommandIdChecked: id => this.commandsMap[id].checked, isCommandIdChecked: id => this.commandsMap[id] ? this.commandsMap[id].checked : undefined,
isCommandIdEnabled: id => this.commandsMap[id].enabled, isCommandIdEnabled: id => this.commandsMap[id] ? this.commandsMap[id].enabled : undefined,
isCommandIdVisible: id => this.commandsMap[id].visible, isCommandIdVisible: id => this.commandsMap[id] ? this.commandsMap[id].visible : undefined,
getAcceleratorForCommandId: (id, useDefaultAccelerator) => { getAcceleratorForCommandId: (id, useDefaultAccelerator) => {
const command = this.commandsMap[id] const command = this.commandsMap[id]
if (command === null) return if (!command) return
if (command.accelerator !== null) return command.accelerator if (command.accelerator) return command.accelerator
if (useDefaultAccelerator) return command.getDefaultRoleAccelerator() if (useDefaultAccelerator) return command.getDefaultRoleAccelerator()
}, },
getIconForCommandId: id => this.commandsMap[id].icon, getIconForCommandId: id => this.commandsMap[id] ? this.commandsMap[id].icon : undefined,
executeCommand: (event, id) => { executeCommand: (event, id) => {
const command = this.commandsMap[id] const command = this.commandsMap[id]
if (command === null) return if (!command) return
command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents()) command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents())
}, },
menuWillShow: () => { menuWillShow: () => {
@ -49,7 +49,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window] let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window]
// menu.popup(x, y, positioningItem) // menu.popup(x, y, positioningItem)
if (window !== null) { if (!window) {
// shift over values // shift over values
if (typeof window !== 'object' || window.constructor !== BrowserWindow) { if (typeof window !== 'object' || window.constructor !== BrowserWindow) {
[newPosition, newY, newX, newWindow] = [y, x, window, null] [newPosition, newY, newX, newWindow] = [y, x, window, null]
@ -57,7 +57,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
} }
// menu.popup(window, {}) // menu.popup(window, {})
if (x !== null && typeof x === 'object') { if (x && typeof x === 'object') {
const opts = x const opts = x
newX = opts.x newX = opts.x
newY = opts.y newY = opts.y
@ -69,7 +69,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
if (typeof x !== 'number') newX = -1 if (typeof x !== 'number') newX = -1
if (typeof y !== 'number') newY = -1 if (typeof y !== 'number') newY = -1
if (typeof positioningItem !== 'number') newPosition = -1 if (typeof positioningItem !== 'number') newPosition = -1
if (window === null) newWindow = BrowserWindow.getFocusedWindow() if (!window) newWindow = BrowserWindow.getFocusedWindow()
if (typeof asyncPopup !== 'boolean') asyncPopup = false if (typeof asyncPopup !== 'boolean') asyncPopup = false
this.popupAt(newWindow, newX, newY, newPosition, asyncPopup) this.popupAt(newWindow, newX, newY, newPosition, asyncPopup)
@ -77,12 +77,10 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
// close an existing popup // close an existing popup
Menu.prototype.closePopup = function (window) { Menu.prototype.closePopup = function (window) {
if (window == null || window.constructor !== BrowserWindow) { if (!window || window.constructor !== BrowserWindow) {
window = BrowserWindow.getFocusedWindow() window = BrowserWindow.getFocusedWindow()
} }
if (window != null) { if (window) this.closePopupAt(window.id)
this.closePopupAt(window.id)
}
} }
// return a MenuItem with the specified id // return a MenuItem with the specified id
@ -105,7 +103,7 @@ Menu.prototype.append = function (item) {
// insert a new menu item at a specified location // insert a new menu item at a specified location
Menu.prototype.insert = function (pos, item) { Menu.prototype.insert = function (pos, item) {
if ((item != null ? item.constructor : void 0) !== MenuItem) { if ((item ? item.constructor : void 0) !== MenuItem) {
throw new TypeError('Invalid item') throw new TypeError('Invalid item')
} }
@ -113,9 +111,9 @@ Menu.prototype.insert = function (pos, item) {
insertItemByType.call(this, item, pos) insertItemByType.call(this, item, pos)
// set item properties // set item properties
if (item.sublabel != null) this.setSublabel(pos, item.sublabel) if (item.sublabel) this.setSublabel(pos, item.sublabel)
if (item.icon != null) this.setIcon(pos, item.icon) if (item.icon) this.setIcon(pos, item.icon)
if (item.role != null) this.setRole(pos, item.role) if (item.role) this.setRole(pos, item.role)
// Make menu accessable to items. // Make menu accessable to items.
item.overrideReadOnlyProperty('menu', this) item.overrideReadOnlyProperty('menu', this)
@ -127,9 +125,9 @@ Menu.prototype.insert = function (pos, item) {
// Force menuWillShow to be called // Force menuWillShow to be called
Menu.prototype._callMenuWillShow = function () { Menu.prototype._callMenuWillShow = function () {
if (this.delegate != null) this.delegate.menuWillShow() if (this.delegate) this.delegate.menuWillShow()
this.items.forEach(item => { this.items.forEach(item => {
if (item.submenu != null) item.submenu._callMenuWillShow() if (item.submenu) item.submenu._callMenuWillShow()
}) })
} }
@ -142,13 +140,13 @@ Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
// set application menu with a preexisting menu // set application menu with a preexisting menu
Menu.setApplicationMenu = function (menu) { Menu.setApplicationMenu = function (menu) {
if (!(menu === null || menu.constructor === Menu)) { if (!(menu || menu.constructor === Menu)) {
throw new TypeError('Invalid menu') throw new TypeError('Invalid menu')
} }
applicationMenu = menu applicationMenu = menu
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
if (menu === null) return if (!menu) return
menu._callMenuWillShow() menu._callMenuWillShow()
bindings.setApplicationMenu(menu) bindings.setApplicationMenu(menu)
} else { } else {
@ -205,7 +203,7 @@ function generateGroupId (items, pos) {
// Returns the index of item according to |id|. // Returns the index of item according to |id|.
function indexOfItemById (items, id) { function indexOfItemById (items, id) {
const foundItem = items.find(item => item.id === id) || null const foundItem = items.find(item => item.id === id) || -1
return items.indexOf(foundItem) return items.indexOf(foundItem)
} }
@ -218,7 +216,7 @@ function indexToInsertByPosition (items, position) {
// warn if query doesn't exist // warn if query doesn't exist
if (idx === -1 && query !== 'endof') { if (idx === -1 && query !== 'endof') {
console.warn("Item with id '" + id + "' is not found") console.warn(`Item with id ${id} is not found`)
return items.length return items.length
} }