Skip to content

Instantly share code, notes, and snippets.

@eirikb eirikb/store.js
Created Jan 6, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.