Skip to content

Commit

Permalink
Extract explaining method
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Sep 22, 2024
1 parent 3ad21e9 commit 595634e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/channels/turbo/streams/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,9 @@ def broadcast_refresh_to(*streamables, **opts)
end

def broadcast_action_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering)
content = rendering.delete(:content)
html = rendering.delete(:html)
render = rendering.delete(:render)

template =
if render == false
nil
else
content || html || (render_format(:html, **rendering) if rendering.present?)
end

broadcast_stream_to(*streamables, content: turbo_stream_action_tag(action, target: target, targets: targets, template: template, **attributes))
broadcast_stream_to *streamables, content: turbo_stream_action_tag(
action, target: target, targets: targets, template: render_broadcast_action(rendering), **attributes
)
end

def broadcast_replace_later_to(*streamables, **opts)
Expand Down Expand Up @@ -119,4 +110,17 @@ def refresh_debouncer_for(*streamables, request_id: nil) # :nodoc:
def render_format(format, **rendering)
ApplicationController.render(formats: [ format ], **rendering)
end

def render_broadcast_action(rendering)
content = rendering.delete(:content)
html = rendering.delete(:html)
render = rendering.delete(:render)

template =
if render == false
nil
else
content || html || (render_format(:html, **rendering) if rendering.present?)
end
end
end

0 comments on commit 595634e

Please sign in to comment.