Skip to content

Commit 3f4ea66

Browse files
committed
delete route functionality works
1 parent 932bc51 commit 3f4ea66

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/components/RouteDisplay.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export default {
3636
}
3737
},
3838
methods: {
39-
...mapActions(['addRouteToRouteMap']),
39+
...mapActions(['addRouteToRouteMap', 'setRoutes']),
4040
handleEnterKeyPress () {
4141
this.addRouteToRouteMap(this.newRoute)
4242
.then(() => {
4343
this.newRoute = ''
4444
})
45+
4546
.catch(err => console.log(err))
4647
}
4748
}

src/components/Routes.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ export default {
3838
...mapActions(['setActiveRoute', 'deleteRoute']),
3939
handleClick (route) {
4040
this.setActiveRoute(route)
41-
console.log(this.routes)
4241
},
4342
deleteSelectedRoute (route) {
44-
for (let key in this.routes) {
45-
if (key === route) {
46-
delete this.routes.route
47-
}
48-
}
4943
this.deleteRoute(route)
44+
this.setActiveRoute('')
5045
}
5146
}
5247
}

src/store/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ const actions = {
113113
[types.parentSelected]: ({ commit }, payload) => {
114114
commit(types.PARENT_SELECTED, payload)
115115
},
116-
[types.deleteRoute]: ({ commit }, payload) => {
117-
console.log('actionspayload:', payload)
116+
[types.deleteRoute]: ({ state, commit }, payload) => {
117+
console.log('stat in actions:', state)
118118
commit(types.DELETE_ROUTE, payload)
119119
}
120120
}

src/store/mutations.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const mutations = {
103103
...state.routes,
104104
[payload]: []
105105
}
106+
console.log('payload in add_route', payload)
106107
},
107108
// Changes the component map
108109
[types.ADD_ROUTE_TO_COMPONENT_MAP]: (state, payload) => {
@@ -128,6 +129,7 @@ const mutations = {
128129
state.activeComponent = payload
129130
},
130131
[types.SET_ROUTES]: (state, payload) => {
132+
console.log('setroutespayload:', payload)
131133
state.routes = Object.assign({}, payload)
132134
},
133135
// invoked when a component is deleted
@@ -181,10 +183,11 @@ const mutations = {
181183
state.parentSelected = payload
182184
},
183185
[types.DELETE_ROUTE]: (state, payload) => {
184-
console.log('payload in mutations', payload)
185-
const newState = delete state.routes[payload]
186-
console.log('new state', newState)
187-
state = newState
186+
const stateCopy = state
187+
delete stateCopy.routes[payload]
188+
delete stateCopy.componentMap[payload]
189+
state = stateCopy
190+
console.log('aftermutations state', state)
188191
}
189192
}
190193

0 commit comments

Comments
 (0)