Make A Stimulus Controller More Configurable & Extendable

InstructorDamon Bauer

Share this video with your friends

Send Tweet

The more generic you can make your Stimulus controllers, the better.

We'll explore how to put more control in the hands of the consumer of your Stimulus controller by providing a data attribute configure a controller (and a fallback, in case an attribute isn't provided).

We'll also look at how we can make your code "open for extension, but closed for modification" (part of SOLID). We'll refactor a ternary operator to use an object literal lookup. This will help make a method "do one thing" (bordering on "single responsibility principle", the S in SOLID).