diff --git a/CHANGELOG.md b/CHANGELOG.md index b2a9cfe5..b658665d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/resources/docs/docs/widgets/advanced-syntaxes.md b/resources/docs/docs/widgets/advanced-syntaxes.md index 05bceb7e..c36c8224 100644 --- a/resources/docs/docs/widgets/advanced-syntaxes.md +++ b/resources/docs/docs/widgets/advanced-syntaxes.md @@ -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: `#{ }` This is a shorthand for the `JS{}` syntax, the only difference being that `` is automatically prepended with a `return` statement. diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 39df6b4d..dd2660e5 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -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. ---- diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 23ade29a..459d3468 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -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--