Mid-level Track Roadmap

Hotwire: custom Stimulus

This course covers how Stimulus controllers in one Rails application communicate without holding references to each other. It starts with two controllers attached to one element, then the inherited dispatch() method and its defaults for target, detail and bubbling. It explains why event names get the controller identifier as a prefix and how to change or turn off that prefix. It then covers same-element listeners, @window listeners for custom and native events, and several action descriptors on one element.

What you'll learn

  • ✓Attaching several controllers to one element with data-controller
  • ✓Firing custom events with this.dispatch() and its defaults
  • ✓The identifier:eventName convention and the prefix option
  • ✓Listening for events dispatched on the same element
  • ✓Using @window for custom and native browser events
  • ✓Combining several action descriptors in one data-action
Free preview · Lesson 1 3 min read

Multiple controllers, one element

data-controller isn't limited to one identifier. Write two, separated by a space, and both controllers attach to the same element independently, each with its own targets, values and lifecycle. Neither knows the other exists unless something explicitly connects them. This app's real challenge UI,…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...