LiveDebugger.Structs.TreeNode (LiveDebugger v0.1.4)

View Source

This module provides functions to work with the tree of LiveView and LiveComponent nodes (TreeNodes).

Summary

Functions

Adds a child to the parent node.

Returns string representation of the node's ID, ready to be displayed in the UI.

Returns a child of the parent node by PID or CID.

Returns PID or CID of the node.

Parses ID from string to PID or CID.

Same as id_from_string/1, but raises an ArgumentError if the ID is invalid.

Parses channel_state state to LiveDebugger.Structs.TreeNode.LiveComponent of given CID. If the component is not found, returns nil.

Parses channel_state to a list of all LiveDebugger.Structs.TreeNode.LiveComponent nodes. It doesn't include children.

Parses channel_state to LiveDebugger.Structs.TreeNode.LiveView.

Gives type of the node. Types

Types

Functions

add_child(parent, child)

@spec add_child(parent :: t(), child :: t()) :: t()

Adds a child to the parent node.

display_id(arg1)

@spec display_id(node :: t()) :: String.t()

Returns string representation of the node's ID, ready to be displayed in the UI.

get_child(parent, child_id)

@spec get_child(parent :: t(), child_id :: id()) :: t() | nil

Returns a child of the parent node by PID or CID.

id(node)

@spec id(node :: t()) :: id()

Returns PID or CID of the node.

id_from_string(id)

@spec id_from_string(id :: String.t()) :: {:ok, id()} | :error

Parses ID from string to PID or CID.

id_from_string!(string)

@spec id_from_string!(id :: String.t()) :: id()

Same as id_from_string/1, but raises an ArgumentError if the ID is invalid.

live_component_node(channel_state, cid)

@spec live_component_node(
  channel_state :: LiveDebugger.CommonTypes.channel_state(),
  cid :: cid()
) ::
  {:ok, t() | nil} | {:error, term()}

Parses channel_state state to LiveDebugger.Structs.TreeNode.LiveComponent of given CID. If the component is not found, returns nil.

Examples

iex> {:ok, state} = LiveDebugger.Services.LiveViewDiscoveryService.channel_state_from_pid(pid)
iex> LiveDebugger.Structs.TreeNode.live_component_node(state, 2)
{:ok, %LiveDebugger.Structs.TreeNode.LiveComponent{cid: 2, ...}}

iex> {:ok, state} = LiveDebugger.Services.LiveViewDiscoveryService.channel_state_from_pid(pid)
iex> LiveDebugger.Structs.TreeNode.live_component_node(state, 999)
{:ok, nil}

live_component_nodes(channel_state)

@spec live_component_nodes(channel_state :: LiveDebugger.CommonTypes.channel_state()) ::
  {:ok, [t()]} | {:error, term()}

Parses channel_state to a list of all LiveDebugger.Structs.TreeNode.LiveComponent nodes. It doesn't include children.

Examples

iex> {:ok, state} = LiveDebugger.Services.get_channel_state(pid)
iex> LiveDebugger.Structs.TreeNode.live_component_nodes(state)
{:ok, [%LiveDebugger.Structs.TreeNode.LiveComponent{...}, ...]}

live_view_node(channel_state)

@spec live_view_node(channel_state :: LiveDebugger.CommonTypes.channel_state()) ::
  {:ok, t()} | {:error, term()}

Parses channel_state to LiveDebugger.Structs.TreeNode.LiveView.

Examples

iex> {:ok, state} = LiveDebugger.Services.LiveViewDiscoveryService.channel_state_from_pid(pid)
iex> LiveDebugger.Structs.TreeNode.live_view_node(state)
{:ok, %LiveDebugger.Structs.TreeNode.LiveView{...}}

type(arg1)

@spec type(node :: t()) :: atom()

Gives type of the node. Types:

  • :live_view
  • :live_component