defmodule LiveDebuggerWeb.Live.Traces.Components.Stream do @moduledoc """ This component is used to display the traces stream. It allows to compose style for the trace using `LiveDebuggerWeb.Live.Traces.Components.Trace` components. """ use LiveDebuggerWeb, :hook_component @required_assigns [:id, :existing_traces_status] @doc """ Initializes the component by attaching the hook to the socket. """ @spec init(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t() def init(socket) do socket |> check_assigns!(@required_assigns) |> check_stream!(:existing_traces) |> register_hook(:traces_stream) end @doc """ Renders the traces stream. It is used to display the traces stream. """ attr(:id, :string, required: true) attr(:existing_traces_status, :atom, required: true) attr(:existing_traces, :any, required: true) slot(:trace, required: true, doc: "Used for styling trace element. Remember to add `id`") def traces_stream(assigns) do ~H"""
<%= for {dom_id, wrapped_trace} <- @existing_traces do %> <%= if wrapped_trace.id == "separator" do %> <.separator id={dom_id} /> <% else %> <%= render_slot(@trace, {dom_id, wrapped_trace}) %> <% end %> <% end %>
""" end attr(:id, :string, required: true) defp separator(assigns) do ~H"""
Past Traces
""" end end