Last active
March 23, 2020 20:59
-
-
Save robertoandres24/9ac5253bdd3215e20bc666117739bd73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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