Slide 1

Slide 1 text

Phoenix LiveView: Making modern web apps without JavaScript Miloš Mošić https://milosmosic.com 1 / 27

Slide 2

Slide 2 text

Who am I? 2 / 27

Slide 3

Slide 3 text

Who am I? Senior Software Engineer at Mainframe 3 / 27

Slide 4

Slide 4 text

Who am I? Senior Software Engineer at Mainframe Worked with Elixir & Phoenix since 2014 4 / 27

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

What is Elixir? 7 / 27

Slide 8

Slide 8 text

What is Phoenix? 8 / 27

Slide 9

Slide 9 text

What is Phoenix LiveView? 9 / 27

Slide 10

Slide 10 text

What is Phoenix LiveView? A brand new library for Phoenix 10 / 27

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

What is Phoenix LiveView? A brand new library for Phoenix Made by the Phoenix creator, Chris McCord Not released yet 12 / 27

Slide 13

Slide 13 text

What is Phoenix LiveView? 13 / 27

Slide 14

Slide 14 text

What would you use Phoenix LiveView for? 14 / 27

Slide 15

Slide 15 text

Killing JavaScript 15 / 27

Slide 16

Slide 16 text

How does it work? 16 / 27

Slide 17

Slide 17 text

Simple example 17 / 27

Slide 18

Slide 18 text

defmodule DemoWeb.ImageView do use Phoenix.LiveView def render(assigns) do ~L""" <%= @width %>px 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) %>
""" end def radio_tag(assigns) do ~L""" /> """ 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

Slide 19

Slide 19 text

def deps do [ {:phoenix_live_view, github: "phoenixframework/phoenix_live_view"} ] end https://github.com/phoenixframework/phoenix_live_view 19 / 27

Slide 20

Slide 20 text

defmodule DemoWeb.ImageView do use Phoenix.LiveView end 20 / 27

Slide 21

Slide 21 text

def render(assigns) do ~L""" <%= @width %>px 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) %>
""" end 21 / 27

Slide 22

Slide 22 text

def radio_tag(assigns) do ~L""" /> """ 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

Slide 23

Slide 23 text

Example one more time 23 / 27

Slide 24

Slide 24 text

How does it work? 24 / 27

Slide 25

Slide 25 text

Wait, holding an open websocket connection for every single page? 25 / 27

Slide 26

Slide 26 text

https://phoenixframework.org/blog/the-road-to-2-million-websocket-connections 26 / 27

Slide 27

Slide 27 text

Thank You! Questions? 27 / 27