|
|
@ -15,10 +15,35 @@ export default new Vuex.Store({
|
|
|
|
getters: {
|
|
|
|
getters: {
|
|
|
|
countLinks: state => { return state.links.length }
|
|
|
|
countLinks: state => { return state.links.length }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Used when we want to change state data
|
|
|
|
|
|
|
|
// Should be used for synchronous functions
|
|
|
|
mutations: {
|
|
|
|
mutations: {
|
|
|
|
|
|
|
|
// By convention mutators are all caps
|
|
|
|
|
|
|
|
ADD_LINK: (state, link) => {
|
|
|
|
|
|
|
|
state.links.push(link)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
REMOVE_LINK: (state, link) => {
|
|
|
|
|
|
|
|
state.links.splice(link, 1)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
REMOVE_ALL: (state) => {
|
|
|
|
|
|
|
|
state.links = []
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Actions are for async functions
|
|
|
|
actions: {
|
|
|
|
actions: {
|
|
|
|
|
|
|
|
// the context provides you the same methods and instances as the store instance, and then we pass in a payload
|
|
|
|
|
|
|
|
// Here we are using actions to asynchronously call a mutation function
|
|
|
|
|
|
|
|
removeLink(context, link) {
|
|
|
|
|
|
|
|
context.commit("REMOVE_LINK", link)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// Pretty sure we are just using object destructuring here
|
|
|
|
|
|
|
|
removeAll({commit}) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
setTimeout(()=> {
|
|
|
|
|
|
|
|
commit('REMOVE_ALL')
|
|
|
|
|
|
|
|
resolve()
|
|
|
|
|
|
|
|
}, 1500) // 1.5 seconds
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|