Suppose I create a map inside mount/3 containing data from various sources:
- session
- get_connect_params(socket)
- database
This map does not change during the LiveView session.
The map needs to be available to all of my LiveComponents.
When I assign the map to the LiveComponent sockets, I get a lot of copies (one for each LiveComponent), each of them change tracked, costing both memory and additional latency.
I am thinking about doing the following inside mount/3:
my_map = %{
# fields
}
{:ok, assign(socket, get_my_map: fn -> my_map end)}
Does this solve my problem without creating other problems?