Skip to content

Instantly share code, notes, and snippets.

@robertoandres24
Last active March 23, 2020 20:59
Show Gist options
  • Save robertoandres24/9ac5253bdd3215e20bc666117739bd73 to your computer and use it in GitHub Desktop.
Save robertoandres24/9ac5253bdd3215e20bc666117739bd73 to your computer and use it in GitHub Desktop.
const getDefaultState = () => {
return {
items: [],
status: 'empty'
}
}
// initial state
const state = getDefaultState()
const actions = {
resetCartState ({ commit }) {
commit('resetState')
},
addItem ({ state, commit }, item) { /* ... */ }
}
const mutations = {
resetState (state) {
// Merge rather than replace so we don't lose observers
// https://github.com/vuejs/vuex/issues/1118
Object.assign(state, getDefaultState())
}
}
export default {
state,
getters: {},
actions,
mutations
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment