Skip to content

Instantly share code, notes, and snippets.

@eirikb
Created January 6, 2019 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/b45bf87c885044698fde9218fdcce475 to your computer and use it in GitHub Desktop.
Save eirikb/b45bf87c885044698fde9218fdcce475 to your computer and use it in GitHub Desktop.
Auto Vuex mutations
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(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