Module: Superglue::Streams::Broadcasts
- Included in:
- Superglue::StreamsChannel
- Defined in:
- app/channels/superglue/streams/broadcasts.rb
Overview
This file was ported from the amazing folks at turbo-rails You can find its MIT License here: github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
Instance Method Summary collapse
- #broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) ⇒ Object
- #broadcast_action_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) ⇒ Object
- #broadcast_append_later_to(*streamables, **opts) ⇒ Object
- #broadcast_append_to(*streamables, **opts) ⇒ Object
- #broadcast_prepend_later_to(*streamables, **opts) ⇒ Object
- #broadcast_prepend_to(*streamables, **opts) ⇒ Object
- #broadcast_stream_to(*streamables, content:) ⇒ Object
- #broadcast_update_later_to(*streamables, **opts) ⇒ Object
- #broadcast_update_to(*streamables, **opts) ⇒ Object
Instance Method Details
#broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 49 def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) streamables.flatten! streamables.compact_blank! return unless streamables.present? targets = (target ? [target] : targets).map do |item| convert_to_superglue_fragment_id(item) end if save_target [:saveAs] = convert_to_superglue_fragment_id(save_target) end Superglue::Streams::ActionBroadcastJob.perform_later \ stream_name_from(streamables), action: action, targets: targets, options: , **rendering end |
#broadcast_action_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 17 def broadcast_action_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering) locals = rendering[:locals] || {} targets = (target ? [target] : targets) targets = targets.map do |item| convert_to_superglue_fragment_id(item) end if save_target [:saveAs] = convert_to_superglue_fragment_id(save_target) end locals[:broadcast_target_keys] = targets locals[:broadcast_action] = action locals[:broadcast_options] = rendering[:locals] = locals broadcast_stream_to(*streamables, content: render_broadcast_action(rendering)) end |
#broadcast_append_later_to(*streamables, **opts) ⇒ Object
41 42 43 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 41 def broadcast_append_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :append, **opts) end |
#broadcast_append_to(*streamables, **opts) ⇒ Object
9 10 11 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 9 def broadcast_append_to(*streamables, **opts) broadcast_action_to(*streamables, action: :append, **opts) end |
#broadcast_prepend_later_to(*streamables, **opts) ⇒ Object
45 46 47 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 45 def broadcast_prepend_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :prepend, **opts) end |
#broadcast_prepend_to(*streamables, **opts) ⇒ Object
13 14 15 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 13 def broadcast_prepend_to(*streamables, **opts) broadcast_action_to(*streamables, action: :prepend, **opts) end |
#broadcast_stream_to(*streamables, content:) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 67 def broadcast_stream_to(*streamables, content:) streamables.flatten! streamables.compact_blank! return unless streamables.present? ActionCable.server.broadcast stream_name_from(streamables), content end |
#broadcast_update_later_to(*streamables, **opts) ⇒ Object
37 38 39 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 37 def broadcast_update_later_to(*streamables, **opts) broadcast_action_later_to(*streamables, action: :update, **opts) end |
#broadcast_update_to(*streamables, **opts) ⇒ Object
5 6 7 |
# File 'app/channels/superglue/streams/broadcasts.rb', line 5 def broadcast_update_to(*streamables, **opts) broadcast_action_to(*streamables, action: :update, **opts) end |