script: add updateProp() to force prop check on a widget

This commit is contained in:
bordun 2020-05-22 15:33:36 +02:00
parent fab0ed0eab
commit 0e5edb76de
2 changed files with 24 additions and 1 deletions

View file

@ -64,6 +64,14 @@ Returns the property called `"name"` of the first matching widget.
----
#### `updateProp`: `function(id, name)`
- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget.
- `name`: property name.
Forcers a widget to check if one of its properties has changed and update itself if needed.
----
#### `httpGet`: `function(url, callback)`
- `url`: url of the resource to fetch (local url only)

View file

@ -132,6 +132,21 @@ class ScriptVm extends Vm {
}
this.sandbox.contentWindow.updateProp = (id, prop)=>{
var widgets = this.resolveId(id),
widget = this.getWidget()
if (widget.builtIn) widget = widget.parent
for (var i = widgets.length - 1; i >= 0; i--) {
widgets[i].updateProps(Array.isArray(prop) ? prop : [prop], widget)
}
}
this.sandbox.contentWindow.httpGet = (url, callback)=>{
var parser = urlParser(url),
@ -263,7 +278,7 @@ class ScriptVm extends Vm {
}
for (var imports of ['set', 'get', 'getProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
for (var imports of ['set', 'get', 'getProp', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout']) {
this.sanitize(this.sandbox.contentWindow[imports])
}