Is there any technical reason not to do this, specifically around change tracking in live views?
def my_component(assigns) do
value = assigns.something <> assigns.something_else
# never calling assigns = assign(assigns, :value, value)
~H"""
<div><%= value %></div> <!-- not using @value -->
"""
end
My specific usecase is
def my_component(assigns) do
~H"""
<div>
<%= if assigns[:label] %> <!-- accessing `assigns` -->
<%= render_slot @label %>
<% else %>
<%= humanize(@field) %>
<% end %>
</div>
"""
end
vs
def my_component(assigns) do
# always go through an @var
assigns = assign_new(assigns, :label, fn -> false end)
~H"""
<div>
<%= if @label %>
<%= render_slot @label %>
<% else %>
<%= humanize(@field) %>
<% end %>
</div>
"""
end
I would generally preference using assign() explicitly, but I am wondering if I am adding verbosity when there is no point.
Is assigns[:label] as good as @label (or even label if in scope), in terms of change tracking and live view “health”?