Skip to content

Commit

Permalink
Fix reflex_data keyword argument (#673)
Browse files Browse the repository at this point in the history
# Type of PR (feature, enhancement, bug fix, etc.)
bug fix

## Description
Rename named parameter, and change error message that was causing an
exception in a rescue block.

## Why should this be added

Stimulus reflex doesn't work at all without these fixes.

## Checklist

- [X ] My code follows the style guidelines of this project
- [ X] Checks (StandardRB & Prettier-Standard) are passing
  • Loading branch information
brunoenten committed Nov 26, 2023
1 parent aed8da1 commit 208409e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/channels/stimulus_reflex/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def receive(data)
delegate_call_to_reflex reflex
rescue => exception
error = exception_with_backtrace(exception)
error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}"

if reflex
error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}"
reflex.rescue_with_handler(exception)
reflex.logger&.error error_message
reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
else
error_message = "\e[31mReflex failed: #{error[:message]} \e[0m\n#{error[:stack]}"
unless exception.is_a?(StimulusReflex::VersionMismatchError)
StimulusReflex.config.logger.error error_message
end
Expand Down
1 change: 1 addition & 0 deletions lib/stimulus_reflex/reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class StimulusReflex::Reflex
# END TODO: remove

alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
alias_method :data, :reflex_data

def initialize(channel, reflex_data:)
@channel = channel
Expand Down
2 changes: 1 addition & 1 deletion lib/stimulus_reflex/reflex_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(channel, data)
end

def call
reflex_class.new(channel, data: data)
reflex_class.new(channel, reflex_data: data)
end

private
Expand Down

0 comments on commit 208409e

Please sign in to comment.