Skip to content

Commit 4eb65f6

Browse files
committed
add state reset
1 parent fc1b720 commit 4eb65f6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/vuex/modules/category/actions.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import wordpressService from '../../../app.service'
2-
// import defaultState from './defaultState'
2+
import defaultState from './defaultState'
33

44
const getCategoryPromises = ({commit, state}, responseCategories, page) => {
55
var postPromises = []
@@ -31,17 +31,15 @@ const getCategory = ({commit, state, dispatch}, params) => {
3131
}
3232

3333
if (state) {
34-
// Object.assign(state, {}, ...defaultState)
34+
Object.assign(state, {}, defaultState)
3535
}
3636

3737
return new Promise((resolve, reject) => {
3838
wordpressService.getCategory(null, params.categorySlug, params.parentId).then((responseCategories) => {
3939
state.page = params.page
4040

41-
console.log('PASS')
4241
const postPromises = getCategoryPromises({commit, state}, responseCategories, params.page)
4342
Promise.all(postPromises).then(resolveCategories => {
44-
console.log('PASS')
4543
state.categories = resolveCategories
4644
resolve()
4745
})
@@ -64,6 +62,15 @@ const getCategoryPosts = ({commit, state}, params) => {
6462
}
6563

6664
const getPost = ({commit, state}, postSlug) => {
65+
if (state.single &&
66+
state.single.slug === postSlug) {
67+
return
68+
}
69+
70+
if (state) {
71+
Object.assign(state, {}, defaultState)
72+
}
73+
6774
return wordpressService.getPost(null, postSlug).then((post) => {
6875
commit('POST_UPDATED', post[0])
6976
}).catch(error => {

0 commit comments

Comments
 (0)