Skip to content

Commit

Permalink
Handle page_bundle_path channel messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bartblast committed Oct 26, 2024
1 parent d76a0fd commit b8bc2d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/hologram/socket/channel.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions test/elixir/hologram/socket/channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit b8bc2d8

Please sign in to comment.