docs: script details

This commit is contained in:
bordun 2020-10-28 17:01:53 +01:00
parent 23084dbf28
commit f1e50ee740
2 changed files with 7 additions and 8 deletions

View file

@ -18,7 +18,7 @@ A widget can fetch its own properties or its direct parent's by using the keywor
#### `uuid`
Each widget has a unique random identifier that can be retreived with the property name `uuid` (e.g. `@{this.uuid}`, `@{parent.uuid}`).
Each widget has a unique random identifier that can be retreived with the property name `uuid` (e.g. `@{this.uuid}`, `@{parent.uuid}`).
#### Dynamic properties
@ -65,7 +65,7 @@ Options can contain `@{}` blocks.
## Javascript: `JS{{ <code> }}`
This syntax allows writing formulas in pure javascript. The code will be compiled as a function and executed in a restricted context.
This syntax allows writing formulas in [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context.
- if no `return` statement is found, the formula will return an empty string
- javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled
@ -84,7 +84,7 @@ A property cannot contain multiple `JS{{}}` blocks
- `url`: server url,
- `platform`: operating system as seen by the client
In this context, `@{} / OSC{}` are also seen as variables (named `VAR_XXX`), not as the value they hold,
In this context, `@{} / OSC{}` are also seen as variables (named `VAR_XXX`), not as the value they hold.
Parsing errors can be read in the DevTool console (F12).

View file

@ -1,12 +1,11 @@
# Scripting
The `script` property allows widgets to run javascript code when their value update. It differs from the [javascript property syntax ](./advanced-syntaxes.md#available-variables) in the following ways:
The `script` property allows widgets to run [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) code when their value update.
- no `JS{{}}` wrapper, just the code
- `@{}`, `OSC{}`, `JS{{}}` and `#{}` blocks are replaced with their value before the script's compilation
!!! info "It's slightly different from the [javascript property syntax ](./advanced-syntaxes/#javascript-js-code)"
!!! warning "Avoid advanced syntax in scripts"
To avoid syntax errors it is recommended to use `getProp()` and `get()` instead of `@{}` and `OSC{}`. `JS{{}}` and `#{}` blocks should be avoided here as well.
- no `JS{{}}` wrapper, just the code
- `@{}`, `OSC{}`, `JS{{}}` and `#{}` blocks are replaced with their literal value before the script's compilation, therefore **it is recommended to avoid these syntaxes** and use `getProp()` and `get()` instead.
## Event-dependent variables