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.