Skip to content

Commit 2a790b3

Browse files
committed
README: let & const working now for UI-based scripts, mention disable dependency tracking
Refs openhab/openhab-addons#19019. Signed-off-by: Florian Hotze <dev@florianhotze.com>
1 parent 0762b50 commit 2a790b3

1 file changed

Lines changed: 3 additions & 20 deletions

File tree

README.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,6 @@ console.log(event.itemState.toString() == "test") // OK
178178

179179
The openHAB JavaScript Scripting runtime attempts to provide a familiar environment to JavaScript developers.
180180

181-
### `let` and `const`
182-
183-
Due to the way how openHAB runs UI based scripts, `let`, `const` and `class` are not supported at top-level.
184-
Use `var` instead or wrap your script inside a self-invoking function:
185-
186-
```javascript
187-
// Wrap script inside a self-invoking function:
188-
(function (data) {
189-
const C = 'Hello world';
190-
console.log(C);
191-
})(this.event);
192-
193-
// Defining a class using var:
194-
var Tree = class {
195-
constructor (height) {
196-
this.height = height;
197-
}
198-
}
199-
```
200-
201181
### `require`
202182

203183
Scripts may include standard NPM based libraries by using CommonJS `require`.
@@ -1587,6 +1567,9 @@ Follow these steps to create your own library (it's called a CommonJS module):
15871567
1. Tar it up by running `npm pack` from your library's folder.
15881568
1. Install it by running `npm install <path-to-library-folder>/<name>-<version>.tgz` from the `automation/js` folder.
15891569
1. After you've installed it with `npm`, you can continue development of the library inside `node_modules`.
1570+
1. As you might have already noticed, the JavaScript Scripting add-on is reloading a script as soon as one of its dependencies changes.
1571+
When developing a library inside `node_modules`, this can cause regular reloads.
1572+
To avoid this situation, you can disable dependency tracking in the JavaScript Scripting add-on settings (you need to tick "show advanced" for the setting to come up).
15901573
15911574
It is also possible to upload your library to [npm](https://npmjs.com) to share it with other users.
15921575

0 commit comments

Comments
 (0)