excid3 / tailwindcss-stimulus-components

A set of StimulusJS components for TailwindCSS apps similar to Bootstrap JS components.

Home Page:https://excid3.github.io/tailwindcss-stimulus-components/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to utlize `cb`?

bilogic opened this issue · comments

_hide(cb) {
setTimeout(
(() => {
if (this.hasButtonTarget) {
this.buttonTarget.setAttribute("aria-expanded", "false")
}
this._invisibleClassList[0].forEach(klass => this.menuTarget.classList.add(klass))
this._visibleClassList[0].forEach(klass => this.menuTarget.classList.remove(klass))
this._activeClassList[0].forEach(klass => this.activeTarget.classList.remove(klass))
this._leavingClassList[0].forEach(klass => this.menuTarget.classList.add(klass))
setTimeout(
(() => {
this._leavingClassList[0].forEach(klass => this.menuTarget.classList.remove(klass))
if (typeof cb == 'function') cb()

I noticed this cb in the controllers, does it mean there is a way to pass a callback into the controllers?
My use case is, I would like to have a toggle switch to change some setting on the server, but I don't want to be hardcoding the XHR/AJAX inside the controller itself.

Any examples of how I can do this callback from controller back to the HTML side?

Thank you.

UPDATE: ok, I misunderstood the code