fix: don't fail to build Phoenix.Socket.Broadcast

This commit is contained in:
Zach Daniel 2022-08-29 08:05:12 -06:00
parent d0c28ec215
commit 7930e3efa1
4 changed files with 20 additions and 40 deletions

View file

@ -21,7 +21,7 @@ The available aggregate types are:
- `sum` - sums the related items meeting the criteria. Must specify the `field` to sum.
- `list` - lists the related values. Must specify the `field` to list.
See the docs on {{link:ash:dsl:aggregates/aggregate}} for more information.
See the docs on {{link:ash:dsl:resource/aggregates}} for more information.
The aggregates declared on a resource allow for declaring a set of named aggregates that can be used by extensions.

View file

@ -202,46 +202,26 @@ defmodule Ash.Notifier.PubSub do
end)
end
case Code.ensure_compiled(Phoenix.Socket.Broadcast) do
{:module, _} ->
def to_payload(topic, event, notification) do
case Ash.Notifier.PubSub.Info.broadcast_type(notification.resource) do
:phoenix_broadcast ->
%Phoenix.Socket.Broadcast{
topic: topic,
event: event,
payload: notification
}
def to_payload(topic, event, notification) do
case Ash.Notifier.PubSub.Info.broadcast_type(notification.resource) do
:phoenix_broadcast ->
%{
__struct__: Phoenix.Socket.Broadcast,
topic: topic,
event: event,
payload: notification
}
:broadcast ->
%{
topic: topic,
event: event,
payload: notification
}
:broadcast ->
%{
topic: topic,
event: event,
payload: notification
}
:notification ->
notification
end
end
_ ->
def to_payload(topic, event, notification) do
case Ash.Notifier.PubSub.Info.broadcast_type(notification.resource) do
:phoenix_broadcast ->
raise "A resource was configured with `broadcast_type :phoenix_broadcast` but `Phoenix.Socket.Broadcast` was not compiled."
:broadcast ->
%{
topic: topic,
event: event,
payload: notification
}
:notification ->
notification
end
end
:notification ->
notification
end
end
defp fill_template(topic, _) when is_binary(topic), do: [topic]

View file

@ -51,7 +51,7 @@ defmodule Ash.Registry.Dsl do
@moduledoc """
A small DSL for declaring an `Ash.Registry`.
`Ash.Registry` can be used generically, but the main way it is used in Ash is to provide a compile-time registry for {{link:ash:guide:Apis}}.
`Ash.Registry` can be used generically, but the main way it is used in Ash is to provide a compile-time registry for an Ash Api.
<!--- ash-hq-hide-start--> <!--- -->