script: add condition prop

This commit is contained in:
jean-emmanuel 2018-08-07 10:43:55 +02:00
parent 9502ac4dc3
commit 74ab465150
2 changed files with 14 additions and 3 deletions

View file

@ -83,10 +83,16 @@
}
```
### `condition`
- type: `string`
- default: `''`
- usage: when the widget receives a value, if this property return a falsy value, the `script` property won't be evaluated. If it's non-falsy, it will be evaluated normally. [Formulas](../extras/advanced-property-syntax/#formulas) are given 1 extra variable in this context:
- `value`: the value received by the widget
### `script`
- type: `string`
- default: `''`
- usage: this property is evaluated each time the widgets receives a non-falsy value. [Formulas](../extras/advanced-property-syntax/#formulas) are given extras variables in this context:
- usage: this property is evaluated each time the widget receives a value if `condition` is non-falsy. [Formulas](../extras/advanced-property-syntax/#formulas) are given extras variables in this context:
- `value`: the value received by the widget
- `send`: `function` for sending osc messages
- `set`: `function` for setting a widget's value
@ -96,6 +102,7 @@
- `address` (`string`): a valid osc address
- `arg`: one or several osc arguments to be sent. The script's `preArgs` property is ignored
#### `set(id, value)`
- `id` (`string`): a widget's id
- `value`: the widget's new value

View file

@ -26,6 +26,7 @@ class Script extends Widget {
_script:'script',
condition: 1,
script:'',
_osc:'osc',
@ -86,7 +87,9 @@ class Script extends Widget {
log: console.log
}
if (v) this.resolveProp('script', undefined, false, false, false, context)
var condition = this.resolveProp('condition', undefined, false, false, false, {value: v})
if (condition) this.resolveProp('script', undefined, false, false, false, context)
// if (options.send) this.sendValue()
if (options.sync) this.changed(options)
@ -97,7 +100,8 @@ class Script extends Widget {
}
Script.dynamicProps = Script.prototype.constructor.dynamicProps.concat(
'script'
'condition',
'script',
)
module.exports = Script