File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ class Store {
85
85
}
86
86
87
87
dispatch ( type , payload ) {
88
+ // check object-style dispatch
89
+ if ( isObject ( type ) && type . type ) {
90
+ payload = type
91
+ type = type . type
92
+ }
88
93
const entry = this . _actions [ type ]
89
94
if ( ! entry ) {
90
95
console . error ( `[vuex] unknown action type: ${ type } ` )
Original file line number Diff line number Diff line change @@ -23,6 +23,24 @@ describe('Vuex', () => {
23
23
expect ( store . state . a ) . toBe ( 3 )
24
24
} )
25
25
26
+ it ( 'committing with object style' , ( ) => {
27
+ const store = new Vuex . Store ( {
28
+ state : {
29
+ a : 1
30
+ } ,
31
+ mutations : {
32
+ [ TEST ] ( state , payload ) {
33
+ state . a += payload . amount
34
+ }
35
+ }
36
+ } )
37
+ store . commit ( {
38
+ type : TEST ,
39
+ amount : 2
40
+ } )
41
+ expect ( store . state . a ) . toBe ( 3 )
42
+ } )
43
+
26
44
it ( 'dispatching actions, sync' , ( ) => {
27
45
const store = new Vuex . Store ( {
28
46
state : {
@@ -43,6 +61,29 @@ describe('Vuex', () => {
43
61
expect ( store . state . a ) . toBe ( 3 )
44
62
} )
45
63
64
+ it ( 'dispatching with object style' , ( ) => {
65
+ const store = new Vuex . Store ( {
66
+ state : {
67
+ a : 1
68
+ } ,
69
+ mutations : {
70
+ [ TEST ] ( state , n ) {
71
+ state . a += n
72
+ }
73
+ } ,
74
+ actions : {
75
+ [ TEST ] ( { commit } , payload ) {
76
+ commit ( TEST , payload . amount )
77
+ }
78
+ }
79
+ } )
80
+ store . dispatch ( {
81
+ type : TEST ,
82
+ amount : 2
83
+ } )
84
+ expect ( store . state . a ) . toBe ( 3 )
85
+ } )
86
+
46
87
it ( 'dispatching actions, with returned Promise' , done => {
47
88
const store = new Vuex . Store ( {
48
89
state : {
You can’t perform that action at this time.
0 commit comments