Events and Lifecycle
lifecycle
In Briz, Lifecycle happens automatically within Briz. It automatically initializes data-nav and data-ajax, thus preventing memory leaks. And if you combine it with Leaf, Leaf will automatically initialize when data-scope appears and remove when data-scope disappears from the DOM. This is why we recommend using Briz with Leaf. You can also combine Leaf with HTMX or Briz with AlpineJs.
Events
There are several events in Briz, namely:
z:before-requestwill be executed before the request.z:request-successwill be executed after a successful request.z:request-errorwill be executed after a request-error.z:after-requestwill be executed after a request, regardless of whether it is an error or a success.z:before-swapwill be executed before the swap process.z:after-swapwill be executed after the swap process.z:before-navigationwill be executed before navigation.z:after-navigationwill be executed after navigation.
Example
document.addEventListener("z:before-request", (event) => {
//it will run before request, example before submit something from <form> tag
console.log(event.detail)
//it will show you all the detail event.
})
The main function of all the events above is to run something like loading, or inject headers before the request.
Prev: Real-Time Features