Skip to content

Instantly share code, notes, and snippets.

@ftes
Created October 1, 2021 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftes/4cf79658e7394821eca7aeb24297d5a1 to your computer and use it in GitHub Desktop.
Save ftes/4cf79658e7394821eca7aeb24297d5a1 to your computer and use it in GitHub Desktop.
alpine.js + liveview
defmodule PetalsDragNDropWeb.PageLive do
use PetalsDragNDropWeb, :live_view
data world, :string, default: "world!"
@impl true
def render(assigns) do
~F"""
<div
id="page"
:hook="Page"
x-data
x-init="setTimeout(() => { pageHook.pushEvent('set_world', 'WORLD!') }, 1000)"
class="h-screen flex justify-center items-center font-bold text-3xl"
>
Hello {@world}
</div>
"""
end
@impl true
def handle_event("set_world", value, socket) do
{:noreply, assign(socket, world: value)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment