Update Shopping Carts in Real-time
Explore how to implement real-time shopping cart updates using Phoenix Presence. Learn to track cart changes across sessions and view live updates within the admin dashboard, enhancing your application's responsiveness and user interaction.
We'll cover the following...
We'll cover the following...
Updating the cart
We’ll hook into two different functions to update the tracked cart:
- When the Channel broadcasts its cart.
- When it receives a broadcast that the cart contents have changed.
Add the highlighted send/2 function calls in the existing ShoppingCartChannel functions.
Presence works by sending an initial state to a client and keeping that state up to date by pushing changes. We need to send the initial state ourselves in the Admin.DashboardChannel. Add the following ...