1
1
import Vue from 'vue' ;
2
- import { FETCH_POST , POST_DELETE , POST_EDIT , POST_EDIT_TAGS , POST_EDIT_TOPIC , POST_RESET_STATE } from '../actions.type' ;
3
- import { SET_POST , SET_TAGS , SET_TOPIC , RESET_STATE } from '../mutations.type' ;
4
2
5
3
const initialState = {
6
4
id : '' ,
@@ -23,18 +21,18 @@ const initialState = {
23
21
const state = { ...initialState } ;
24
22
25
23
const actions = {
26
- async [ FETCH_POST ] ( context , id ) {
24
+ async fetchPost ( context , id ) {
27
25
this . request ( )
28
26
. get ( '/api/posts/' + id )
29
27
. then ( ( response ) => {
30
- context . commit ( SET_POST , response . data . post ) ;
28
+ context . commit ( ' SET_POST' , response . data . post ) ;
31
29
} )
32
30
. catch ( ( errors ) => {
33
31
console . log ( errors ) ;
34
32
} ) ;
35
33
} ,
36
- // eslint-disable-next-line no-unused-vars
37
- [ POST_EDIT ] ( { context , id, payload } ) {
34
+
35
+ updatePost ( { id, payload } ) {
38
36
this . request ( )
39
37
. post ( '/api/posts/' + id , payload )
40
38
. then ( ( response ) => {
@@ -44,14 +42,16 @@ const actions = {
44
42
console . log ( errors ) ;
45
43
} ) ;
46
44
} ,
47
- [ POST_EDIT_TAGS ] ( { context, tags } ) {
48
- context . commit ( SET_TAGS , tags ) ;
45
+
46
+ setTags ( { context, tags } ) {
47
+ context . commit ( 'SET_TAGS' , tags ) ;
49
48
} ,
50
- [ POST_EDIT_TOPIC ] ( { context, topic } ) {
51
- context . commit ( SET_TOPIC , topic ) ;
49
+
50
+ setTopic ( { context, topic } ) {
51
+ context . commit ( 'SET_TOPIC' , topic ) ;
52
52
} ,
53
- // eslint-disable-next-line no-unused-vars
54
- [ POST_DELETE ] ( { context , id } ) {
53
+
54
+ deletePost ( { id } ) {
55
55
this . request ( )
56
56
. delete ( '/api/posts/' + id , id )
57
57
. then ( ( response ) => {
@@ -61,22 +61,26 @@ const actions = {
61
61
console . log ( errors ) ;
62
62
} ) ;
63
63
} ,
64
- [ POST_RESET_STATE ] ( { commit } ) {
65
- commit ( RESET_STATE ) ;
64
+
65
+ resetPost ( { commit } ) {
66
+ commit ( 'RESET_STATE' ) ;
66
67
} ,
67
68
} ;
68
69
69
70
const mutations = {
70
- [ SET_POST ] ( state , post ) {
71
+ SET_POST ( state , post ) {
71
72
state = post ;
72
73
} ,
73
- [ SET_TAGS ] ( state , tags ) {
74
+
75
+ SET_TAGS ( state , tags ) {
74
76
state . tags = tags ;
75
77
} ,
76
- [ SET_TOPIC ] ( state , topic ) {
78
+
79
+ SET_TOPIC ( state , topic ) {
77
80
state . topic = topic ;
78
81
} ,
79
- [ RESET_STATE ] ( ) {
82
+
83
+ RESET_STATE ( ) {
80
84
for ( let f in state ) {
81
85
Vue . set ( state , f , initialState [ f ] ) ;
82
86
}
0 commit comments