File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,11 @@ class Store {
77
77
*/
78
78
79
79
dispatch ( type , ...payload ) {
80
+ // compatibility for object actions, e.g. FSA
81
+ if ( typeof type === 'object' && type . type && arguments . length === 1 ) {
82
+ payload = [ type ]
83
+ type = type . type
84
+ }
80
85
const mutation = this . _mutations [ type ]
81
86
const prevSnapshot = this . _prevSnapshot
82
87
const state = this . state
Original file line number Diff line number Diff line change @@ -386,4 +386,22 @@ describe('Vuex', () => {
386
386
done ( )
387
387
} )
388
388
} )
389
+
390
+ it ( 'object-format mutations' , ( ) => {
391
+ const store = new Vuex . Store ( {
392
+ state : {
393
+ a : 1
394
+ } ,
395
+ mutations : {
396
+ [ TEST ] ( state , action ) {
397
+ state . a += action . by
398
+ }
399
+ }
400
+ } )
401
+ store . dispatch ( {
402
+ type : TEST ,
403
+ by : 2
404
+ } )
405
+ expect ( store . state . a ) . to . equal ( 3 )
406
+ } )
389
407
} )
You can’t perform that action at this time.
0 commit comments