Class: MaquinaStream::Broadcaster::TurboTransport
- Inherits:
-
Object
- Object
- MaquinaStream::Broadcaster::TurboTransport
- Defined in:
- lib/maquina_stream/broadcaster.rb
Overview
Default transport. Turbo Streams today; the seam is here so SSE is possible without the broadcaster knowing about it.
Appends go out as broadcast_append_to against the message element;
patches as broadcast_replace_to with method: "morph", so idiomorph
pairs the node by id instead of recreating it. Every stream action carries
data-ms-seq and data-ms-frame.
A no-op when Turbo is not loaded, so the engine's Ruby side stays usable without it.
Instance Method Summary collapse
-
#call(record:, frame:, config:) ⇒ Object
Emits one Frame.
Instance Method Details
#call(record:, frame:, config:) ⇒ Object
Emits one Frame. The transport contract is this method and nothing else.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/maquina_stream/broadcaster.rb', line 201 def call(record:, frame:, config:) return unless defined?(Turbo::StreamsChannel) target = record.maquina_stream_target frame.appends.each do |block| Turbo::StreamsChannel.broadcast_append_to( target, target: "ms-msg-#{record.maquina_stream_id}", content: block.html, attributes: frame_attributes(frame, :append) ) end frame.patch.each do |block| Turbo::StreamsChannel.broadcast_replace_to( target, target: block.id, content: block.html, attributes: frame_attributes(frame, :patch).merge("method" => "morph") ) end end |