How to respond to channel broadcasts in a Phoenix LiveView app layout (global broadcasts)
July 29, 2024
#development #elixir #phoenix #reading-list
🔗 How to respond to channel broadcasts in a Phoenix LiveView app layout (global broadcasts)
andrewtimberlake.com
In a project I'm working on, I have a menu in my app layout that displays a number of unread messages. Because this is in the app layout, it does not belong to any one LiveView instance, but to all of them. When a new message comes in, or a message is marked as read, there is a broadcast on a PubSub channel that communicates the unread change. While you can subscribe to a channel within a LiveView, you can't subscribe to a channel across all LiveViews in order to update what is essentially global state.
continue reading on andrewtimberlake.com
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.