diff --git a/lib/hologram/socket/channel.ex b/lib/hologram/socket/channel.ex index c8d18b9af..78e81a9a7 100644 --- a/lib/hologram/socket/channel.ex +++ b/lib/hologram/socket/channel.ex @@ -1,8 +1,10 @@ defmodule Hologram.Socket.Channel do use Phoenix.Channel + alias Hologram.Assets.PageDigestRegistry alias Hologram.Compiler.Encoder alias Hologram.Component.Action + alias Hologram.Router.Helpers, as: RouterHelpers alias Hologram.Server alias Hologram.Socket.Decoder alias Hologram.Template.Renderer @@ -49,4 +51,15 @@ defmodule Hologram.Socket.Channel do {:reply, {:ok, html}, socket} end + + @impl Phoenix.Channel + def handle_in("page_bundle_path", payload, socket) do + page_bundle_path = + payload + |> Decoder.decode() + |> PageDigestRegistry.lookup() + |> RouterHelpers.page_bundle_path() + + {:reply, {:ok, page_bundle_path}, socket} + end end diff --git a/test/elixir/hologram/socket/channel_test.exs b/test/elixir/hologram/socket/channel_test.exs index a79d730f6..eb01f90ed 100644 --- a/test/elixir/hologram/socket/channel_test.exs +++ b/test/elixir/hologram/socket/channel_test.exs @@ -184,6 +184,17 @@ defmodule Hologram.Socket.ChannelTest do end end + test "handle_in/3, page_bundle_path" do + stub_with(PageDigestRegistryMock, PageDigestRegistryStub) + setup_page_digest_registry(PageDigestRegistryStub) + ETS.put(PageDigestRegistryStub.ets_table_name(), Module2, "12345678901234567890123456789012") + + payload = [1, "__atom__:Elixir.Hologram.Test.Fixtures.Socket.Channel.Module2"] + + assert handle_in("page_bundle_path", payload, :dummy_socket) == + {:reply, {:ok, "/hologram/page-12345678901234567890123456789012.js"}, :dummy_socket} + end + describe "join/3" do test "valid topic name" do assert join("hologram", :dummy_payload, :dummy_socket) == {:ok, :dummy_socket}