Skip to content

Commit

Permalink
Add Alpinejs (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambareesha7 committed Sep 6, 2021
1 parent 5d16680 commit 13afaaa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
23 changes: 18 additions & 5 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import LiveSocket from "phoenix_live_view"
import { html } from "diff2html"
import hljs from "highlight.js"

// add alpinejs
import Alpine from "alpinejs";
window.Alpine = Alpine;
Alpine.start();

let Hooks = {}

let scrollAt = () => {
Expand All @@ -27,7 +32,7 @@ Hooks.CodeViewer = {
hljs.highlightBlock(this.el);
},

updated(){
updated(){
hljs.highlightBlock(this.el);
}
}
Expand All @@ -41,7 +46,7 @@ Hooks.InfiniteScroll = {
this.pending = this.page() + 1
this.pushEvent("load-more", {})
}

})
},
reconnected(){ this.pending = this.page() },
Expand All @@ -68,7 +73,17 @@ Hooks.Logs = {
}

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}});
let liveSocket = new LiveSocket("/live", Socket, {
hooks: Hooks,
params: { _csrf_token: csrfToken },
dom: {
onBeforeElUpdated(from, to){
if(from._x_dataStack){
window.Alpine.clone(from, to);
}
}
},
});

// connect if there are any LiveViews on the page
liveSocket.connect()
Expand All @@ -79,5 +94,3 @@ liveSocket.connect()
window.liveSocket = liveSocket

window.diff2html = html


21 changes: 21 additions & 0 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"watch": "webpack --mode development --watch"
},
"dependencies": {
"alpinejs": "^3.3.1",
"chokidar": "^3.5.1",
"diff2html": "^3.1.11",
"highlight.js": "^10.4.1",
Expand Down

0 comments on commit 13afaaa

Please sign in to comment.