Can we create Mixins in Stimulus?

You can extend controllers as described here to inherit the targets/methods. That’s been pretty useful for me.

You can also have multiple stimulus controllers per DOM element, essentially letting you mix and match groups of behaviors on the fly. I find it nicest to keep stimulus methods concerned with just responding to events on targets and light data/dom manipulation and tuck more complex logic away in other modules.

2 Likes