Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save collegeimprovements/b795cee4670a064e7a23033b9c8a2f1a to your computer and use it in GitHub Desktop.
Save collegeimprovements/b795cee4670a064e7a23033b9c8a2f1a to your computer and use it in GitHub Desktop.
AlpineJS 3 with Phoenix Live
import "../css/app.scss"
import "phoenix_html"
import {Socket} from "phoenix"
import topbar from "topbar"
import {LiveSocket} from "phoenix_live_view"
import Alpine from 'alpinejs'
window.Alpine = Alpine
Alpine.start()
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {
dom: {
onBeforeElUpdated(from, to) {
if (from._x_dataStack) { window.Alpine.clone(from, to) }
}
},
params: {_csrf_token: csrfToken}
})
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
window.addEventListener("phx:page-loading-start", info => topbar.show())
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
liveSocket.connect()
window.liveSocket = liveSocket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment