Phoenix LiveView - Making modern web apps witho...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Phoenix LiveView - Making modern web apps without JavaScript

Miloš Mošić

May 30, 2019

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

27 slides
  1. Who am I? Senior Software Engineer at Mainframe Worked with

    Elixir & Phoenix since 2014 Helped spread Elixir by introducing it into Evercam 5 / 27
  2. Who am I? Senior Software Engineer at Mainframe Worked with

    Elixir & Phoenix since 2014 Helped spread Elixir by introducing it into Evercam Gave a talk at the first Elixir Conf EU 6 / 27
  3. What is Phoenix LiveView? A brand new library for Phoenix

    Made by the Phoenix creator, Chris McCord 11 / 27
  4. What is Phoenix LiveView? A brand new library for Phoenix

    Made by the Phoenix creator, Chris McCord Not released yet 12 / 27
  5. defmodule DemoWeb.ImageView do use Phoenix.LiveView def render(assigns) do ~L""" <form

    phx-change="update"> <input type="range" min="10" max="630" name="width" value="<%= @width %>" /> <%= @width %>px <fieldset> White <%= radio_tag(name: :bg, value: "white", checked: @bg) %> Black <%= radio_tag(name: :bg, value: "black", checked: @bg) %> Blue <%= radio_tag(name: :bg, value: "blue", checked: @bg) %> </fieldset> </form> <br/> <img src="/images/phx.png" width="<%= @width %>" style="background: <%= @bg %>;" /> """ end def radio_tag(assigns) do ~L""" <input type="radio" name="<%= @name %>" value="<%= @value %>" <%= if @value == @checked, do: "checked" %> /> """ end def mount(_session, socket) do {:ok, assign(socket, width: 100, bg: "white")} end def handle_event("update", %{"width" => width, "bg" => bg}, socket) do {:noreply, assign(socket, width: String.to_integer(width), bg: bg)} end end 18 / 27
  6. def render(assigns) do ~L""" <form phx-change="update"> <input type="range" min="10" max="630"

    name="width" value="<%= @width %>" /> <%= @width %>px <fieldset> White <%= radio_tag(name: :bg, value: "white", checked: @bg) %> Black <%= radio_tag(name: :bg, value: "black", checked: @bg) %> Blue <%= radio_tag(name: :bg, value: "blue", checked: @bg) %> </fieldset> </form> <br/> <img src="/images/phx.png" width="<%= @width %>" style="background: <%= @bg %>;" /> """ end 21 / 27
  7. def radio_tag(assigns) do ~L""" <input type="radio" name="<%= @name %>" value="<%=

    @value %>" <%= if @value == @checked, do: "checked" %> /> """ end def mount(_session, socket) do {:ok, assign(socket, width: 100, bg: "white")} end def handle_event("update", %{"width" => width, "bg" => bg}, socket) do {:noreply, assign(socket, width: String.to_integer(width), bg: bg)} end 22 / 27

More Decks by Miloš Mošić

Other Decks in Programming