class ViewComponentReflex::Engine

Public Class Methods

configure() { |self| ... } click to toggle source
# File lib/view_component_reflex/engine.rb, line 33
def self.configure
  yield self if block_given?
end

Public Instance Methods

receive(data) click to toggle source
# File lib/view_component_reflex/engine.rb, line 11
def receive(data)
  target = data["target"].to_s
  reflex_name, _ = target.split("#")
  reflex_name = reflex_name.camelize
  component_name = reflex_name.end_with?("Reflex") ? reflex_name[0...-6] : reflex_name
  component = begin
    component_name.constantize
  rescue
    # Since every reflex runs through this monkey patch, we're just going to ignore the ones that aren't for components
  end

  if component&.respond_to?(:init_stimulus_reflex)
    component.init_stimulus_reflex
  else
    p "Tried to initialize view_component_reflex on #{component_name}, but it's not a view_component_reflex"
  end
  receive_original(data)
end