diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue
index 21fb796..196f86c 100644
--- a/src/components/HelloWorld.vue
+++ b/src/components/HelloWorld.vue
@@ -2,24 +2,50 @@
@@ -36,4 +52,15 @@ li {
a {
color: #42b983;
}
+
+button {
+ padding: 10px;
+ margin-top: 30px;
+ width: 100%;
+ background: none;
+ border: 1px solid lightgrey;
+ outline: 0;
+ cursor: pointer;
+}
+
diff --git a/src/store.js b/src/store.js
index cc10ea9..e55e56e 100644
--- a/src/store.js
+++ b/src/store.js
@@ -15,10 +15,35 @@ export default new Vuex.Store({
getters: {
countLinks: state => { return state.links.length }
},
+ // Used when we want to change state data
+ // Should be used for synchronous functions
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: {
-
+ // 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
+ })
+ }
}
})
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 02d9ab5..a0dc7e7 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -1,6 +1,6 @@
-
+