I’m happy to announce a new project, Phoenix Playground, the easiest way to build single-file Phoenix apps.
Here is an example:
Mix.install([
{:phoenix_playground, "~> 0.1.0"}
])
defmodule DemoLive do
use Phoenix.LiveView
def mount(_params, _session, socket) do
{:ok, assign(socket, count: 0)}
end
def render(assigns) do
~H"""
<span><%= @count %></span>
<button phx-click="inc">+</button>
<button phx-click="dec">-</button>
<style type="text/css">
body { padding: 1em; }
</style>
"""
end
def handle_event("inc", _params, socket) do
{:noreply, assign(socket, count: socket.assigns.count + 1)}
end
def handle_event("dec", _params, socket) do
{:noreply, assign(socket, count: socket.assigns.count - 1)}
end
end
PhoenixPlayground.start(live: DemoLive)
See Announcing Phoenix Playground blog post for more information and check out the GitHub repo. I’m looking forward to hearing what you are building with this.
Happy hacking!