ndrean
Very first Phoenix Liveview project. Probably my understanding of the life cycle is “weak” at this stage so I hope theses questions make sense.
All my pages are liveviews. The only time is need to declare a mount function is for a live module when I need some internal state, with handlers.
I can put a nav link inside “templates/layout/root.html.heex”, and use @conn in the links:
<li><%= live_redirect "demo", to: Routes.live_path(@conn, DemoWeb.HomeLive) %></li>.
I can also put a nav link in the “templates/layout/live.html.heex” but have to use @socket in the links.
<li><%= live_redirect "home", to: Routes.live_path(@socket, DemoWeb.HomeLive) %></li>
Where does @conn come from for the “layout/root” case? And where does the @socket comes from as well for the “layout/live” case?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ndrean
Answering to myself if any interest:
An HTTP request is processed with Plug that creates a
Plug.Connaliasconnstruct. Thus you have theconnstruct when navigating in a non-liveview page.With liveviews, it is a websocket and you get a
socketstruct.Samuei2000
Can you explain what is the difference between
socketandconn?codeanpeace
socket=> websockets (stateful and ongoing two-way connections)conn=> HTTP request/response (stateless and one-off one-way connections)Samuei2000
Plug.Conn represents an ordinary HTTP request. But this request can start a Liveview. And inside a live view, there is Phoenix.LiveView.Socket which represents a websocket
codeanpeace
Yup, websocket connection are just upgraded HTTP connections!
source: Protocol upgrade mechanism - HTTP | MDN
And with LiveView, the handoff between the two is configured and can be customized as described here.