komposable / komponent

An opinionated way of organizing front-end code in Ruby on Rails, based on components

Home Page:http://komponent.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an example of generic javascript files

florentferry opened this issue · comments

In the documentation, we don't have an example on how to handle generic javascript file, only javascript file specific to component. We need to show where to set that kind of files in our component-based hierarchy, in frontend ?

A lot of people shoulda use turbolinks or rails-ujs so let's show how to handle that kind of modules in our structure.

If it's just Turbolink and Rails UJS initialization (a couple lines for each), I think it can stay in each pack file (ie. frontend/packs/application.js).

If it's more than that, maybe in frontend/base/on in another folder in frontend/?

But that's lines are duplicated for each packs, we could make a folder in frontend/ to share that kind of initialization, but not a strong need because its just 2 lines for both.

While we have js file or controller to handle specific behaviors on component, we have the need to share common ones to several components. Like showing a datepicker in various componets, but that's not the way component-based doing it, if we need to doing that way, we have just to create new datepicker component.

Just put that files in frontend/ like we do with stimulus_application or in a specific frontend/shared folder, and require it in your code seems fine.

So let's close that issue if we have not idea yet on what can stand in here except preventing 2 lines initialization duplication.