From 7f632ef081a6a75b9472d0e394818ffc9a128e26 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 7 Aug 2018 10:43:55 +0200 Subject: [PATCH] script: add condition prop --- resources/docs/widgets/inputs.md | 9 ++++++++- src/browser/js/app/widgets/inputs/script.js | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/resources/docs/widgets/inputs.md b/resources/docs/widgets/inputs.md index ab62add4..854db9ef 100644 --- a/resources/docs/widgets/inputs.md +++ b/resources/docs/widgets/inputs.md @@ -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 diff --git a/src/browser/js/app/widgets/inputs/script.js b/src/browser/js/app/widgets/inputs/script.js index 4ba0efe2..389672bd 100644 --- a/src/browser/js/app/widgets/inputs/script.js +++ b/src/browser/js/app/widgets/inputs/script.js @@ -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