Skip to content

How to broadcast to live resource #495

Closed Answered by Flo0807
asok asked this question in Q&A
Jul 29, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@asok
Comment options

@Flo0807
Comment options

Answer selected by Flo0807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants