Created
January 6, 2019 11:30
-
-
Save eirikb/b45bf87c885044698fde9218fdcce475 to your computer and use it in GitHub Desktop.
Auto Vuex mutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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