better-stimulus_skill

This skill helps you write maintainable StimulusJS controllers by applying SOLID and Better Stimulus patterns for configurable state and declarative
  • Shell

31

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill steveclarke/dotfiles --skill better-stimulus

  • SKILL.md7.8 KB

Overview

This skill applies Better Stimulus best practices for writing maintainable, reusable StimulusJS controllers that follow SOLID design principles. It codifies patterns for configurable controllers, state management with the Values API, declarative events, and clear lifecycle handling. Use it to standardize controller structure and reduce coupling across your front-end codebase.

How this skill works

The skill inspects controller code and recommends or enforces patterns: externalizing configuration into data attributes, migrating instance state to Stimulus values, and minimizing connect() responsibilities. It highlights communication strategies (custom events, outlets, callbacks), lifecycle pairing (connect/disconnect/teardown), and error-handling via an ApplicationController. Output is practical guidance to refactor controllers toward single responsibility and dependency injection.

When to use it

  • When creating new Stimulus controllers to set a consistent architecture
  • When refactoring controllers that mix responsibilities or use instance properties for state
  • During code reviews to enforce declarative events and Values API usage
  • When integrating third-party libraries (Swiper, Chart.js) to scope initialization and cleanup
  • When debugging controller-to-controller communication or Turbo-related DOM caching

Best practices

  • Externalize hardcoded values to data attributes and static classes to make controllers configurable
  • Use static values and valueChanged callbacks for state instead of instance properties
  • Keep connect() focused on third-party initialization and feature detection — avoid setting state or adding listeners there
  • Register DOM and global events with data-action, not addEventListener, to let Stimulus manage lifecycle
  • Prefer custom events, outlets, or callbacks based on relationship: unknown receivers → events; known hierarchy → outlets; direct data requests → callbacks
  • Provide an ApplicationController with handleError(), pair connect() with disconnect(), and implement teardown for Turbo caching

Example use cases

  • Build a reusable toggle controller that reads its active class from data attributes and exposes a value for state
  • Refactor a monolithic page controller into focused controllers that each handle one concern (form, modal, list)
  • Integrate Chart.js in a controller using connect() for init and disconnect() for teardown, with chart config passed via data attributes
  • Replace document addEventListener usage with data-action declarations and value change callbacks
  • Set up inter-controller communication using custom events for broadcasts and outlets for parent-child interactions

FAQ

Use custom events for loose broadcasting or unknown receivers, outlets for direct parent-child relationships, and callbacks when a controller needs to request or return structured data.

When should I put state in values vs. instance properties?

Use values for any serializable state you want Stimulus to observe and persist in the DOM; use instance properties only for transient, non-serializable resources (like library instances), and clean them up in disconnect().

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
better-stimulus skill by steveclarke/dotfiles | VeilStrat