Skip to content

Commit

Permalink
also support object format dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 8, 2016
1 parent 0c9994f commit f07adca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit f07adca

Please sign in to comment.