Fix JS linting

This commit is contained in:
Samuel Attard 2016-11-29 18:55:07 +11:00 committed by Kevin Sawicki
parent 257b32b84b
commit 4f0caffc3b
3 changed files with 25 additions and 28 deletions

View file

@ -1,4 +1,4 @@
const {app, BrowserWindow,TouchBar} = require('electron') const {app, BrowserWindow, TouchBar} = require('electron')
const path = require('path') const path = require('path')
let mainWindow = null let mainWindow = null
@ -29,8 +29,8 @@ exports.load = (appUrl) => {
new (TouchBar.Button)({ new (TouchBar.Button)({
label: 'Hello World!', label: 'Hello World!',
// image: '/path/to/image', // image: '/path/to/image',
backgroundColor: "FF0000", backgroundColor: 'FF0000',
labelColor: "0000FF", labelColor: '0000FF',
click: () => { click: () => {
console.log('Hello World Clicked') console.log('Hello World Clicked')
} }
@ -68,7 +68,7 @@ exports.load = (appUrl) => {
change: (newVal) => { change: (newVal) => {
console.log('Slider was changed', newVal, typeof newVal) console.log('Slider was changed', newVal, typeof newVal)
} }
}), })
])) ]))
}) })
} }

View file

@ -1,6 +1,6 @@
'use strict' 'use strict'
const {ipcMain,TouchBar} = require('electron') const {ipcMain, TouchBar} = require('electron')
const {EventEmitter} = require('events') const {EventEmitter} = require('events')
const {BrowserWindow} = process.atomBinding('window') const {BrowserWindow} = process.atomBinding('window')
const v8Util = process.atomBinding('v8_util') const v8Util = process.atomBinding('v8_util')
@ -133,8 +133,8 @@ BrowserWindow.prototype._init = function () {
}) })
// Proxy TouchBar events // Proxy TouchBar events
this.on('-touch-bar-interaction', (event, item_type, id, ...args) => { this.on('-touch-bar-interaction', (event, itemType, id, ...args) => {
TouchBar._event(item_type, id, ...args) TouchBar._event(itemType, id, ...args)
}) })
} }
@ -206,9 +206,9 @@ Object.assign(BrowserWindow.prototype, {
// TouchBar API // TouchBar API
BrowserWindow.prototype.setTouchBar = function (touchBar) { BrowserWindow.prototype.setTouchBar = function (touchBar) {
if (touchBar === null || typeof touchBar === 'undefined') { if (touchBar === null || typeof touchBar === 'undefined') {
this._destroyTouchBar(); this._destroyTouchBar()
} else if (Array.isArray(touchBar)) { } else if (Array.isArray(touchBar)) {
this._setTouchBar((new TouchBar(touchBar)).toJSON()); this._setTouchBar((new TouchBar(touchBar)).toJSON())
} else { } else {
this._setTouchBar(touchBar.toJSON()) this._setTouchBar(touchBar.toJSON())
} }

View file

@ -1,9 +1,6 @@
const {EventEmitter} = require('events')
const {app} = require('electron')
class TouchBar { class TouchBar {
constructor (items) { constructor (items) {
this.items = items; this.items = items
if (!Array.isArray(items)) { if (!Array.isArray(items)) {
throw new Error('The items object provided has to be an array') throw new Error('The items object provided has to be an array')
} }
@ -15,33 +12,33 @@ class TouchBar {
} }
toJSON () { toJSON () {
return this.items.map((item) => item.toJSON ? item.toJSON() : item); return this.items.map((item) => item.toJSON ? item.toJSON() : item)
} }
} }
let item_id_incrementor = 1 let itemIdIncrementor = 1
const item_event_handlers = {} const itemEventHandlers = {}
TouchBar._event = (itemType, eventArgs) => { TouchBar._event = (itemType, eventArgs) => {
let args = eventArgs.slice(1) let args = eventArgs.slice(1)
if (itemType === 'slider') { if (itemType === 'slider') {
args = args.map(val => parseInt(val, 10)) args = args.map(val => parseInt(val, 10))
} }
const id_parts = eventArgs[0].split('.') const idParts = eventArgs[0].split('.')
const item_id = id_parts[id_parts.length - 1] const itemId = idParts[idParts.length - 1]
if (item_event_handlers[item_id]) item_event_handlers[item_id](...args) if (itemEventHandlers[itemId]) itemEventHandlers[itemId](...args)
} }
class TouchBarItem { class TouchBarItem {
constructor (config) { constructor (config) {
this.id = item_id_incrementor++ this.id = itemIdIncrementor++
const mConfig = Object.assign({}, config || {}) const mConfig = Object.assign({}, config || {})
Object.defineProperty(this, 'config', { Object.defineProperty(this, 'config', {
configurable: false, configurable: false,
enumerable: false, enumerable: false,
get: () => mConfig get: () => mConfig
}) })
this.config.id = `${this.config.id || this.id}`; this.config.id = `${this.config.id || this.id}`
if (typeof this.config !== 'object' || this.config === null) { if (typeof this.config !== 'object' || this.config === null) {
throw new Error('Provided config must be a non-null object') throw new Error('Provided config must be a non-null object')
} }
@ -58,7 +55,7 @@ TouchBar.Button = class TouchBarButton extends TouchBarItem {
this.config.type = 'button' this.config.type = 'button'
const click = config.click const click = config.click
if (typeof click === 'function') { if (typeof click === 'function') {
item_event_handlers[`${this.id}`] = click itemEventHandlers[`${this.id}`] = click
} }
} }
} }
@ -69,7 +66,7 @@ TouchBar.ColorPicker = class TouchBarColorPicker extends TouchBarItem {
this.config.type = 'colorpicker' this.config.type = 'colorpicker'
const change = this.config.change const change = this.config.change
if (typeof change === 'function') { if (typeof change === 'function') {
item_event_handlers[`${this.id}`] = change itemEventHandlers[`${this.id}`] = change
} }
} }
} }
@ -81,7 +78,7 @@ TouchBar.Group = class TouchBarGroup extends TouchBarItem {
} }
toJSON () { toJSON () {
const config = this.config; const config = this.config
return Object.assign({}, config, { return Object.assign({}, config, {
items: config.items && config.items.toJSON ? config.items.toJSON() : [] items: config.items && config.items.toJSON ? config.items.toJSON() : []
}) })
@ -102,7 +99,7 @@ TouchBar.PopOver = class TouchBarPopOver extends TouchBarItem {
} }
toJSON () { toJSON () {
const config = this.config; const config = this.config
return Object.assign({}, config, { return Object.assign({}, config, {
touchBar: config.touchBar && config.touchBar.toJSON ? config.touchBar.toJSON() : [] touchBar: config.touchBar && config.touchBar.toJSON ? config.touchBar.toJSON() : []
}) })
@ -112,12 +109,12 @@ TouchBar.PopOver = class TouchBarPopOver extends TouchBarItem {
TouchBar.Slider = class TouchBarSlider extends TouchBarItem { TouchBar.Slider = class TouchBarSlider extends TouchBarItem {
constructor (config) { constructor (config) {
super(config) super(config)
this.config.type = 'slider'; this.config.type = 'slider'
const change = this.config.change const change = this.config.change
if (typeof change === 'function') { if (typeof change === 'function') {
item_event_handlers[this.id] = change itemEventHandlers[this.id] = change
} }
} }
} }
module.exports = TouchBar; module.exports = TouchBar