浏览代码

move silent flag out of payload (#278)

katashin 8 年之前
父节点
当前提交
faac7ca827
共有 2 个文件被更改,包括 9 次插入6 次删除
  1. 5 4
      src/index.js
  2. 4 2
      test/unit/test.js

+ 5 - 4
src/index.js

@@ -30,8 +30,8 @@ class Store {
     this.dispatch = function boundDispatch (type, payload) {
     this.dispatch = function boundDispatch (type, payload) {
       return dispatch.call(store, type, payload)
       return dispatch.call(store, type, payload)
     }
     }
-    this.commit = function boundCommit (type, payload) {
-      return commit.call(store, type, payload)
+    this.commit = function boundCommit (type, payload, options) {
+      return commit.call(store, type, payload, options)
     }
     }
 
 
     // strict mode
     // strict mode
@@ -58,10 +58,11 @@ class Store {
     assert(false, `Use store.replaceState() to explicit replace store state.`)
     assert(false, `Use store.replaceState() to explicit replace store state.`)
   }
   }
 
 
-  commit (type, payload) {
+  commit (type, payload, options) {
     // check object-style commit
     // check object-style commit
     let mutation
     let mutation
     if (isObject(type) && type.type) {
     if (isObject(type) && type.type) {
+      options = payload
       payload = mutation = type
       payload = mutation = type
       type = type.type
       type = type.type
     } else {
     } else {
@@ -77,7 +78,7 @@ class Store {
         handler(payload)
         handler(payload)
       })
       })
     })
     })
-    if (!payload || !payload.silent) {
+    if (!options || !options.silent) {
       this._subscribers.forEach(sub => sub(mutation, this.state))
       this._subscribers.forEach(sub => sub(mutation, this.state))
     }
     }
   }
   }

+ 4 - 2
test/unit/test.js

@@ -623,10 +623,12 @@ describe('Vuex', () => {
       type: TEST,
       type: TEST,
       n: 2
       n: 2
     })
     })
+    store.commit(TEST, { n: 3 }, { silent: true })
     store.commit({
     store.commit({
       type: TEST,
       type: TEST,
-      silent: true,
-      n: 3
+      n: 4
+    }, {
+      silent: true
     })
     })
     expect(mutations.length).toBe(2)
     expect(mutations.length).toBe(2)
     expect(mutations[0].type).toBe(TEST)
     expect(mutations[0].type).toBe(TEST)