Skip to content

Commit 50d590b

Browse files
committed
Add examples/demo_live.livemd
1 parent 929c8f3 commit 50d590b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/demo_live.livemd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Demo
2+
3+
```elixir
4+
Mix.install([
5+
{:phoenix_playground, "~> 0.1.0"}
6+
])
7+
```
8+
9+
## Section
10+
11+
```elixir
12+
defmodule DemoLive do
13+
use Phoenix.LiveView
14+
15+
def mount(_params, _session, socket) do
16+
{:ok, assign(socket, count: 0)}
17+
end
18+
19+
def render(assigns) do
20+
~H"""
21+
<span><%= @count %></span>
22+
<button phx-click="inc">+</button>
23+
<button phx-click="dec">-</button>
24+
25+
<style type="text/css">
26+
body { padding: 1em; }
27+
span { font-family: monospace; }
28+
</style>
29+
"""
30+
end
31+
32+
def handle_event("inc", _params, socket) do
33+
{:noreply, assign(socket, count: socket.assigns.count + 1)}
34+
end
35+
36+
def handle_event("dec", _params, socket) do
37+
{:noreply, assign(socket, count: socket.assigns.count - 1)}
38+
end
39+
end
40+
41+
PhoenixPlayground.start(live: DemoLive)
42+
```

0 commit comments

Comments
 (0)