The new Outlets feature looks like a great addition to Stimulus.
To me, a relative newcomer to Stimulus, it seems so obvious that the selection should be done using the controller identifier instead of CSS selector.
<div id="results">
<div class="result" data-controller="result">...</div>
<div class="result" data-controller="result">...</div>
...
</div>
<!-- from the docs -->
<div data-controller="search" data-search-result-outlet=".result">
<!-- why not simply -->
<div data-controller="search" data-search-result-outlet="result">
This would obviate the need to create a CSS class and ensure that there’s never a mismatch (e.g., class="result" data-controller="results"
).
The only reason I can think of for using CSS selectors is that they may be more performant for Stimulus:
document.querySelectorAll('.results') // might be faster than
document.querySelectorAll('[data-controller="results"]')
Can someone please enlighten me about this design choice?