Skip to content

Instantly share code, notes, and snippets.

@shubie

shubie/wecode.ex Secret

Created November 5, 2022 17:10
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 shubie/8fedbf4ec478e8bdfe6ccad9e160e6fb to your computer and use it in GitHub Desktop.
Save shubie/8fedbf4ec478e8bdfe6ccad9e160e6fb to your computer and use it in GitHub Desktop.
wecode.ex
defmodule WecodeWeb.FirstLive do
use WecodeWeb, :live_view
def mount(_params, _session, socket) do
{:ok, socket |> assign(:name, "Shuaib")}
end
def render(assigns) do
~H"""
<h1> <%= @name %> </h1>
<button phx-click="click" phx-value-sex="female"> Click me </button>
"""
end
@impl true
def handle_event("click", %{"sex" => sex}, socket) do
IO.inspect(sex, label: "sex")
send(self(),"msg")
{:noreply, socket |> assign(:name, "Hakeem")}
end
@impl true
def handle_info("msg", socket) do
IO.inspect("I GOT A MESSAGE")
{:noreply, socket}
end
def terminate(reason, socket) do
IO.inspect(reason, label: "reason")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment