Skip to content

Commit f07adca

Browse files
committed
also support object format dispatch
1 parent 0c9994f commit f07adca

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class Store {
7777
*/
7878

7979
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+
}
8085
const mutation = this._mutations[type]
8186
const prevSnapshot = this._prevSnapshot
8287
const state = this.state

test/unit/test.js

+18
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,22 @@ describe('Vuex', () => {
386386
done()
387387
})
388388
})
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+
})
389407
})

0 commit comments

Comments
 (0)