refactoring: continue prop defaults refactor
This commit is contained in:
parent
9b3cb19091
commit
3ac0a0eddf
15 changed files with 37 additions and 24 deletions
|
|
@ -25,7 +25,7 @@ var Editor = class Editor {
|
|||
|
||||
this.defaults = {}
|
||||
for (var k in widgets) {
|
||||
this.defaults[k] = widgets[k].defaults()
|
||||
this.defaults[k] = widgets[k].defaults()._props()
|
||||
}
|
||||
|
||||
this.selectedWidgets = []
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
address = widget ? widget.getProp('address') : address
|
||||
|
||||
if (!Array.isArray(preArgs) && preArgs !== '') preArgs = [preArgs]
|
||||
if (preArgs === '') preArgs = []
|
||||
|
||||
preArgs = preArgs.map(x=>typeof x === 'object' && x !== null && x.value !== undefined ? x.value : x)
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ var Parser = class Parser {
|
|||
delete props.noSync
|
||||
}
|
||||
// Safe copy widget's options
|
||||
let defaults = this.widgets[props.type].defaults()
|
||||
let defaults = this.widgets[props.type].defaults()._props()
|
||||
|
||||
// Set widget's undefined options to default
|
||||
for (let i in defaults) {
|
||||
|
|
|
|||
|
|
@ -83,13 +83,13 @@ class Widget extends EventEmitter {
|
|||
'Values can be defined as objects if the osc type tag needs to be specified: `{type: "i", value: 1}`'
|
||||
]},
|
||||
target: {type: 'string|array|null', value: '', help: [
|
||||
'An string or or array of strings formatted as follow: `ip:port` or `["ip:port"]`.',
|
||||
'If midi is enabled, targets can be `midi:device_name`.',
|
||||
'The special item `"self"` can be used to refer to the emitting client directly.',
|
||||
'If no target is set, messages can still be sent if the server has default targets',
|
||||
'The server\'s default targets can be bypassed by setting of the items to `null`'
|
||||
'- A `string` or `array` of strings formatted as follow: `ip:port` or `["ip:port"]`',
|
||||
'- If midi is enabled, targets can be `midi:device_name`',
|
||||
'- The special item `"self"` can be used to refer to the emitting client directly.',
|
||||
'- If no target is set, messages can still be sent if the server has default targets',
|
||||
'- The server\'s default targets can be bypassed by setting of the items to `null`'
|
||||
]},
|
||||
bypass: {type: 'boolean', value: false, help: 'Set to `true` to prevent the widget from sending any osc message'}
|
||||
bypass: {type: 'boolean', value: false, help: 'Set to `true` to prevent the widget from sending any osc message'}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +110,17 @@ class Widget extends EventEmitter {
|
|||
alterDefaults[m] = push[m]
|
||||
}
|
||||
|
||||
alterDefaults._props = function() {
|
||||
var props = {}
|
||||
for (var k in this) {
|
||||
if (k[0] !== '_') {
|
||||
props[k] = this[k].value
|
||||
}
|
||||
}
|
||||
return props
|
||||
}
|
||||
|
||||
|
||||
return alterDefaults
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module.exports = class Root extends Panel {
|
|||
|
||||
_children:'children',
|
||||
|
||||
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
|
||||
variables: {type: '*', value: {}, help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
|
||||
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object'},
|
||||
id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ module.exports = class Strip extends Panel {
|
|||
|
||||
constructor(options) {
|
||||
|
||||
var defaults = Panel.defaults()
|
||||
var defaults = Panel.defaults()._props()
|
||||
for (var k in defaults) {
|
||||
if (!options.props.hasOwnProperty(k))
|
||||
options.props[k] = defaults[k]
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ module.exports.widgets = {
|
|||
|
||||
// maths
|
||||
// deprecated / hidden
|
||||
formula: require('./maths/formula')
|
||||
// formula: require('./maths/formula')
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ module.exports = class Formula extends Widget {
|
|||
|
||||
this.input = new Input({
|
||||
props:{
|
||||
...Input.defaults(),
|
||||
...Input.defaults()._props(),
|
||||
editable:false,
|
||||
precision:this.getProp('precision'),
|
||||
unit: this.getProp('unit')
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var Pad = require('./pad'),
|
|||
touchstate = require('../mixins/touch_state')
|
||||
|
||||
|
||||
var xyDefaults = Xy.defaults()
|
||||
var xyDefaults = Xy.defaults()._props()
|
||||
|
||||
|
||||
module.exports = class MultiXy extends Pad {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ var Pad = require('./pad'),
|
|||
{clip, hsbToRgb, rgbToHsb} = require('../utils'),
|
||||
Input = require('../inputs/input')
|
||||
|
||||
var faderDefaults = Fader.defaults(),
|
||||
xyDefaults = Xy.defaults()
|
||||
var faderDefaults = Fader.defaults()._props(),
|
||||
xyDefaults = Xy.defaults()._props()
|
||||
|
||||
module.exports = class Rgb extends Pad {
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ module.exports = class Rgb extends Pad {
|
|||
if (this.getProp('input')) {
|
||||
|
||||
this.input = new Input({
|
||||
props:{...Input.defaults(), precision:this.getProp('precision'), unit:this.getProp('unit')},
|
||||
props:{...Input.defaults()._props(), precision:this.getProp('precision'), unit:this.getProp('unit')},
|
||||
parent:this, parentNode:this.widget
|
||||
})
|
||||
this.widget.appendChild(this.input.widget)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var Pad = require('./pad'),
|
|||
Input = require('../inputs/input'),
|
||||
touchstate = require('../mixins/touch_state')
|
||||
|
||||
var faderDefaults = Fader.defaults()
|
||||
var faderDefaults = Fader.defaults()._props()
|
||||
|
||||
module.exports = class Xy extends Pad {
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ module.exports = class Xy extends Pad {
|
|||
if (this.getProp('input')) {
|
||||
|
||||
this.input = new Input({
|
||||
props:{...Input.defaults(), precision:this.getProp('precision'), unit:this.getProp('unit')},
|
||||
props:{...Input.defaults()._props(), precision:this.getProp('precision'), unit:this.getProp('unit')},
|
||||
parent:this, parentNode:this.widget
|
||||
})
|
||||
this.widget.appendChild(this.input.widget)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var {clip} = require('../utils'),
|
|||
Input = require('../inputs/input'),
|
||||
touchstate = require('../mixins/touch_state')
|
||||
|
||||
var faderDefaults = Fader.defaults()
|
||||
var faderDefaults = Fader.defaults()._props()
|
||||
|
||||
var RangeFader = class RangeFader extends Fader {
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ module.exports = class Range extends Widget {
|
|||
if (this.getProp('input')) {
|
||||
|
||||
this.input = new Input({
|
||||
props:{...Input.defaults(),
|
||||
props:{...Input.defaults()._props(),
|
||||
precision:this.getProp('precision'),
|
||||
unit:this.getProp('unit'),
|
||||
vertical: this.getProp('compact') && !this.getProp('horizontal')
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class Slider extends Canvas {
|
|||
|
||||
this.input = new Input({
|
||||
props:{
|
||||
...Input.defaults(),
|
||||
...Input.defaults()._props(),
|
||||
precision:this.getProp('precision'),
|
||||
unit:this.getProp('unit'),
|
||||
vertical: this.getProp('type') == 'fader' && this.getProp('compact') && !this.getProp('horizontal')
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
var Switcher = require('./switcher'),
|
||||
Widget = require('../common/widget'),
|
||||
Fader = require('../sliders/fader'),
|
||||
{mapToScale} = require('../utils')
|
||||
|
||||
var faderDefaults = Fader.defaults()
|
||||
var faderDefaults = Fader.defaults()._props()
|
||||
|
||||
|
||||
module.exports = class Crossfader extends Switcher {
|
||||
|
||||
static defaults(){
|
||||
|
||||
return super.defaults({
|
||||
return Widget.defaults({
|
||||
|
||||
_crossfader: 'crossfader',
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var _switchers_base = require('./_switchers_base'),
|
||||
Switch = require('../buttons/switch')
|
||||
|
||||
var switchDefaults = Switch.defaults()
|
||||
var switchDefaults = Switch.defaults()._props()
|
||||
|
||||
module.exports = class Switcher extends _switchers_base {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue