I tried to unsubscribe old channel and to subscribe new channel in LiveComponent.
I expected that old channel is in the assigns of socket in update/2
callback of LiveComponent, but it isn’t.
All assigns of socket don’t exist.
@impl true
def update(assigns, socket) do
old_channel_name = socket.assigns[:channel_name]
new_channel_name = assigns.channel_name
IO.inspect(socket.assigns, label: "socket.assigns")
IO.inspect({old_channel_name, new_channel_name}, label: "assigns")
if connected?(socket) do
if old_channel_name do
:ok = Chat.unsubscribe_channel(old_channel_name)
end
:ok = Chat.subscribe_channel(new_channel_name)
end
socket =
socket
|> assign(assigns)
|> assign_messages(new_channel_name)
{:ok, socket}
end
Can’t I get the old assigns in update/2
callback of LiveComponent?
page: Home · Json Media
code: json_corp/channel.ex at chat · nallwhy/json_corp · GitHub