How to have smaller pubsub payloads?

So, AFAIK when using the built-in pubsub feature of Ash, the payload will always be the action returned data with some other stuff. That payload sometimes is very big, especially if it is a big resource and there is a bunch of processes subscribed to that event. This is OK if you need the full resource, but sometimes you don't need the whole thing. For example, let's say I have a front page that lists properties and I subscribe to an event that will notify me when a new property is added. In this scenario, I don't want to get the full property and just add to the list, what I want is just add a button to the page saying "there are new properties available, click here to update your list". In that case, I just need an event that will tell me that a new property was added, the property content itself is meaningless since the user needs to click on the button to refresh the page and get a new list with the new property meaning that my payload can be empty. Would be possible to set the payload of a pubsub event using Ash?
1 Reply
ZachDaniel
ZachDaniel3y ago
It definitely can be, but we don't currently have anything to let you do it. The option in the short term is to define your own notifier.
use Ash.Resource,
notifiers: [YourNotifier]


defmodule YourNotifier do
def notify(%{action: :your_action}) do
broadcast_to_pubsub("thing_created")
end

def notify(_), do: :ok
end
use Ash.Resource,
notifiers: [YourNotifier]


defmodule YourNotifier do
def notify(%{action: :your_action}) do
broadcast_to_pubsub("thing_created")
end

def notify(_), do: :ok
end
But we could add something like this at some point:
publish :create, ...., payload: fn notification ->
notification_payload(notification)
end

# or
publish, :create, ...., payload: CreatePayload
publish :create, ...., payload: fn notification ->
notification_payload(notification)
end

# or
publish, :create, ...., payload: CreatePayload

Did you find this page helpful?