broadcast_toimmediately transmit all pending operations to subscribed ActionCable clients. Both methods can be called on an existing instance of
CableReady::Channelsor as the conclusion to a method chain.
clear: falseas the last keyword parameter to prevent clearing the queue. Not clearing the operations queue leaves it available for potential future
broadcastmethods to repeat.
stream_frommethod in their
broadcastis most frequently called with no arguments, which instructs CableReady to send one ActionCable payload for every string-based stream identifier with pending operations.
broadcastwith no parameters delivers all queues identified by strings while ignoring any queues identified by constants.
stream_formethod in their
broadcast_tois most frequently called with its single mandatory argument, which is an instance of an ActiveRecord model. This instructs CableReady to send one ActionCable payload for every constant-based stream identifier with pending operations.
broadcastmethod, the developer can deliver multiple constant-based identifiers, or constain the call to a subset. However, while we don't want to be prescriptive, the nature of the resource-driven functionality and the patterns it enables means that most applications using constant-based identifiers will likely be used in a 1:1 channel-to-broadcast capacity. It's actually difficult to come up with a realistic example:
broadcast_towith only an ActiveRecord model parameter delivers all queues identified by constants while ignoring any queues identified by strings.
CableReady::Broadcasterhas access to a special, server-side version of the Rails dom_id helper. Whereas the view helper is typically used to generate
idvalues for rendering DOM elements which map cleanly to ActiveRecord model instances, this method is intended to generate CSS selector strings used by CableReady to locate those DOM elements.
#so that it can be passed directly to
document.querySelector()on the client. This syntactic sugar means you can use a clever DSL instead of ugly string concatenations.