
See our bindings page for a complete list of all LiveViewīindings as well as our JavaScript interoperability guide.Ĭompartmentalize-state-markup-and-events-in-liveviewĬompartmentalize state, markup, and events in LiveView
#PLUGINS LIVEVIEW UPDATE#
To update UI state, for example, to open and close dropdowns, switch tabs,Įtc, LiveView also supports JS commands ( ), whichĮxecute directly on the client without reaching the server. In the installation guide before continuing.Ī LiveView is a simple module that requires two callbacks: mount/3Īnd render/1: defmodule MyAppWeb.ThermostatLive do # In Phoenix v1.6+ apps, the line below should be: use MyAppWeb, :live_view use Phoenix.LiveView def render ( assigns ) do ~H""" The phx.newĬommand with the -live flag will create a new project with

If you are just getting started, this canīe easily done by running mix phx.new my_app -live. LiveView also allows attaching hooks to specific life-cycle stages withīefore writing your first example, make sure that Phoenix LiveView Reconnects to the server, calling mount/3 and handle_params/3 again. Is encountered, or the client connection drops, the client gracefully If at any point during the stateful life-cycle a crash The result of render/1 to the client and continues on for the duration Is spawned on the server, runs handle_params/3 again and then pushes

The first rendering, mount/3, is invoked with params, session,Īnd socket state, However in the connected client case, a LiveView process To the browser, and receive client events via phx- bindings. To the server where stateful views are spawned to push rendered updates Is invoked and the HTML is sent as a regular HTML response to theĪfter rendering the static page, LiveView connects from the client Is invoked so uri and query params are handled. The mount/3 callback wires up socketĪssigns necessary for rendering the view. The session always contains private data setīy the application itself. With the current params, the current session and the LiveView socket.Īs in a regular request, params contains public data that can be When LiveView is first rendered, the mount/3 callback is invoked You begin by rendering a LiveView typically from your router. Guaranteeing a regular HTML page even if JavaScript is disabled.Īny time a stateful view changes or updates its socket assigns, it isĪutomatically re-rendered and the updates are pushed to the client. Uses more memory on the server compared to stateless requests.Ī LiveView begins as a regular HTTP request and HTML response,Īnd then upgrades to a stateful view on client connect, This allows LiveView applications to react faster to userĮvents as there is less work to be done and less data to be sentĬompared to stateless requests that have to authenticate, decode, load,Īnd encode data on every request. Then a persistent connection is established between client and Paint", in addition to helping search and indexing engines. HTTP requests, which provides quick times for "First Meaningful LiveView is first rendered statically as part of regular Internal application messages (usually emitted by Phoenix.PubSub) The state itself is nothing more than functionalĪnd immutable Elixir data structures. Process that receives events as messages and updates its Work of tracking changes and sending the relevant diffs toĪt the end of the day, a LiveView is nothing more than a This means developers write LiveView templates asĪny other server-rendered HTML and LiveView does the hard

To the browser, which updates itself in the most efficient Re-render the relevant parts of its HTML template and push it

Saying "once event X happens, change Y on the page",Įvents in LiveView are regular messages which may causeĬhanges to its state. The LiveView programming model is declarative: instead of LiveView provides rich, real-time user experiences with Settings View Source Phoenix.LiveView behaviour (Phoenix LiveView v0.17.10)
