1
1
import wordpressService from '../../../app.service'
2
- // import defaultState from './defaultState'
2
+ import defaultState from './defaultState'
3
3
4
4
const getCategoryPromises = ( { commit, state} , responseCategories , page ) => {
5
5
var postPromises = [ ]
@@ -31,17 +31,15 @@ const getCategory = ({commit, state, dispatch}, params) => {
31
31
}
32
32
33
33
if ( state ) {
34
- // Object.assign(state, {}, ... defaultState)
34
+ Object . assign ( state , { } , defaultState )
35
35
}
36
36
37
37
return new Promise ( ( resolve , reject ) => {
38
38
wordpressService . getCategory ( null , params . categorySlug , params . parentId ) . then ( ( responseCategories ) => {
39
39
state . page = params . page
40
40
41
- console . log ( 'PASS' )
42
41
const postPromises = getCategoryPromises ( { commit, state} , responseCategories , params . page )
43
42
Promise . all ( postPromises ) . then ( resolveCategories => {
44
- console . log ( 'PASS' )
45
43
state . categories = resolveCategories
46
44
resolve ( )
47
45
} )
@@ -64,6 +62,15 @@ const getCategoryPosts = ({commit, state}, params) => {
64
62
}
65
63
66
64
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
+
67
74
return wordpressService . getPost ( null , postSlug ) . then ( ( post ) => {
68
75
commit ( 'POST_UPDATED' , post [ 0 ] )
69
76
} ) . catch ( error => {
0 commit comments