Publishing Model Changes to a Phoenix Channel

I want to ask if the information as outlined in the following tutorial is still valid for latest Phoenix versions, or is there any new methods to notify about model changes by channels:

I want simply notify the front-end and instruct it to reload the page if new records were created.
Thank you.

This is what you want:
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html

1 Like

I should have mentioned that I do complete separation between back-end (Phoenix) and the front-end (JS driven). So, in other words, how to monitor model changes and notify the JS based front-end about those changes? To put the notifier method (broadcasting the change to the clients) inside the create/update/delete methods?

Well then this is what you want:
https://hexdocs.pm/absinthe/overview.html

It does require you to implement graphql in your frontend though.
Which is not a bad thing as graphql fits your needs perfectly.
Also I can fully recommend Absinthe, it’s awesome.

2 Likes

If You use postgres, You might use triggers for notification. But it is postgres specific…

1 Like

For my current and future projects I use only PostreSQL. You mean to make PostgreSQL notify Phoenix, which in turn notifies the clients via channel messages?

Yes

1 Like

The problem is probably not knowing when inserts and so on are executed, because you are probably using Ecto.Repo.insert/2 in some module that handles these things.
Probably the problem lies in the plumbing that connects the frontend to the backend.
This is where Absinthe/GraphQL comes in.

1 Like

Yes, this is still relevant. The code is a little dated versus some new stuff, but the ideas are the same. There’s no need to use LiveView or Absinthe, you can just use Channels. The Real-Time Phoenix book goes over this with theory, examples, and real-world example.

2 Likes