Class: StimulusReflex::PageBroadcaster

Inherits:
Broadcaster show all
Defined in:
lib/stimulus_reflex/broadcasters/page_broadcaster.rb

Instance Attribute Summary

Attributes inherited from Broadcaster

#cable_ready, #logger, #operations, #reflex

Instance Method Summary collapse

Methods inherited from Broadcaster

#broadcast_error, #broadcast_forbid, #broadcast_halt, #initialize, #nothing?, #selector?

Constructor Details

This class inherits a constructor from StimulusReflex::Broadcaster

Instance Method Details

#broadcast(selectors, data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stimulus_reflex/broadcasters/page_broadcaster.rb', line 5

def broadcast(selectors, data)
  reflex.controller.process reflex.params[:action]
  document = StimulusReflex::HTML::Document.new(reflex.controller.response.body)

  return if document.empty?

  selectors = selectors.select { |s| document.match(s).present? }
  selectors.each do |selector|
    operations << [selector, StimulusReflex.config.morph_operation]
    html = document.match(selector).inner_html
    cable_ready.send StimulusReflex.config.morph_operation, {
      selector: selector,
      html: html,
      payload: payload,
      children_only: true,
      permanent_attribute_name: permanent_attribute_name,
      stimulus_reflex: data.merge(morph: to_sym)
    }
  end
  cable_ready.broadcast
end

#page?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/stimulus_reflex/broadcasters/page_broadcaster.rb', line 31

def page?
  true
end

#to_sObject



35
36
37
# File 'lib/stimulus_reflex/broadcasters/page_broadcaster.rb', line 35

def to_s
  "Page"
end

#to_symObject



27
28
29
# File 'lib/stimulus_reflex/broadcasters/page_broadcaster.rb', line 27

def to_sym
  :page
end