Make label and colorpicker types work

This commit is contained in:
Samuel Attard 2016-11-28 18:24:48 +11:00 committed by Kevin Sawicki
parent 7857c83ea1
commit 18c7c3ece8
8 changed files with 64 additions and 27 deletions

View file

@ -23,8 +23,9 @@ class TouchBar {
let item_id_incrementor = 1
const item_event_handlers = {}
TouchBar._event = (id, ...args) => {
const id_parts = id.split('.')
TouchBar._event = (eventArgs) => {
const args = eventArgs.slice(1)
const id_parts = eventArgs[0].split('.')
const item_id = id_parts[id_parts.length - 1]
if (item_event_handlers[item_id]) item_event_handlers[item_id](...args)
}
@ -39,7 +40,6 @@ class TouchBarItem {
get: () => mConfig
})
this.config.id = `${this.config.id || this.id}`;
this.config.type = 'button';
if (typeof this.config !== 'object' || this.config === null) {
throw new Error('Provided config must be a non-null object')
}
@ -53,7 +53,7 @@ class TouchBarItem {
TouchBar.Button = class TouchBarButton extends TouchBarItem {
constructor (config) {
super(config)
this.config.type = 'button';
this.config.type = 'button'
const click = config.click
if (typeof click === 'function') {
item_event_handlers[`${this.id}`] = click
@ -64,22 +64,27 @@ TouchBar.Button = class TouchBarButton extends TouchBarItem {
TouchBar.ColorPicker = class TouchBarColorPicker extends TouchBarItem {
constructor (config) {
super(config)
this.config.type = 'colorpicker';
const change = config.change
this.config.type = 'colorpicker'
const change = this.config.change
if (typeof change === 'function') {
item_event_handlers[`${this.id}`] = change
}
}
}
TouchBar.Label = class TouchBarLabel extends TouchBarItem {}
TouchBar.Label = class TouchBarLabel extends TouchBarItem {
constructor (config) {
super(config)
this.config.type = 'label'
}
}
TouchBar.List = class TouchBarList extends TouchBarItem {}
TouchBar.Slider = class TouchBarSlider extends TouchBarItem {
constructor (config) {
super(config)
const change = config.change
const change = this.config.change
if (typeof change === 'function') {
item_event_handlers[this.id] = change
}