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: nil, targets: nil, **rendering) ⇒ Object



66
67
68
69
# File 'app/channels/turbo/streams/broadcasts.rb', line 66

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

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



36
37
38
39
40
# File 'app/channels/turbo/streams/broadcasts.rb', line 36

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

#broadcast_after_later_to(*streamables, **opts) ⇒ Object



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

def broadcast_after_later_to(*streamables, **opts)
  broadcast_action_later_to(*streamables, action: :after, **opts)
end

#broadcast_after_to(*streamables, **opts) ⇒ Object



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

def broadcast_after_to(*streamables, **opts)
  broadcast_action_to(*streamables, action: :after, **opts)
end

#broadcast_append_later_to(*streamables, **opts) ⇒ Object



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

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

#broadcast_append_to(*streamables, **opts) ⇒ Object



28
29
30
# File 'app/channels/turbo/streams/broadcasts.rb', line 28

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

#broadcast_before_later_to(*streamables, **opts) ⇒ Object



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

def broadcast_before_later_to(*streamables, **opts)
  broadcast_action_later_to(*streamables, action: :before, **opts)
end

#broadcast_before_to(*streamables, **opts) ⇒ Object



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

def broadcast_before_to(*streamables, **opts)
  broadcast_action_to(*streamables, action: :before, **opts)
end

#broadcast_prepend_later_to(*streamables, **opts) ⇒ Object



62
63
64
# File 'app/channels/turbo/streams/broadcasts.rb', line 62

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

#broadcast_prepend_to(*streamables, **opts) ⇒ Object



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

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

#broadcast_remove_to(*streamables, **opts) ⇒ Object



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

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

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



75
76
77
# File 'app/channels/turbo/streams/broadcasts.rb', line 75

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

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



71
72
73
# File 'app/channels/turbo/streams/broadcasts.rb', line 71

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

#broadcast_replace_later_to(*streamables, **opts) ⇒ Object



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

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

#broadcast_replace_to(*streamables, **opts) ⇒ Object



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

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

#broadcast_stream_to(*streamables, content:) ⇒ Object



79
80
81
# File 'app/channels/turbo/streams/broadcasts.rb', line 79

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

#broadcast_update_later_to(*streamables, **opts) ⇒ Object



46
47
48
# File 'app/channels/turbo/streams/broadcasts.rb', line 46

def broadcast_update_later_to(*streamables, **opts)
  broadcast_action_later_to(*streamables, action: :update, **opts)
end

#broadcast_update_to(*streamables, **opts) ⇒ Object



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

def broadcast_update_to(*streamables, **opts)
  broadcast_action_to(*streamables, action: :update, **opts)
end