-
Notifications
You must be signed in to change notification settings - Fork 443
Description
Hey there, thanks for the new Stimulus 2.0 release!
I really love the new APIs!
After using the new unified target attributes introduced in #202 I asked myself why the same thing wasn't applied for the action attributes. Was there a specific reason to not do that?
The goal of unifying the target attributes was to align with the new values and classes APIs, so it would make sense to also adopt this syntax to the action attributes, right?
Personally I somehow dislike the new target attributes syntax, because it requires to write more HTML code. Especially if you have a lot of targets in your HTML markup - it seems to clutter up the HTML markup even more, which doesn't seem to be the goal of Stimulus. You end up with a lot of "new" data attributes on the element which are all named differently compared to one attribute which is always named data-target but can hold a bunch of targets.
<div data-controller="list sort">
<div data-target="list.item sort.item">...</div>
</div>Compared to:
<div data-controller="list sort">
<div data-list-target="item" data-sort-target="item">...</div>
</div>But I guess it just takes some time to get used to it.
Anyway, if we now take a look at the current action attributes it doesn't behave the same way.
Because the motivation for the target attribute change was to be consistent with the other APIs it would just make sense to also apply this "new" syntax on the action attributes.
Example:
<div data-controller="gallery">
<button data-action="click->gallery#next">…</button>
</div>becomes:
<div data-controller="gallery">
<button data-gallery-action="click->next">…</button>
</div>Or using the event shorthand syntax:
<button data-gallery-action="next">…</button>Either way, I just think it would make sense to have a consistent API for all data attributes😉
I'm happy to discuss or to get to know the thought process behind that change!
Thank you!