diff --git a/src/index.js b/src/index.js index d2fec63db..a9a9c2992 100644 --- a/src/index.js +++ b/src/index.js @@ -77,6 +77,11 @@ class Store { */ dispatch (type, ...payload) { + // compatibility for object actions, e.g. FSA + if (typeof type === 'object' && type.type && arguments.length === 1) { + payload = [type] + type = type.type + } const mutation = this._mutations[type] const prevSnapshot = this._prevSnapshot const state = this.state diff --git a/test/unit/test.js b/test/unit/test.js index 15345b6cc..e5132e401 100644 --- a/test/unit/test.js +++ b/test/unit/test.js @@ -386,4 +386,22 @@ describe('Vuex', () => { done() }) }) + + it('object-format mutations', () => { + const store = new Vuex.Store({ + state: { + a: 1 + }, + mutations: { + [TEST] (state, action) { + state.a += action.by + } + } + }) + store.dispatch({ + type: TEST, + by: 2 + }) + expect(store.state.a).to.equal(3) + }) })