-
Hi, I'm new to elixir, but as far as I understand one should be able to use PubSub to send messages to live components, right? Say I have an API and I create a new user, how can I broadcast the creation event so the live component of the live resource refreshes?
I was hoping something like this might work:
But the function seems to accept more arguments. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @asok You must broadcast the event using the same PubSub configuration as in your LiveResource. Suppose your LiveResource configuration looks like this defmodule MyAppWeb.UserLive do
use Backpex.LiveResource,
# other configuration ...
pubsub: MyApp.PubSub,
topic: "users",
event_prefix: "user_"
end Your API can broadcast the creation of a user like this Phoenix.PubSub.broadcast(MyApp.PubSub, "users", {"backpex:user_created", item}) Backpex should now handle the event and update the UI accordingly. |
Beta Was this translation helpful? Give feedback.
Hey @asok
You must broadcast the event using the same PubSub configuration as in your LiveResource.
Suppose your LiveResource configuration looks like this
Your API can broadcast the creation of a user like this
Backpex should now handle the event and update the UI accordingly.