Skip to content

Commit 8035e4c

Browse files
sp1kerAkryum
andcommitted
fix: payload on replaying mutation, closes #773 , closes #792, closes #802 (#829)
* test(e2e): test mutation payload * Fix payload on replaying mutation * test(e2e): fix expect Co-authored-by: Guillaume Chau <[email protected]>
1 parent ada7f58 commit 8035e4c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cypress/integration/vuex-tab.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite('vuex tab', () => {
2323

2424
it('should filter state & getters', () => {
2525
cy.get('.right .search input').clear().type('cou')
26-
cy.get('.data-field').should('have.length', 1)
26+
cy.get('.data-field').should('have.length', 2)
2727
cy.get('.right .search input').clear().type('no value')
2828
cy.get('.data-field').should('have.length', 0)
2929
cy.get('.right .search input').clear()
@@ -59,6 +59,11 @@ suite('vuex tab', () => {
5959
expect(el.text()).to.include('type:"INCREMENT"')
6060
expect(el.text()).to.include('count:2')
6161
})
62+
cy.get('.data-field .key').contains('lastCountPayload').click()
63+
cy.get('.vuex-state-inspector').then(el => {
64+
expect(el.text()).to.include('a:1')
65+
expect(el.text()).to.include('b:Object')
66+
})
6267
cy.get('#target').iframe().then(({ get }) => {
6368
get('#counter p').contains('1')
6469
})

shells/dev/target/store.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default new Vuex.Store({
77
state: {
88
inited: 0,
99
count: 0,
10+
lastCountPayload: null,
1011
date: new Date(),
1112
set: new Set(),
1213
map: new Map(),
@@ -23,8 +24,14 @@ export default new Vuex.Store({
2324
},
2425
mutations: {
2526
TEST_INIT: state => state.inited++,
26-
INCREMENT: state => state.count++,
27-
DECREMENT: state => state.count--,
27+
INCREMENT: (state, payload) => {
28+
state.count++
29+
state.lastCountPayload = payload
30+
},
31+
DECREMENT: (state, payload) => {
32+
state.count--
33+
state.lastCountPayload = payload
34+
},
2835
UPDATE_DATE: state => {
2936
state.date = new Date()
3037
},

src/backend/vuex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function initVuexBackend (hook, bridge) {
146146
// Replay mutations
147147
for (let i = snapshot.index + 1; i <= index; i++) {
148148
const mutation = mutations[i]
149-
mutation.handlers.forEach(handler => handler(state, mutation.payload))
149+
mutation.handlers.forEach(handler => handler(mutation.payload))
150150
if (i !== index && i % SharedData.cacheVuexSnapshotsEvery === 0) {
151151
takeSnapshot(i, state)
152152
}

0 commit comments

Comments
 (0)