Vuex: do we need mutation_types?
Do we get any benefit from mutation types vs simply using strings for mutation names? Here are some reasons that plain strings are preferable to me:
- Vuex warns if you commit an action that doesn't exist
This isn't quite as good/useful as the static analysis, but means we can catch this in tests. And we could probably statically analyze check that any commit() has a valid mutation as the first argument
- We don't use types for
dispatch. These two lines that should almost identical look very different
dispatch('doThatThing');
commit(types.DO_THAT_THING);
-
Relatedly, why are we using
UPPER_SNAKE_CASE? Makes sense for the mutation_types file, since they are constants. But in the actual mutations file (i.e. the thing that is actual code that we use) we haveFUNCTION_NAMES_FORMATTED_LIKE_THIS -
Save $$$ on keystrokes. Never type
types.again!
I also don't really like computed keys in objects. Compare:
import * as types from './mutation_types';
export default {
[types.REQUEST_METRICS_DATA](state) {
return 🤮;
}
}
export default {
REQUEST_METRICS_DATA(state) {
return 😎;
}
}
- Benefits for JetBrains editor users
observation from @winh
at least it jumps to mutations if you click on the strings (which it does not when using mutation types)