Coming in Stimulus 1.2: The Classes and Values APIs

Hello friends!

I’ve just opened a pull request for two new Stimulus APIs, Classes and Values, which we’ve slated for inclusion in the next release.

It’s designed as an improvement on the existing this.data API (a.k.a. the Data Map API). In short, it helps you:

  • Split app-specific CSS class strings out of your controllers and into HTML, and access them through controller properties
  • Declare the name and value type (string, number, boolean, array, or object) of data attributes, and access those values through controller properties
  • Observe and respond to changes in data attributes

Please take a look through the PR and let us know what you think. Towards the bottom you’ll find instructions for trying these APIs out in your application.

13 Likes

Observe and respond to changes in data attributes

How weird, I was just about to ask politely if it’d be possible to add something like that since I end up writing my own code to do it on a relatively regular basis.

Big thanks, by the way - been using Stimulus since one of the ‘0’ versions. It’s the first library I’ve found which I can use in pretty much the same way that I’ve written JS for the past decade or so, but with some clever refinements that I’d not thought of! It’s so cool :slight_smile:

1 Like