I need to render a LiveView stream while accumulating previous state. With a regular collection, I would use recursion:
def mount(_, _, socket) do
{:ok, assign(socket, list: [1, 2, 3])}
end
def render(assigns) do
~H"""
<.list list={@list} prev="first" />
"""
end
defp list(%{list: []} = assigns), do: ~H""
defp list(assigns) do
~H"""
<div>
<%= "cur: #{hd(@list)}, prev: #{@prev}" %>
<.list list={tl(@list)} prev={hd(@list)} />
</div>
"""
end
Can I do this if I replace list with a LiveView stream?