defmodule LivebookWeb.Output.TabsComponent do use LivebookWeb, :live_component @impl true def mount(socket) do {:ok, stream(socket, :outputs, [])} end @impl true def update(assigns, socket) do {labels, assigns} = Map.pop!(assigns, :labels) {outputs, assigns} = Map.pop!(assigns, :outputs) # We compute these only on initial render, when we have all outputs socket = socket |> assign_new(:labels, fn -> Enum.zip_with(labels, outputs, fn label, {output_idx, _} -> {output_idx, label} end) end) |> assign_new(:active_idx, fn -> get_in(outputs, [Access.at(0), Access.elem(0)]) end) socket = assign(socket, assigns) stream_items = for {idx, output} <- outputs do id = "#{idx}-tabs-item" %{id: id, idx: idx, output: output} end socket = stream(socket, :outputs, stream_items) {:ok, socket} end @impl true def render(assigns) do ~H"""
""" end end