Sha256: 129b6e3eeeef964f2195ddc4a5b972166836f25143aab51e08ce535e3bd6dd90

Contents?: true

Size: 991 Bytes

Versions: 6

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module StimulusReflex
  class PageBroadcaster < Broadcaster
    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

    def to_sym
      :page
    end

    def page?
      true
    end

    def to_s
      "Page"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.3 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.5.0.rc4 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.5.0.rc3 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.5.0.rc2 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.5.0.rc1 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.5.0.pre10 lib/stimulus_reflex/broadcasters/page_broadcaster.rb