Move StimulusReflex::Channel to app/ and allow for a configurable parent channel #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of PR (feature, enhancement, bug fix, etc.)
Feature/enhancement and bug fix
Description
This PR is 100% a carbon-copy of @dark-panda's #322, adapted to use the new initializer structure introduced in #339. @dark-panda did all of the hard work on this and I just needed to move things along in service of a timely v3.4.0 release.
Feature/Enhancement
Allows the parent class of
StimulusReflex::Channel
to be configurable viaStimulusReflex.configuration.parent_channel
. This can be done via the initializer:It defaults to
ApplicationCable::Channel
.Bug Fix
This came about while attempting an upgrade because for some reason @dark-panda's app's
ApplicationCable::Channel
implementation was not being loaded correctly, but only in certain situations. For instance, passenger in would not load the file, but puma would. There are mysterious forces at work in the Rails loading mechanisms and all of the various pieces that touch it, and they sometimes have different behaviour.In putting together this PR, a second issue was discovered that is not specific to my app. Because SR is overriding
ApplicationCable::Channel#initialize
and then doing arequire
on the user-supplied implementation, the user-supplied implementation gets skipped on the first call to a channel's#initialize
method. Thus, if the user supplies their ownApplicationCable::Channel#initialize
method, it will only start to be used after at least one ActionCable connection is made, as that will cause the SR implementation to be called first, which itself then overwrites its own implementation via therequire
. Because this PR avoids overridingApplicationCable::Channel
in any way, we avoid this oddity. As to why anyone would overrideApplicationCable::Channel#initialize
is another matter, but regardless, this PR avoids this behaviour.Why should this be added
It is possible that someone would want to provide a different parent class to
StimulusReflex::Channel
, or otherwise name their base channel something else entirely. This allows them to configure this behaviour, with the default being as it was before.It avoids a small issue discovered when calling a user-supplied
ApplicationCable::Channel#initialize
.Reduces code complexity by avoiding having to override
ApplicationCable::Channel
in SR.Checklist