Skip to content

Commit 752c460

Browse files
committed
add flag for dead view mode
1 parent 2f1ccbf commit 752c460

6 files changed

Lines changed: 38 additions & 4 deletions

File tree

config/config.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ if config_env() == :dev do
4040
]
4141

4242
config :live_debugger,
43+
dead_view_mode?: true,
4344
live_reload: [
4445
patterns: [
4546
~r"priv/static/.*(js|css|svg)$",

lib/live_debugger/env.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ defmodule LiveDebugger.Env do
1919
Application.get_env(:live_debugger, :test_mode?, false) and
2020
not Application.get_env(:live_debugger, :e2e?, false)
2121
end
22+
23+
def dead_view_mode?() do
24+
Application.get_env(:live_debugger, :dead_view_mode?, false)
25+
end
2226
end

lib/live_debugger/gen_servers/ets_table_server.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ defmodule LiveDebugger.GenServers.EtsTableServer do
6565
|> Map.update!(closed_pid, fn table_info -> %{table_info | alive?: false} end)
6666
|> maybe_delete_ets_table(closed_pid)
6767

68-
PubSubUtils.process_status_topic()
69-
|> PubSubUtils.broadcast({:process_status, {:died, closed_pid}})
68+
if LiveDebugger.Env.dead_view_mode?() do
69+
PubSubUtils.process_status_topic()
70+
|> PubSubUtils.broadcast({:process_status, {:died, closed_pid}})
71+
end
7072

7173
{:noreply, state}
7274
end

lib/live_debugger_web/components/navbar.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ defmodule LiveDebuggerWeb.Components.Navbar do
107107

108108
@doc """
109109
Component for displaying the connection status of a LiveView.
110+
When button is clicked, it will trigger a `find-successor` event with the PID of the LiveView.
110111
"""
111112
attr(:connected?, :boolean, required: true, doc: "Whether LiveView is connected.")
112113
attr(:pid, :string, required: true, doc: "The PID of the LiveView.")
@@ -121,6 +122,7 @@ defmodule LiveDebuggerWeb.Components.Navbar do
121122
<%= @pid %>
122123
<% else %>
123124
<span class="font-medium">Disconnected</span>
125+
<.button phx-click="find-successor" variant="secondary" size="sm">Continue</.button>
124126
<% end %>
125127
</div>
126128
"""

lib/live_debugger_web/hooks/linked_view.ex

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ defmodule LiveDebuggerWeb.Hooks.LinkedView do
6363
PubSubUtils.process_status_topic()
6464
|> PubSubUtils.subscribe!()
6565

66-
LiveDebugger.GenServers.EtsTableServer.watch(fetched_lv_process.pid)
66+
if LiveDebugger.Env.dead_view_mode?() do
67+
LiveDebugger.GenServers.EtsTableServer.watch(fetched_lv_process.pid)
68+
end
6769

6870
socket
6971
|> assign(:lv_process, AsyncResult.ok(fetched_lv_process))
@@ -83,6 +85,12 @@ defmodule LiveDebuggerWeb.Hooks.LinkedView do
8385

8486
def handle_async(_, _, socket), do: {:cont, socket}
8587

88+
def handle_info(:find_successor, socket) do
89+
socket
90+
|> find_successor_lv_process()
91+
|> halt()
92+
end
93+
8694
def handle_info(
8795
{:process_status, {:died, pid}},
8896
%{assigns: %{lv_process: %{result: %LvProcess{pid: pid}}}} = socket
@@ -93,7 +101,17 @@ defmodule LiveDebuggerWeb.Hooks.LinkedView do
93101
|> halt()
94102
end
95103

96-
def handle_info({:process_status, _}, socket), do: halt(socket)
104+
def handle_info(
105+
{:process_status, {:dead, pid}},
106+
%{assigns: %{lv_process: %{result: %LvProcess{pid: pid}}}} = socket
107+
) do
108+
if LiveDebugger.Env.dead_view_mode?() do
109+
socket
110+
else
111+
find_successor_lv_process(socket)
112+
end
113+
|> halt()
114+
end
97115

98116
def handle_info(_, socket), do: {:cont, socket}
99117

lib/live_debugger_web/live/channel_dashboard_live.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ defmodule LiveDebuggerWeb.ChannelDashboardLive do
8686
"""
8787
end
8888

89+
@impl true
90+
def handle_event("find-successor", _, socket) do
91+
send(self(), :find_successor)
92+
93+
{:noreply, socket}
94+
end
95+
8996
defp assign_node_id(socket, %{"node_id" => node_id}) do
9097
case TreeNode.id_from_string(node_id) do
9198
{:ok, id} ->

0 commit comments

Comments
 (0)