View Components: Recursively add scripts for subclass's parent component#7772
Merged
View Components: Recursively add scripts for subclass's parent component#7772
Conversation
zachmargolis
approved these changes
Feb 6, 2023
| @scripts ||= _sidecar_files(['js', 'ts']).map { |file| File.basename(file, '.*') } | ||
| @scripts ||= begin | ||
| scripts = _sidecar_files(['js', 'ts']).map { |file| File.basename(file, '.*') } | ||
| scripts.concat superclass.scripts if superclass.respond_to?(:scripts) |
Contributor
There was a problem hiding this comment.
I think one of the things that was bugging me about the previous implementation was the specific BaseComponent being hardcoded, but switching this to superclass.respond_to?(:scripts) is way better IMO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎫 Ticket
Extracted from #7761, related to LG-8771.
🛠 Summary of changes
Revises behavior of base script component to add scripts for the current class implementation, as well as any parent class scripts if the current component is subclassing another.
Essentially, given the following:
Before: When rendering
ChildClassComponent, onlychild_class_component.tswould be added to the pageAfter: Both
child_class_component.tsandparent_class_component.tswould be added to the pageNote that this seemed like an "obvious" behavior to me on Friday, though I'm of a less-strong opinion today, so happy to hear any dissenting opinion on whether it should work this way.
This should not impact any existing component, since while we do have some subclassing (e.g.
DownloadButtonComponent < ButtonComponent), the parent classes in those cases do not have any associated scripts. This was discovered to be an issue while implementing #7761.📜 Testing Plan
rspec spec/components/base_component_spec.rb