![]() Render/1: defmodule MyAppWeb.ThermostatLive do # In Phoenix v1.6+ apps, the line is typically: use MyAppWeb, :live_view use Phoenix.LiveView def render ( assigns ) do ~H""" LiveView also allows attaching hooks to specific life-cycle stages withĪ LiveView is a module that requires two callbacks: mount/3 and 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 However in the connected client case, a LiveView process The first rendering, mount/3, is invoked with params, session,Īnd socket state. 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. Of a token or cookie and rebuilding the state on the server to service HTTP pattern of sending the connection state to the client in the form This is different from the common stateless Socket assigns are stateful values kept on the server side in 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. 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,Ī LiveView begins as a regular HTTP request and HTML response,Īnd then upgrades to a stateful view on client connect, 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 (usually emitted by Phoenix.PubSub) or sent by the client/browser. The events are either internal application messages LiveView state is nothing more than functional and immutableĮlixir data structures. Work of tracking changes and sending the relevant diffs to 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 Its state, and render updates to a page as diffs. Settings View Source Phoenix.LiveView behaviour (Phoenix LiveView v0.19.0)Ī LiveView is a process that receives events, updates
0 Comments
Leave a Reply. |