Initial support for dynamic properties

This commit is contained in:
Kevin Sawicki 2017-02-28 16:08:12 -08:00
parent cbb6f8c33e
commit 98f5858b11
10 changed files with 46 additions and 33 deletions

View file

@ -14,6 +14,9 @@ class TouchBar extends EventEmitter {
this.ordereredItems = []
const registerItem = (item) => {
this.items[item.id] = item
item.on('change', () => {
this.emit('change', item.id, item.type)
})
if (item.child instanceof TouchBar) {
item.child.ordereredItems.forEach(registerItem)
}
@ -35,8 +38,9 @@ class TouchBar extends EventEmitter {
}
}
class TouchBarItem {
class TouchBarItem extends EventEmitter {
constructor (config) {
super()
this.id = `${itemIdIncrementor++}`
}
}
@ -81,7 +85,16 @@ TouchBar.Label = class TouchBarLabel extends TouchBarItem {
constructor (config) {
super(config)
this.type = 'label'
this.label = config.label
this._label = config.label
}
set label (newLabel) {
this._label = newLabel
this.emit('change')
}
get label () {
return this._label
}
}