3 ms·
Stimulus has a very small surface area, but I find it really enjoyable to use when combined with Turbolinks. My only complaint/comment is that some of the HTML
by mike1o1 6y ago
Stimulus has a very small surface area, but I find it really enjoyable to use when combined with Turbolinks.
My only complaint/comment is that some of the HTML that I need to generate ends up being littered with so many data attributes, especially when combining multiple Stimulus controllers/behaviors.
Has anybody found a clean way around that in Rails templates?
- jyunderwood 6y agoI've found it works well with [ViewComponent](https://github.com/github/view_component https://github.com/github/view_component) if you're in to that.
- swanson 6y agoI share some of the same issues, I have found that ERB templates work better than HAML for lots of data attributes. Basecamp seems to use liberal newlines / spacing when creating html tags (like one line per attribute) so that might help. Server-side "component partials" still don't have a great story, but view_component is one emerging option.
- nthj 6y agoAs another option, HAML lets you extract the attributes into a ruby helper method: https://haml.info/docs/yardoc/file.REFERENCE.html#attribute-methods https://haml.info/docs/yardoc/file.REFERENCE.html#attribute-...
- aaronbrethorst 6y agoSame. I’ve been a happy user of Haml for about ten years, but I think that Tailwind and Stimulus will permanently force me back to ERB :(
- inopinatus 6y agoSame advice as when using Tailwind CSS, or anything of this sort: refactor your application-specific front-end parts at the point of generation, into purposefully named units. For Rails, that means shifting your boilerplate into helpers, partials, and partial layouts. If you're ready for a sharper leading edge, look at ViewComponent. Once the boundaries of your server-side parts for something are congruent to the client-side parts, you have reached the nirvana state of wondering, "can I extract & package these into a library and share it?". This is general advice for all development but particularly and specifically true for Rails devs.