[jsscripting] Rename library injection parameter & Improve docs (#15547)

* [jsscripting] Rename parameter useIncludedLibrary to injectionCachingEnabled (#4)
* [jsscripting] Improve README for cached library injection
* Remove settings image

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze
2023-09-26 22:59:20 +02:00
committed by GitHub
parent afda8c5f47
commit 99f0512c73
6 changed files with 42 additions and 26 deletions

View File

@@ -39,13 +39,25 @@ to common openHAB functionality within rules including items, things, actions, l
## Configuration
This add-on includes by default the [openhab-js](https://github.com/openhab/openhab-js/) NPM library and exports its namespaces onto the global namespace.
This allows the use of `items`, `actions`, `cache` and other objects without the need to explicitly import them using `require()`.
This functionality can be disabled for users who prefer to manage their own imports via the add-on configuration options.
By default, the injection of the included [openhab-js](https://github.com/openhab/openhab-js/) NPM library is cached to improve performance and reduce memory usage.
If you want to use a different version of openhab-js (installed to the `node_modules` folder) than the included one, you need to disable the usage of the included library.
By default, the injection of the [openhab-js](https://github.com/openhab/openhab-js/) NPM library is cached (using a special mechanism instead of `require()`) to improve performance and reduce memory usage.
![openHAB Rule Configuration](doc/settings.png)
When configuring the add-on, you should ask yourself these questions:
1. Do I want to have the openhab-js namespaces automatically globally available (`injectionEnabled`)?
- Yes: "Use Built-In Variables" (default)
- No: "Do Not Use Built-In Variables", which will allow you to decide what to import and really speed up script loading, but you need to manually import the library, which actually will slow down script loading again.
2. Do I want to have a different version injected other than the included one (`injectionCachingEnabled`)?
- Yes: "Do Not Cache Library Injection" and install your version to the `$OPENHAB_CONF/automation/js/node_modules` folder, which will slow down script loading, because the injection is not cached.
- No: "Cache Library Injection" (default), which will speed up the initial loading of a script because the library's injection is cached.
Note that in case you disable caching or your code uses `require()` to import the library and there is no installation of the library found in the node_modules folder, the add-on will fallback to its included version.
In general, the first run of a script will take longer than the subsequent runs.
This is because on the first run both the globals (like `console`) and (if enabled) the library are injected into the script's context.
<!-- Paste the copied docs from openhab-js under this comment. Do NOT forget the table of contents. -->