Skip to content

Commit 779eb20

Browse files
committed
accepts multiple topics-patterns
1 parent 207cc31 commit 779eb20

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/phoenix_live_reload/channel.ex

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ defmodule Phoenix.LiveReloader.Channel do
1111
if Process.whereis(:phoenix_live_reload_file_monitor) do
1212
FileSystem.subscribe(:phoenix_live_reload_file_monitor)
1313
config = socket.endpoint.config(:live_reload)
14-
live_reload_config = socket.endpoint.config(:live_view)
1514

1615
socket =
1716
socket
1817
|> assign(:patterns, config[:patterns] || [])
1918
|> assign(:debounce, config[:debounce] || 0)
2019
|> assign(:notify_patterns, config[:notify] || [])
21-
|> assign(:live_reload_topic, live_reload_config[:live_reload_topic] || nil)
2220

2321
{:ok, socket}
2422
else
@@ -31,7 +29,6 @@ defmodule Phoenix.LiveReloader.Channel do
3129
patterns: patterns,
3230
debounce: debounce,
3331
notify_patterns: notify_patterns,
34-
live_reload_topic: live_reload_topic
3532
} = socket.assigns
3633

3734
if matches_any_pattern?(path, patterns) do
@@ -44,12 +41,14 @@ defmodule Phoenix.LiveReloader.Channel do
4441
end
4542
end
4643

47-
if matches_any_pattern?(path, notify_patterns) do
48-
Phoenix.PubSub.broadcast(
49-
socket.pubsub_server,
50-
live_reload_topic,
51-
{:phoenix_live_reload, live_reload_topic, path}
52-
)
44+
for {topic, patterns} <- notify_patterns do
45+
if matches_any_pattern?(path, patterns) do
46+
Phoenix.PubSub.broadcast(
47+
socket.pubsub_server,
48+
to_string(topic),
49+
{:phoenix_live_reload, topic, path}
50+
)
51+
end
5352
end
5453

5554
{:noreply, socket}

0 commit comments

Comments
 (0)