Created
April 20, 2020 00:30
-
-
Save brianstorti/8dea2107d7bdff8d7ab93e61c3dff1c7 to your computer and use it in GitHub Desktop.
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
defmodule CounterWeb.Counter do | |
use Phoenix.LiveView | |
def render(assigns) do | |
~L""" | |
<div> | |
<h1>The count is: <%= @val %></h1> | |
<button phx-click="dec">-</button> | |
<button phx-click="inc">+</button> | |
</div> | |
""" | |
end | |
def mount(_params, _session, socket) do | |
{:ok, assign(socket, val: 0)} | |
end | |
def handle_event(action = "inc", _, socket) do | |
{:noreply, update(socket, :val, &(&1 + 1))} | |
end | |
def handle_event(action = "dec", _, socket) do | |
{:noreply, update(socket, :val, &(&1 - 1))} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment