Or, put it other way, what is the memory cost of having 1.000 temporary_assign
values set to []
or nil
?
I was refactoring my project into LiveView components and I got this question: “What if I changed all my static assigns from old Phoenix templates to dynamic LiveView assigns for all my styling?”
Imagine I would have something like this inside a LiveView:
def mount(socket) do
socket = assign(socket, styleOne: "width: 100%; margin: 1.5rem;",
styleTwo: "width: 100%; padding: 0.25rem; background-color: White",
styleThree: "width: 100%")
{:ok, socket, temporary_assigns: [styleOne: nil, styleTwo: nil, styleThree: nil]}
end
def render(assigns) do
~L"""
<div style="<%=@styleOne%>">
<div style="<%=@styleTwo%>">Text</div>
<div style="<%=@styleThree%>">...</div>
</div>
"""
end
There are several WHY reasons for that, one of them would be to easily allow users to customise some styling on some elements if needed.
But this is also a more architectural theoretical question