TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Learn Stimulus in Ruby on Rails by Building a Toggle)

27 pointsby hbroadbentalmost 2 years ago

3 comments

hbroadbentalmost 2 years ago
Hey HN!<p>For those new to Rails, Stimulus (<a href="https:&#x2F;&#x2F;stimulus.hotwired.dev&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;stimulus.hotwired.dev&#x2F;</a>) is a way to sprinkle frontend javascript code into your Rails views.<p>I held off using Stimulus in my Rails apps for a long time because I didn&#x27;t understand it — the data= attributes looked weird, and the connection between my Rails views and Stimulus javascript controllers was confusing.<p>So I decided to write the guide I wish I had when I was learning Stimulus.<p>Hope you enjoy it! I&#x27;m happy to answer any questions, feel free to ask any.<p>Thanks, Harrison
评论 #36502284 未加载
评论 #36487445 未加载
RileyJamesalmost 2 years ago
I love stimulus. And Hotwire. I find everything more maintainable and faster to developer when rails on the centre of the universe. Obviously a personal preference.<p>I faced a similar display toggle-able use case for form fields recently.<p>I did find that I used stimulus to hide the fields there was a slightly “flicker” as they appeared and then were hidden in the connect() function.<p>It didn’t affect my use case, as I could default hide and then toggle them to appear with stimulus.<p>But in the event they should appear by default and then be hidden based on some logic within the stimulus controller, is there a better way to handle this?
评论 #36488271 未加载
ArizonaJoealmost 2 years ago
Thanks for the writeup. I had the opportunity to use StimulusJS at a recent opportunity and couldn&#x27;t agree with it. I found several issues with the patterns it encourages, such as:<p>-magic variable transformed from props, lots of uncertainty between the HTML attributes I typed and the actual name of the JS variable -have to now define these magic variables in typescript -defining values and automatically converting strings &#x2F; numbers magically seems hacky - why does it ask to separate CSS classes into it&#x27;s own special attribute and magic variable?<p>I feel like I&#x27;m speaking crazy when I see anyone recommend Stimulus and from my experience I&#x27;d much rather just use web components without shadow DOM. Seriously, EVERYTHING Stimulus does web components do 10x better and cleaner. They both try to do the same thing but the Stimulus approach honestly came across as a high school final project taken too far.
评论 #36505483 未加载