-
-
Save collegeimprovements/b795cee4670a064e7a23033b9c8a2f1a to your computer and use it in GitHub Desktop.
AlpineJS 3 with Phoenix Live
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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