Sha256: 7df1f2b9e529a94e9c9946b397bffcfb49643c512c0fab17d8ef868624a34030

Contents?: true

Size: 925 Bytes

Versions: 2

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

module StimulusReflex
  class PageBroadcaster < Broadcaster
    def broadcast(selectors, data)
      reflex.controller.process reflex.url_params[:action]
      page_html = reflex.controller.response.body

      return unless page_html.present?

      document = Nokogiri::HTML(page_html)
      selectors = selectors.select { |s| document.css(s).present? }
      selectors.each do |selector|
        html = document.css(selector).inner_html
        cable_ready[stream_name].morph(
          selector: selector,
          html: html,
          children_only: true,
          permanent_attribute_name: permanent_attribute_name,
          stimulus_reflex: data.merge({
            last: selector == selectors.last,
            broadast_type: to_sym
          })
        )
      end
      cable_ready.broadcast
    end

    def to_sym
      :page
    end

    def page?
      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stimulus_reflex-3.3.0.pre3 lib/stimulus_reflex/broadcasters/page_broadcaster.rb
stimulus_reflex-3.3.0.pre2 lib/stimulus_reflex/broadcasters/page_broadcaster.rb