-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Proposal: change mutation name style #1733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
We're actually inconsistent about this in our current examples - sometimes using UPPER_CASE, sometimes camelCase. We're discussing it internally and right now, are leaning towards consolidating on camelCase for mutation names, which is more generally the standard for function names in JavaScript. |
@chrisvfritz awesome, very glad to hear! -- should I keep this PR open then? :) |
Up to you, if you want to get contribution credit. 🙂 Once we have a clear consensus, I'll be going through and updating all our examples, in all repos. Here are the specific conventions we're leaning towards though:
|
@chrisvfritz I'll insist then on my proposal for past-tense mutations then. I think having both I'll leave the PR open if this suggestion stands a chance of consideration. |
@galvez I think the chances are relatively low, but it's not impossible at this point. Personally, if I see something called Also more generally in JavaScript, imperative-style verbs are almost universally used for called functions, so we'd be breaking a big convention of the larger ecosystem. Does that make sense? Also, I'd love to hear more about the confusions that the past-tense convention resolved for you. I'm wondering if there may be a 3rd option or additional convention that could resolve all our concerns. 🙂 |
That's a valid point. Adopting past tense for mutations also required creating the notion that mutations are really special functions. Since their purpose is to provoke actual state change, past tense simply created a way to identify them by interpreting them in a what happened after this ran narrative. It made sense enough to me, but I understand it may confuse some. Other ideas that come to mind would involve even more complex and redundant semantics. |
One small thing: the past-tense narrative also encourages data wrangling logic to happen outside the mutation, keeping them pure. |
That makes sense. 🙂 It's what I was attempting to achieve with the suggestion to describe the specific nature of the mutation, but it sounds like it's not quite sufficient to avoid confusion. 😅 Do you think it would help to define an exhaustive list of verbs to recommend that all mutations begin with? Browsing through my own apps, I believe every mutation could begin with one of the verbs below:
As a bonus, this strategy would also help people limit the scope of their mutations, keeping all business logic in actions where it belongs. In the apps I have access to, I did notice some cases where none of the above verbs were appropriate - but in every case, the mutation was doing much more than it should have. And as another bonus, this convention could speed up development with snippets and we might even be able to automate its enforcement in eslint-plugin-vue! 😻 (@michalsnik, do you think that might be feasible?) What are your thoughts? In the teams you've worked with, do you think this would clarify the responsibilities of mutations for and reduce the cognitive overhead of naming them? |
@chrisvfritz No reason we can't do both, I guess? How about we add a paragraph as follow to the docs: |
I added it to the bottom of |
I like this idea @chrisvfritz ! However in terms of eslint rule that might check it - I'm not so sure. Depending on a person or team, structure of the vuex module might differ drastically. Some might keep it in I think that this kind of rule might be feasible but only per-project case as a team's internal agreement, so as from our plugin's perspective I must say: |
Maybe we should move this to https://github.com/vuejs/vuex? 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http-push
The original text uses
REMOVE_TODO
(uppercase constant style, reminiscent of React and Redux) as mutation name in an example. I propose that it changes totodoRemoved
, a style that will match the rest of the code, while maintaining a clear distinction from related actions.