from Hacker News

Stimulus.js 2.0

by ssaunier_ on 12/4/20, 5:52 PM with 133 comments

  • by benzible on 12/4/20, 7:26 PM

    Alpine.js is worth a look as well [1]. I've been working with it as part of the newly christened "PETAL stack" [2] of Phoenix, Elixir, Tailwind, Alpine.js, and LiveView.

    [1] https://css-tricks.com/alpine-js-the-javascript-framework-th...

    [2] https://thinkingelixir.com/podcast-episodes/021-tailwind-css...

  • by phaedryx on 12/4/20, 11:40 PM

    I worked with Stimulus for about a month and found it to be frustrating:

    1. There is not a lot of documentation

    2. They don't provide any testing guidelines, the best I've found is hand-wavy test-with-a-browser stuff

    3. Everything is essentially global

    4. Functions are disconnected from their parameters, i.e. I can't tell which bits of data a function is using without digging through a bunch of code.

    5. Putting state in your HTML is tricky if you also want to modify the DOM.

    6. Their naming scheme is cumbersome, e.g. data-controller="using-a--sub-directory" and data-target="some--nested--target-has-a.function", that is, the fact that everything is location-in-your-code-file-structure based.

    And a lot of other small things.

    Ironically, using Stimulus convinced me to switch to Vue because I liked their value proposition of "Javascript sprinkles for your HTML", which Vue lets me do, but more intuitively.

  • by cutler on 12/4/20, 11:05 PM

    I have great hopes that Stimulus 2.0 and Ruby 3.0 will put Rails back in the spotlight as the sane alternative to SPA abuse. Ruby and Rails have some really talented people on their teams and there's something special about the Ruby language which makes it such a fertile environment for innovation. Only Clojure compares in this respect.
  • by mike1o1 on 12/4/20, 6:28 PM

    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?

  • by catwind7 on 12/5/20, 1:36 AM

    We adopted stimulusjs a couple of years ago for adding some basic interactivity on our pages and it was a decent tool, but we quickly grew out of it once we started adding more complex (form based) front-end behavior involving lots of state changes. We're currently trying to migrate a significant amount of stimulus code over to react.

    Not knocking on stimulusjs, but just be wary that it does not grow well with increasing client side complexity. You'll end up writing a lot of javascript boilerplate / DOM manipulation code / custom state management components. From my experience, it's a nice lightweight tool for when you:

    1. Just need to add some light interactivity (toggling visibility of components, any basic view filtering) that do not involve a lot of logic 2. Don't need j.s unit tests (stimulus has not been the most testable tool - we lean mostly on integration tests).

  • by gerry_shaw on 12/4/20, 9:01 PM

    Unpoly https://unpoly.com is also worth a look if you are interested in these things. It combines Turbolinks and Stimulus functionality in a very usable way.
  • by dang on 12/4/20, 9:07 PM

  • by vmsp on 12/4/20, 9:18 PM

    See also GitHub Catalyst

    https://github.github.io/catalyst/

  • by stepbeek on 12/4/20, 8:32 PM

    I love Stimulus and am super happy to see this update.

    It’s encoding conventions that we’ve fallen into using it for the last year. The callbacks in value changes are going to make my life much easier.

  • by lostfocus on 12/4/20, 10:44 PM

    And just when Symfony announced their preferred way of doing frontend work is based on Stimulus, too. Great timing.
  • by correlator on 12/4/20, 8:00 PM

    Stable, efficient and intuitive. Thank you to the stimulus team!
  • by tpetry on 12/4/20, 6:59 PM

    Now i am waiting for the next turbolinks release. Their hey.com service has some interesting turbolinks extensions: https://dev.to/borama/a-few-sneak-peeks-into-hey-com-technol... and following
  • by obiefernandez on 12/4/20, 6:13 PM

    Good timing. There was talk of a fork brewing...
  • by osxman on 12/5/20, 8:38 AM

    This is good news. I work for 6 months with StimulusJS 1 and I'm very happy to use it. I use it mainly in a rails app combined with Turbolinks.

    My original thought was to go for an SPA with a rails API backend. I tried out both React & Vue extensively but got stuck in a while. Since implementing Rails and plain 'vanilla' JS it went better. But with StimulusJS 1+ it went simply great.

    Allready upgraded to 2.0 and it feels even more structured with the new features, like values and improved targets.

  • by cutler on 12/4/20, 11:31 PM

    What's the difference between Pjax and Turbolinks? Just a generic version of the same thing? Could Stimulus [Reflex] be hacked to work with Django or does it have strong ties to Rails?
  • by shay_ker on 12/4/20, 7:11 PM

    Is there a convincing Stimulus vs. React-Rails post anywhere?
  • by yborg on 12/4/20, 10:23 PM

    Is there a good comparison summary of the major JS frameworks available somewhere?
  • by jdhornby on 12/4/20, 11:24 PM

    If anyone is interested in “the magic” DHH is talking about, this is a fantastic resource: https://dev.to/borama/a-few-sneak-peeks-into-hey-com-technol...
  • by ksec on 12/4/20, 7:36 PM

    Is Stimulus 2.0 the NEW MAGIC DHH was referring to? I was expecting something much bigger.
  • by Drakula2k on 12/4/20, 6:51 PM

    Nice to see that it keeps improving.
  • by Scarbutt on 12/4/20, 7:30 PM

    A modest JavaScript framework for the HTML you already have

    Are they implying one shouldn't use it if you don't have any HTML already?