I'm studying Vue (2.x) + Vuex for some time now and one pattern that I've always seen around is the use of Mutation Types.
To me it is just unnecessary code to add complexity to a project with more files, maybe I didn't have enough experience with it to understand the real usage, therefore this question.
According to the Mutation Types docs it states that it is entirely optional and you should use if you like it also states that "This allows the code to take advantage of tooling like linters, and putting all constants in a single file allows your collaborators to get an at-a-glance view of what mutations are possible in the entire application" and it stop there.
And Also:
Whether to use constants is largely a preference - it can be helpful in large projects with many developers, but it's totally optional if you don't like them
What I would like to understand is what exactly are the advantages here both for tooling and in the so called large projects. Some examples of it would be really nice.
Even the sample code in the docs is silly enough to discourage it:
//mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION';
// store.js
import Vuex from 'vuex'
import { SOME_MUTATION } from './mutation-types'
const store = new Vuex.Store({
state: { ... },
mutations: {
// we can use the ES2015 computed property name feature
// to use a constant as the function name
[SOME_MUTATION] (state) {
// mutate state
}
}
})
Instead of just:
// store.js
import Vuex from 'vuex'
const store = new Vuex.Store({
state: { ... },
mutations: {
//To me this is already clear enough to understand the purpose
//of the mutation and to see AT-A-GLANCE what all mutations in the
//Application are
someMutation (state) {
// mutate state
}
}
})
Specially because modern IDEs (Eclipse, Npp does that) already have the grouping features which means that you will se it all at-a-glance like:
...
mutations: {
+ someMutation1
+ someMutation2
+ someMutation3
+ someMutation4
+ someMutation5
+ someMutation6
+ someMutation7
}
...
Without seen a practical usage of such a thing I think this is like the 5 Monkeys Experiment