Skip to content

Instantly share code, notes, and snippets.



Created Jan 6, 2019
What would you like to do?
Auto Vuex mutations
import Vue from 'vue';
import Vuex from 'vuex';
function teenageAutoMutateTurtles(...props) {
return props.reduce((o, p) => (o[`set${p[0].toUpperCase()}${p.slice(1)}`] = (s, v) => s[p] = v) && o, {});
export default new Vuex.Store({
state: {
herp: '',
derp: ''
mutations: {
...teenageAutoMutateTurtles('herp', 'derp')
actions: {
example({commit}) {
commit('setHerp', 'Herpa!');
commit('setDerp', 'Derpa!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.