How can I recursively render a LiveView stream?

18 Views Asked by At

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?

0

There are 0 best solutions below