Organization and Decisions
Turbo requests
Most turbo requests target lui-main-layout frame. This is by design, to mimic a single page aplication where only the main content changes on navigation.
It should also have the turbo action advance to update the browser history and url.
As a rule of thumb, GET requests inside a turbo frame expect a turbo response. This means that the response should be a partial that can be rendered inside the frame. Meanwhile any non-GET request should return a turbo stream or a redirect.
You should also avoid using data-turbo-method on links and forms without a good reason.
This is because it will make the request a turbo request (expecting a turbo stream response), and depending on how the controller responds, it may not be the desired effect.
This page will be a needed companion when you are deciding how to structure your page and responses having turbo in mind.
Composition over Inheritance
When you need to create a new component, if it uses/configures other existing components, it may be tempting to inherit from them. But, following the official ViewComponent guidelines I advice you to consider using composition over inheritance. Read more here.
This should always apply for Entity specific components.
Entity components are components that are specific to a model or entity in the system.
So, for example, imagine you need to a component to render a EntityToken for a specific model Category.
Example:
# app/view_components/loopos_ui/entities/category_entity_token.rbclass LooposUi::Entities::CategoryEntityToken < LoopComponent option: :category # Category model instance #... the component should know how to render a category entity token private # private methods are acessible only by the component itself and the view # Mapping methods, similar to what we do in Presenters def name category.name end #...end# app/view_components/loopos_ui/entities/category_entity_token/category_entity_token.html.erb<%= render LooposUI::EntityToken.new(text: name, ...) %>