Module: Turbo::Streams::Broadcasts

Includes:
ActionHelper
Included in:
Turbo::StreamsChannel
Defined in:
app/channels/turbo/streams/broadcasts.rb

Overview

Provides the broadcast actions in synchronous and asynchrous form for the Turbo::StreamsChannel. See Turbo::Broadcastable for the user-facing API that invokes these methods with most of the paperwork filled out already.

Can be used directly using something like Turbo::StreamsChannel.broadcast_remove_to :entries, target: 1.

Instance Method Summary collapse

Instance Method Details

#broadcast_action_later_to(*streamables, action:, target:, **rendering) ⇒ Object



43
44
45
46
# File 'app/channels/turbo/streams/broadcasts.rb', line 43

def broadcast_action_later_to(*streamables, action:, target:, **rendering)
  Turbo::Streams::ActionBroadcastJob.perform_later \
    stream_name_from(streamables), action: action, target: target, **rendering
end

#broadcast_action_to(*streamables, action:, target:, **rendering) ⇒ Object



24
25
26
27
28
# File 'app/channels/turbo/streams/broadcasts.rb', line 24

def broadcast_action_to(*streamables, action:, target:, **rendering)
  broadcast_stream_to *streamables, content: turbo_stream_action_tag(action, target: target, template:
    rendering.delete(:content) || (rendering.any? ? render_format(:html, **rendering) : nil)
  )
end

#broadcast_append_later_to(*streamables, target:, **rendering) ⇒ Object



35
36
37
# File 'app/channels/turbo/streams/broadcasts.rb', line 35

def broadcast_append_later_to(*streamables, target:, **rendering)
  broadcast_action_later_to *streamables, action: :append, target: target, **rendering
end

#broadcast_append_to(*streamables, target:, **rendering) ⇒ Object



16
17
18
# File 'app/channels/turbo/streams/broadcasts.rb', line 16

def broadcast_append_to(*streamables, target:, **rendering)
  broadcast_action_to *streamables, action: :append, target: target, **rendering
end

#broadcast_prepend_later_to(*streamables, target:, **rendering) ⇒ Object



39
40
41
# File 'app/channels/turbo/streams/broadcasts.rb', line 39

def broadcast_prepend_later_to(*streamables, target:, **rendering)
  broadcast_action_later_to *streamables, action: :prepend, target: target, **rendering
end

#broadcast_prepend_to(*streamables, target:, **rendering) ⇒ Object



20
21
22
# File 'app/channels/turbo/streams/broadcasts.rb', line 20

def broadcast_prepend_to(*streamables, target:, **rendering)
  broadcast_action_to *streamables, action: :prepend, target: target, **rendering
end

#broadcast_remove_to(*streamables, target:) ⇒ Object



8
9
10
# File 'app/channels/turbo/streams/broadcasts.rb', line 8

def broadcast_remove_to(*streamables, target:)
  broadcast_action_to *streamables, action: :remove, target: target
end

#broadcast_render_later_to(*streamables, **rendering) ⇒ Object



53
54
55
# File 'app/channels/turbo/streams/broadcasts.rb', line 53

def broadcast_render_later_to(*streamables, **rendering)
  Turbo::Streams::BroadcastJob.perform_later stream_name_from(streamables), **rendering
end

#broadcast_render_to(*streamables, **rendering) ⇒ Object



49
50
51
# File 'app/channels/turbo/streams/broadcasts.rb', line 49

def broadcast_render_to(*streamables, **rendering)
  broadcast_stream_to *streamables, content: render_format(:turbo_stream, **rendering)
end

#broadcast_replace_later_to(*streamables, target:, **rendering) ⇒ Object



31
32
33
# File 'app/channels/turbo/streams/broadcasts.rb', line 31

def broadcast_replace_later_to(*streamables, target:, **rendering)
  broadcast_action_later_to *streamables, action: :replace, target: target, **rendering
end

#broadcast_replace_to(*streamables, target:, **rendering) ⇒ Object



12
13
14
# File 'app/channels/turbo/streams/broadcasts.rb', line 12

def broadcast_replace_to(*streamables, target:, **rendering)
  broadcast_action_to *streamables, action: :replace, target: target, **rendering
end

#broadcast_stream_to(*streamables, content:) ⇒ Object



57
58
59
# File 'app/channels/turbo/streams/broadcasts.rb', line 57

def broadcast_stream_to(*streamables, content:)
  ActionCable.server.broadcast stream_name_from(streamables), content
end