Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slot methods to a module instead of the component class itself #2040

Merged
merged 5 commits into from
Aug 27, 2024

Conversation

ozydingo
Copy link
Contributor

@ozydingo ozydingo commented Jun 1, 2024

What are you trying to accomplish?

Addresses #2027:

  • Define slot methods in a dynamic module so that slot name methods can be overridden with ability to call super

What approach did you choose and why?

  • Inspired by ActiveRecord's naming of GeneratedAttributeMethods, I am choosing the name GeneratedSlotMethods
  • Define a new module and set it to the const self::GeneratedSlotMethods in the inherited hook defined by ViewComponent::Slotable, similar to how ActiveRecord creates <model>::GeneratedAttributeMethods.
  • include self::GeneratedSlotMethods in the same inherited hook
  • define the <slot> and <slot>? methods on the module

TODO

  • FIX: Use the inherited hook and not the included hook; ViewComponent::Slotable is included only once by ViewComponent::Base
  • Add test to make sure independent components do not share methods
  • Ensure component subclasses that define their own slots also inherit superclass slot methods
  • Investigate other slottable dynamic methods (currently commented out)

Anything you want to highlight for special attention from reviewers?

  • Added a step in CONTRIBUTING to bundle install, with the goal of installing appraisal (otherwise bundle exec appraisal install would fail)
  • Running bundle exec appraisal install modified the gemfiles and I'm not sure why. I have no experience with appraisal. I imagine I will need to revert these changes, but I'm keeping them on the branch for now since if I revert I can't run tests, and also to ask about it.

@ozydingo ozydingo changed the title Ahs generated methods Add slot methods to a module instead of the component class itself Jun 1, 2024
@ozydingo ozydingo force-pushed the ahs_generated_methods branch 5 times, most recently from 2430994 to c1846e2 Compare August 24, 2024 07:38
@ozydingo ozydingo marked this pull request as ready for review August 24, 2024 08:07
… `#{slot}` and `#{slot?}` methods on this module, allowing these methods to be overridden with access to `super` implementation.
@ozydingo
Copy link
Contributor Author

@joelhawksley after a "brief" hiatus I cam back to this and got it in working order. Unfortunately the "Test compatibility with Primer ViewComponents" is failing, and if anyone had some bandwidth to help shine some light into that failure that would be hugely appreciated. I'll try to dig in when I get another chance but I'll be wandering in a lot of unfamiliar territory as I do! It's also pretty unclear to me, at a high level, why this change would specifically break the test_single_select_item_checked_via_keyboard_space test so I suspect the resolution will involve a lot of digging into those component specifics.

docs/CONTRIBUTING.md Outdated Show resolved Hide resolved
Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'm going to defer to @BlakeWilliams for the review here ❤️

Copy link
Contributor

@BlakeWilliams BlakeWilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this improvement!

docs/CHANGELOG.md Outdated Show resolved Hide resolved
@joelhawksley joelhawksley enabled auto-merge (squash) August 27, 2024 16:16
@joelhawksley joelhawksley merged commit d514f5d into ViewComponent:main Aug 27, 2024
19 checks passed
@ozydingo ozydingo deleted the ahs_generated_methods branch August 27, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants