That is a great point. @perceval62 you really should do this in your mount/3
def mount(_params, _, socket) do
if connected?(socket) do
topic = "global:test"
MyApp.Endpoint.subscribe(topic)
IO.puts("I am now subscribed to " <> topic)
end
param = "This is a test,"
{:ok, assign(socket, :param, param)}
end
When you first connect to a liveview app you get two calls to mount
, one for the static render and one for the live render. I was actually just talking about this in another thread: More convenience functions to deal with assigns inside LiveView - #15 by benwilson512