Add move live updating properties
This commit is contained in:
parent
61aa9bbff4
commit
5f9e9d4b36
2 changed files with 53 additions and 84 deletions
|
@ -96,16 +96,33 @@ class TouchBarItem extends EventEmitter {
|
|||
super()
|
||||
this.id = `${nextItemID++}`
|
||||
}
|
||||
|
||||
_addLiveProperty (name, initialValue) {
|
||||
const privateName = `_${name}`
|
||||
this[privateName] = initialValue
|
||||
Object.defineProperty(this, name, {
|
||||
get: function () {
|
||||
return this[privateName]
|
||||
},
|
||||
set: function (value) {
|
||||
this[privateName] = value
|
||||
this.emit('change')
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
TouchBar.Button = class TouchBarButton extends TouchBarItem {
|
||||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'button'
|
||||
this.label = config.label
|
||||
this.backgroundColor = config.backgroundColor
|
||||
this.labelColor = config.labelColor
|
||||
this.onInteraction = config.click
|
||||
const {click, label, backgroundColor} = config
|
||||
this._addLiveProperty('label', label)
|
||||
this._addLiveProperty('backgroundColor', backgroundColor)
|
||||
if (typeof click === 'function') {
|
||||
this.onInteraction = config.click
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,12 +130,13 @@ TouchBar.ColorPicker = class TouchBarColorPicker extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'colorpicker'
|
||||
this.availableColors = config.availableColors
|
||||
this.selectedColor = config.selectedColor
|
||||
const {availableColors, change, selectedColor} = config
|
||||
this._addLiveProperty('availableColors', availableColors)
|
||||
this._addLiveProperty('selectedColor', selectedColor)
|
||||
|
||||
const {change} = config
|
||||
if (typeof change === 'function') {
|
||||
this.onInteraction = (details) => {
|
||||
this._selectedColor = details.color
|
||||
change(details.color)
|
||||
}
|
||||
}
|
||||
|
@ -140,16 +158,7 @@ TouchBar.Label = class TouchBarLabel extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'label'
|
||||
this._label = config.label
|
||||
}
|
||||
|
||||
set label (newLabel) {
|
||||
this._label = newLabel
|
||||
this.emit('change')
|
||||
}
|
||||
|
||||
get label () {
|
||||
return this._label
|
||||
this._addLiveProperty('label', config.label)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +166,7 @@ TouchBar.Spacer = class TouchBarSpacer extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'spacer'
|
||||
this.size = config.size
|
||||
this._addLiveProperty('size', config.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +174,7 @@ TouchBar.Popover = class TouchBarPopover extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'popover'
|
||||
this.label = config.label
|
||||
this._addLiveProperty('label', config.label)
|
||||
this.showCloseButton = config.showCloseButton
|
||||
this.child = config.items
|
||||
if (!(this.child instanceof TouchBar)) {
|
||||
|
@ -178,13 +187,15 @@ TouchBar.Slider = class TouchBarSlider extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'slider'
|
||||
this.minValue = config.minValue
|
||||
this.maxValue = config.maxValue
|
||||
this.initialValue = config.initialValue
|
||||
const {change, label, minValue, maxValue, value} = config
|
||||
this._addLiveProperty('label', label)
|
||||
this._addLiveProperty('minValue', minValue)
|
||||
this._addLiveProperty('maxValue', maxValue)
|
||||
this._addLiveProperty('value', value)
|
||||
|
||||
const {change} = config
|
||||
if (typeof change === 'function') {
|
||||
this.onInteraction = (details) => {
|
||||
this._value = details.value
|
||||
change(details.value)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue