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

Extract ViewComponent::Core class #1107

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Extract ViewComponent::Core class #1107

wants to merge 5 commits into from

Conversation

BlakeWilliams
Copy link
Member

@BlakeWilliams BlakeWilliams commented Oct 25, 2021

This extracts a new class, ViewComponent::Core which implements the
minimum amount of functionality to have a functioning component library.

The difference between ViewComponent::Core and ViewComponent::Base
is that Base includes extra functionality and compatibility with Rails,
such as slots, built-in route helpers, access to request and
controller, etc.

This new Core class is marked as private and should still be
considered experimental.

This extracts a new class, `ViewComponent::Core` which implements the
minimum amount of functionality to have a functioning component library.

The difference between `ViewComponent::Core` and `ViewComponent::Base`
is that Base includes extra functionality and compatibility with Rails,
such as slots, built-in route helpers, access to `request` and
`controller`, etc.

This new `Core` class is marked as private and should still be
considered experimental.
@jaredcwhite
Copy link
Contributor

@jaredcwhite jaredcwhite commented Oct 25, 2021

@BlakeWilliams Excited to see progress on this! Let me know when it's at a point you'd like some testing outside of a Rails context (aka Bridgetown).

BlakeWilliams and others added 2 commits Oct 25, 2021
* The private keyword is necessary for documentation to correctly
  generate.
* Mark `original_view_context` as protected
* Allow ViewComponent::Core methods to be documented as
  `ViewComponent::Base` methods.
@BlakeWilliams BlakeWilliams marked this pull request as ready for review Oct 26, 2021
@BlakeWilliams BlakeWilliams requested a review from as a code owner Oct 26, 2021
@joelhawksley
Copy link
Contributor

@joelhawksley joelhawksley commented Oct 29, 2021

@jaredcwhite I'd love to see us add some sort of test(s) that put us in the right direction towards better supporting Bridgetown with this change. Might you be up for suggesting some?

@github github deleted a comment from primer-css May 23, 2022
@jaredcwhite
Copy link
Contributor

@jaredcwhite jaredcwhite commented Jun 10, 2022

I'm revisiting this now after some time has passed, and I think what I'm starting to wonder is if there could be some way to have a framework-agnostic component base class (aka one that's not directly subclassing ActionView::Base). The particular view layer used then becomes an implementation detail, pluggable and customizable across different frameworks and not just within Rails.

Alternatively—and this is a much broader topic I realize—is to somehow come up with an external code interface which defines the basics of a "view component" (whether that's actual code in the form of a mixin or something more theoretical like a spec), and then ensure the ViewComponent::Core/Base conforms to that interface.

The rationale for all this being in the Bridgetown framework, we have a Bridgetown::Component base class which is unapologetically inspired by ViewComponent and shares some common semantics, and rather than that being purely "by happenstance" because we're fans, it'd be awesome for those semantics to be enforced to a certain degree by a common interface recognized in the Ruby community as a whole. The "Rack" of component-based view architecture if you will.

Thoughts?

@joelhawksley
Copy link
Contributor

@joelhawksley joelhawksley commented Jun 17, 2022

@jaredcwhite I like it! We've toyed with removing our dependency on AV::Base anyways, and I think @camertron has a branch that is nearly passing without it.

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.

None yet

3 participants