script: add id to context

This commit is contained in:
jean-emmanuel 2019-06-25 12:13:19 +02:00
parent 4628fd4b94
commit 9c2398aa38
4 changed files with 11 additions and 6 deletions

View file

@ -7,6 +7,7 @@
- modal: `scroll` option
- script: `get(id)` function added in `script`execution context
- script: `getProp(id, property)` function added in `script`execution context
- script: `id` variable added in `script`execution context (id of the widget that triggered the script)
## 0.46.1

View file

@ -52,7 +52,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
let v = widget.getValue()
for (let i in widgetsById) {
if (widgetsById[i] !== widget) {
widgetsById[i].setValue(v,{send:false,sync:false})
widgetsById[i].setValue(v,{send:false,sync:false, id})
}
}
}
@ -63,7 +63,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
let v = widget.getValue()
for (let i in widgetsByLinkId) {
if (widgetsByLinkId[i] !== widget) {
widgetsByLinkId[i].setValue(v,{send: options.send,sync: true})
widgetsByLinkId[i].setValue(v,{send: options.send,sync: true, id})
}
}
}

View file

@ -672,6 +672,8 @@ class Widget extends EventEmitter {
propNames.push('value')
}
if (widget && options) options.id = widget.getProp('id')
var reCreate = false,
changedProps = []
@ -713,7 +715,6 @@ class Widget extends EventEmitter {
}
for (var i in changedProps) {
this.onPropChanged(changedProps[i].propName, options, changedProps[i].oldPropValue)
}
@ -728,12 +729,12 @@ class Widget extends EventEmitter {
}
onPropChanged(propName, options, oldPropValue) {
onPropChanged(propName, options={}, oldPropValue) {
switch(propName) {
case 'value':
this.setValue(this.getProp('value'), {sync: true, send: options && options.send})
this.setValue(this.getProp('value'), {sync: true, send: options.send, id: options.id})
return
case 'top':

View file

@ -25,7 +25,8 @@ class Script extends Widget {
]},
script: {type: 'string', value: '', help: [
'This property is evaluated each time the widget receives a value* if condition is non-falsy. Formulas are given extras variables in this context:',
'- `value`: the value received by the widget',
'- `value`: value received by the widget',
'- `id`: id of the widget that triggered the script',
'- `send(target, address, arg1, arg2, ...)`: function for sending osc messages (ignores the script\'s targets and the server\'s defaults unless `target` is `false`; ignores the script\'s `preArgs`)',
'- `set(id, value)`: function for setting a widget\'s value',
'- `get(id)`: function for getting a widget\'s value',
@ -109,6 +110,7 @@ class Script extends Widget {
var context = {
value: v,
id: options.id,
send: options.send ? this.scriptSend.bind(this) : ()=>{},
set: (id, value)=>{Script.scriptSet(id, value, options)},
get: (id)=>{return Script.scriptGet(id)},
@ -134,6 +136,7 @@ Script.parsersContexts.condition = {
Script.parsersContexts.script = {
value: '',
id: '',
send: ()=>{},
set: ()=>{},
get: ()=>{},