Skip to content

Commit 41d5ab8

Browse files
Sleepfulchrismccord
authored andcommitted
Docs: Explain sockets as a server-only data struct
1 parent 0adb911 commit 41d5ab8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

guides/server/assigns-eex.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Assigns and HEEx templates
22

33
All of the data in a LiveView is stored in the socket as assigns.
4+
The socket state is a server side struct in `Phoenix.LiveView.Socket`
5+
and `Phoenix.Socket` which maintains state through a GenServer,
6+
there is one process per socket connection, the socket is never
7+
shared with the client.
8+
49
The `Phoenix.Component.assign/2` and `Phoenix.Component.assign/3`
510
functions help store those values. Those values can be accessed
611
in the LiveView as `socket.assigns.name` but they are accessed

lib/phoenix_live_view.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ defmodule Phoenix.LiveView do
3737
Any time a stateful view changes or updates its socket assigns, it is
3838
automatically re-rendered and the updates are pushed to the client.
3939
40+
Socket assigns are values kept on the server side by
41+
`Phoenix.Socket`, this is different from the common pattern of sending
42+
the connection state to the client in the form of a token or cookie,
43+
typically used in HTTP requests. Under the hood there is a GenServer that
44+
creates a process for each socket connection through `Phoenix.LiveView.Socket`.
45+
4046
You begin by rendering a LiveView typically from your router.
4147
When LiveView is first rendered, the `c:mount/3` callback is invoked
4248
with the current params, the current session and the LiveView socket.

0 commit comments

Comments
 (0)