I would love the ability to alias a controller name in Stimulus. Here’s a possible interface.
<div data-controller="loader->product-loader" data-product-loader-url-value="https://...">
<div data-product-loader-target="spinner">...</div>
<div data-product-loader-target="result">...</div>
</div>
There are several reasons for doing this.
Conflicting Controllers
There are times you need multiple versions of the same controller. Perhaps a product-loader
and a category-loader
in the same area that are both loader
controllers. Aliases would allow two versions of the same controller to overlap without conflict.
Self-Documenting
I usually keep controllers generic, however it can be difficult to determine what each controller does in a sea of generic controller names. What is this loader for? It’s loading a product.
Shorten Controller Names
There are times generic controllers won’t work and you need something specific to the domain. I like to use namespaces (folders) to keep this organized, however that quickly becomes unwiedly.
For example, if you have a controller name store--products--category-loader
you could alias it to category-loader
and reference it easier throughout the rest of the HTML.
For the record, there was an earlier discussion on this topic, but it didn’t get much activity.
Would anyone else find aliasing controllers useful?