question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unifying action attributes

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:21
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
lubomirblazekczcommented, Dec 7, 2020

And please don’t apply this new syntax also on action attributes, that would really destroy the easy convenient HTML markup that stimulus always had. I think data-controller, data-controller, data-action, data-target was always so simple, that’s why I liked stimulus in the first place. And adding data-class, data-values to that would be much better way to go, for me the new syntax is step back.

5reactions
tpetrycommented, Dec 7, 2020

There is a good reason why the actions are different: All actions are run from left to right and you ca cancel execution at any point, this would not be possible if all controllers had their own action attribute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unifying action attributes · Issue #342 · hotwired/stimulus
After using the new unified target attributes introduced in #202 I asked myself why the same thing wasn't applied for the action attributes....
Read more >
Use unified attributes - Laravel Actions
Let's have a look at a concrete example using unified attributes. We'll implement an action that creates a new article and do so...
Read more >
Conversational Recommendation for Cold-Start Users
In this work, we consider the conversational recommendation for cold-start users, where a system can both ask the attributes from and recommend ...
Read more >
One Corps – One VMI: A Unifying Action Plan
These attributes are in high demand in our society and highly sought after in military, government, medical, legal, and private and public ...
Read more >
Conversational Recommendation for Cold-Start Users - arXiv
Seamlessly Unifying Attributes and Items: Conversational Recommendation for Cold-Start Users. Static recommendation methods like collaborative ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found