# Is Stimulus worth using for simple class functions?

**URL:** https://discuss.hotwired.dev/t/is-stimulus-worth-using-for-simple-class-functions/989
**Category:** General
**Created:** [December 18, 2019, 9:41am UTC](https://discuss.hotwired.dev/t/is-stimulus-worth-using-for-simple-class-functions/989 "2019-12-18T09:41:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DannySantos](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/dannysantos/32/639_2.png) [@DannySantos](https://discuss.hotwired.dev/u/DannySantos)
#### Post date: [December 18, 2019, 9:41am UTC](https://discuss.hotwired.dev/t/is-stimulus-worth-using-for-simple-class-functions/989/1 "2019-12-18T09:41:33Z")

</div>

I’ve recently implemented Stimulus on a project and I’m still trying to figure out when to use it, and when to just use regular JS/JQuery. One example of this is I have many tables throughout my app which have checkboxes at the start of each row. In the checkbox column in the table header I have a checkbox which checks/unchecks every checkbox in the table. Currently I’m doing this with a simple function attached to a class:

```
const bindAllChecks = function() {
  $(".select-all-check").change(function() {
    var checks = $(this).closest("table").find(".multiple-check");

    if (this.checked) {
      checks.prop("checked", true).change();
    } else {
      checks.prop("checked", false).change();
    }
  });
};

```

The Stimulus documentation seems to be encouraging me to move this into Stimulus, but that would involve not just adding a controller, but adding a `data-controller`, `data-target` and `data-action` to every single instance of a checkbox table, which isn’t very DRY.

So my question is, is it worth using Stimulus for cases like this or is it better to mix Stimulus with plain JS files?

---

<div class="post-metadata">

### Author: ![sgromkov](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/sgromkov/32/445_2.png) [@sgromkov](https://discuss.hotwired.dev/u/sgromkov)
#### Post date: [December 20, 2019, 12:29pm UTC](https://discuss.hotwired.dev/t/is-stimulus-worth-using-for-simple-class-functions/989/2 "2019-12-20T12:29:18Z")

</div>

Hey Danny!  
As for me, I prefer to do everything via Stimulus controllers. I convince myself that it makes my code cleaner, cause I just have only one way to iteract with DOM elements. And I like the way Stimulus does it for me.

And moreover, Stimulus gives me instruments to do anything I would want with DOM, and I don’t need jQuery anymore.

---

<div class="post-metadata">

### Author: ![mccollek](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/mccollek/32/450_2.png) [@mccollek](https://discuss.hotwired.dev/u/mccollek)
#### Post date: [December 29, 2019, 5:33pm UTC](https://discuss.hotwired.dev/t/is-stimulus-worth-using-for-simple-class-functions/989/3 "2019-12-29T17:33:09Z")

</div>

You could move this to a single ‘check-binding-controller.js’ file in stimulus, and copy-and-paste that function into the ‘connect’ method. The primary advantage you’re getting is that you now have one compact file dedicated to that function, one which you can now easily drop into other applications as you like as it’s own file.

If you added as a data-controller to each check button and modifying the code to just modify the checkbox to which it’s attached you’d also gain the advantages of having it auto-bind when inserting new ones dynamically and also having each one function with it’s own instance of the code.
