Skip to content

Instantly share code, notes, and snippets.

@Ntropish
Created April 2, 2017 16:07
Show Gist options
  • Save Ntropish/8efe3ec28b50517c24508a508d8874b5 to your computer and use it in GitHub Desktop.
Save Ntropish/8efe3ec28b50517c24508a508d8874b5 to your computer and use it in GitHub Desktop.
const mutations = {
SET_SELECTED(state, newSelectedThing) {
state.item = newSelectedThing
Vue.set(state, 'item', newSelectedThing)
},
UPDATE_SELECTED(state, {type, name, value}) {
if (!state.item) throw new Error(`No item selected while trying to update`)
if (!state.item[type]) throw new Error(`Missing property type: ${type}`)
// If no name given update the type, else update type.name
let key = name || type
let object = state.item
if (name) object = object[type]
Vue.set(object, key, value)
},
SELECT_PROPERTY(state, property) {
Vue.set(state, 'property', property)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment