advanced syntaxes: @{} and VAR{} do not return a copy of their value anymore as it may introduce a significant overhead when used extensively. Mutating these objects in #{} and JS{} scripts will now affect the actual values and should be avoided at all cost.
This commit is contained in:
parent
cafb8b904a
commit
887ea569db
4 changed files with 18 additions and 8 deletions
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
- advanced syntaxes
|
||||
- `@{}` and `VAR{}` do not return a copy of their value anymore as it may introduce a significant overhead when used extensively. Mutating these objects in `#{}` and `JS{}` scripts will now affect the actual values and should be avoided at all cost.
|
||||
|
||||
## 1.15.8
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ Options can contain `@{}` blocks.
|
|||
|
||||
## Custom variables: `VAR{variableName, default}`
|
||||
|
||||
This syntax creates a custom variable in the widget that can be read and modified from any widget's script property (see [scripting](./scripting.md#getvarid-name)). Changes made to this variable will be applied automatically.
|
||||
This syntax creates a custom variable in the widget that can be read and modified from any widget's script property (see [scripting](./scripting.md#getvarid-name)). Changes made to this variable using `setVar()` in scripts will be applied automatically where `VAR{}` is used.`
|
||||
|
||||
## File imports: `IMPORT{file_name}`
|
||||
|
||||
|
|
@ -99,13 +99,20 @@ A property *cannot* contain multiple `JS{}` blocks
|
|||
- `session`: session file path
|
||||
- `clipboard`: instance of navigator [Clipboard](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard)
|
||||
|
||||
In this context, `@{} / OSC{}` are seen as variables. When they change, the whole block will be evaluated again.
|
||||
|
||||
Parsing errors can be read in the console (++ctrl+k++).
|
||||
|
||||
!!! warning
|
||||
Modifying values in `locals` or `globals` **does not** trigger anything if they are used somewhere else.
|
||||
|
||||
#### Using in advanced syntaxes
|
||||
|
||||
In this context, `@{}`, `VAR{}` and `OSC{}` syntaxes are seen as variables. When they change, the whole block will be evaluated again.
|
||||
|
||||
!!! danger "Do not mutate"
|
||||
When these syntaxes return objects or arrays, mutating said objects will affect the underlying variables in memory and may lead to unexpected behavior.
|
||||
|
||||
The `@{}` syntax, when used for anything else than the widget's value, will always return a copy of the property and is not affected by this.
|
||||
|
||||
## Javascript: `#{ <code> }`
|
||||
|
||||
This is a shorthand for the `JS{}` syntax, the only difference being that `<code>` is automatically prepended with a `return` statement.
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ The following variables and functions are accessible in this context.
|
|||
#### `get(id)`
|
||||
- `id`: widget `id` as a string.
|
||||
|
||||
Returns the value of the first matching widget.
|
||||
Returns the value of the first matching widget. If the returned value is an object, a copy is returned to allow safe mutation.
|
||||
|
||||
----
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ If the event that triggered the script's execution was initiated by a user inter
|
|||
- `id`: widget `id` as a string.
|
||||
- `name`: variable name as a string.
|
||||
|
||||
Returns the value of a widget's custom variable.
|
||||
Returns the value of a widget's custom variable. If the returned value is an object, a copy is returned to allow safe mutation.
|
||||
|
||||
----
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ This function ignores the widget's `bypass` and `ignoreDefaults` properties.
|
|||
- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget.
|
||||
- `name`: property name.
|
||||
|
||||
Returns the property called `"name"` of the first matching widget.
|
||||
Returns the property called `"name"` of the first matching widget. If the returned value is an object, a copy is returned to allow safe mutation.
|
||||
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ class Widget extends EventEmitter {
|
|||
var r
|
||||
switch (k) {
|
||||
case 'value':
|
||||
r = widgets[i].getValue(true)
|
||||
r = widgets[i].value
|
||||
break
|
||||
case 'uuid':
|
||||
r = widgets[i].hash
|
||||
|
|
@ -746,7 +746,7 @@ class Widget extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
var r = deepCopy(this.variables[name].value)
|
||||
var r = this.variables[name].value
|
||||
|
||||
var varname = 'VAR_' + varnumber
|
||||
varnumber--
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue