I have a helper function in my livecomponent that relies on socket state. What’s the best way to load the socket from the template and pass it into the helper function? When I use @socket, it doesn’t have the assigns just the Phoenix.LiveView.Socket.AssignsNotInSocket.
Generally speaking, avoid accessing variables inside LiveViews, as code that access variables is always executed on every render. This also applies to the assigns variable
You mention it’s not good to access variables inside of the liveview, yet you call container_id(@base_id). Is this call represented differently somehow?
The difference is related to change tracking, when you have the code below and pattern match on the base_id within the container_id function, it will be re-evaluated everytime the assigns changes.
Mmh.
It hadn’t occurred to me that it was a bad suggestion indeed, thanks for correcting it
I might have done such things in the past, in a vein attempt to “encapsulate”/abstract from the name of the variable I was using to compute such an id… And that always turned out to be quite pointless.
Another solution may also be to simply have container_id be an assign of the socket, after all.