There are two different ways of serving Turbo Streams via HTTP and via Websockets
. The regular HTTP streams send updates ONLY to the user that performed an action, whereas Websocket streams (aka Broadcasts) send updates TO ALL users that are subscribed
to a channel.
in Episode 59 we did an in-deep dive into HTTP Turbo Streams.
Now we will dive into the magic beneath Turbo Stream Broadcasts and understand the best practices while working with them.
Episode source code: https://github.com/corsego/121-turbo-hotwire-broadcasts-crud/commit/609c00d0a286ac284dffcc4b5865851294c6cbe4
Broadcaster pattern for Turbo Streams Broadcasts: https://blog.corsego.com/turbo-broadcast-renderer-pattern
Based on this blogpost: https://blog.corsego.com/turbo-hotwire-broadcasts
0:00 Introduction
2:22 Basic Turbo Broadcast from model
5:38 Demistify broadcast_to
7:39 Demistify broadcast_action_to
10:15 Broadcast posts count on create and destroy as HTML
13:31 Broadcast posts count as a partial
14:20 Invoke Broadcasts from Controller, not Model
18:32 Broadcaster pattern. Invoke Broadcasts from Console