Skip to content

Commit faac7ca

Browse files
ktsnyyx990803
authored andcommitted
move silent flag out of payload (vuejs#278)
1 parent 565ebe6 commit faac7ca

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class Store {
3030
this.dispatch = function boundDispatch (type, payload) {
3131
return dispatch.call(store, type, payload)
3232
}
33-
this.commit = function boundCommit (type, payload) {
34-
return commit.call(store, type, payload)
33+
this.commit = function boundCommit (type, payload, options) {
34+
return commit.call(store, type, payload, options)
3535
}
3636

3737
// strict mode
@@ -58,10 +58,11 @@ class Store {
5858
assert(false, `Use store.replaceState() to explicit replace store state.`)
5959
}
6060

61-
commit (type, payload) {
61+
commit (type, payload, options) {
6262
// check object-style commit
6363
let mutation
6464
if (isObject(type) && type.type) {
65+
options = payload
6566
payload = mutation = type
6667
type = type.type
6768
} else {
@@ -77,7 +78,7 @@ class Store {
7778
handler(payload)
7879
})
7980
})
80-
if (!payload || !payload.silent) {
81+
if (!options || !options.silent) {
8182
this._subscribers.forEach(sub => sub(mutation, this.state))
8283
}
8384
}

test/unit/test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,12 @@ describe('Vuex', () => {
623623
type: TEST,
624624
n: 2
625625
})
626+
store.commit(TEST, { n: 3 }, { silent: true })
626627
store.commit({
627628
type: TEST,
628-
silent: true,
629-
n: 3
629+
n: 4
630+
}, {
631+
silent: true
630632
})
631633
expect(mutations.length).toBe(2)
632634
expect(mutations[0].type).toBe(TEST)

0 commit comments

Comments
 (0)