JavaScript API
Datastar is intentional about not (indecently) exposing itself in the global scope – you should be able to do everything you need via Datastar expressions in attribute plugins and datastar-execute-script
SSE events.
When troubleshooting an issue, it may be useful to see the current state of the signals. The easiest way to do this is by outputting them in JSON format using data-text
.
<pre data-text="ctx.signals.JSON()"></pre>
Importing Datastar#
While it is generally recommended against, you can manually import the Datastar object and access its public methods and properties.
<script type="module">
import { Datastar } from '/path/to/datastar.js'
console.log(Datastar.signals.values())
</script>
Public Methods#
The Datastar object exposes the following methods.
load()
#
Loads all plugins and applies them to the DOM.
Datastar.load()
Public Properties#
The Datastar object exposes the following properties.
signals
#
The signal root, on which you can access signal methods. Beware that you should avoid using this for anything other than troubleshooting.
Datastar.signals.values()