JavaScript
Call Actions, emit and listen for Events, and more - all from Vanilla JavaScript.
Last updated
Call Actions, emit and listen for Events, and more - all from Vanilla JavaScript.
Last updated
CBWIRE provides a handful of JavaScript hooks and functionality you can use as needed.
We recommend you use AlpineJS for most of your JavaScript needs, but you can use <script> tags directly inside your components.
Your scripts will be run only once upon the first render of the component. If you need to run a JavaScript function later, you can emit the Event from the component and listen to it in JavaScript.
CBWIRE allows you to execute JavaScript during various events.
Hook | Description |
---|---|
You can interact with your component's actions, set data properties, and more, using cbwire.find. Once you have a reference to the component, you can use the methods below.
component.initialized
Called when a component has been initialized on the page by CBWIRE
element.initialized
Called when CBWIRE initializes an individual element
element.updating
Called before CBWIRE updates an element during its DOM-diffing cycle after a network roundtrip
element.updated
Called after CBWIRE updates an element during its DOM-diffing cycle after a network roundtrip
element.removed
Called after CBWIRE removes an element during its DOM-diffing cycle
message.sent
Called when a CBWIRE update triggers a message sent to the server via AJAX
message.failed
Called if the message send fails for some reason
message.received
Called when a message has finished its roundtrip, but before CBWIRE updates the DOM
message.processed
Called after CBWIRE processes all side effects (including DOM-diffing) from a message