Browse Source

object style commit should record mutation in the same format

Evan You 8 years ago
parent
commit
4cb73014c0
2 changed files with 4 additions and 6 deletions
  1. 2 4
      src/index.js
  2. 2 2
      test/unit/test.js

+ 2 - 4
src/index.js

@@ -62,14 +62,12 @@ class Store {
 
   commit (type, payload, options) {
     // check object-style commit
-    let mutation
     if (isObject(type) && type.type) {
       options = payload
-      payload = mutation = type
+      payload = type
       type = type.type
-    } else {
-      mutation = { type, payload }
     }
+    const mutation = { type, payload }
     const entry = this._mutations[type]
     if (!entry) {
       console.error(`[vuex] unknown mutation type: ${type}`)

+ 2 - 2
test/unit/test.js

@@ -674,8 +674,8 @@ describe('Vuex', () => {
     expect(mutations.length).toBe(2)
     expect(mutations[0].type).toBe(TEST)
     expect(mutations[1].type).toBe(TEST)
-    expect(mutations[0].payload.n).toBe(1) // normal dispatch
-    expect(mutations[1].n).toBe(2) // object dispatch
+    expect(mutations[0].payload.n).toBe(1) // normal commit
+    expect(mutations[1].payload.n).toBe(2) // object commit
   })
 
   it('strict mode: warn mutations outside of handlers', function () {