Skip to content

Commit

Permalink
fix: payload on replaying mutation, closes #773 , closes #792, closes #…
Browse files Browse the repository at this point in the history
…802 (#829)

* test(e2e): test mutation payload

* Fix payload on replaying mutation

* test(e2e): fix expect


Co-authored-by: Guillaume Chau <[email protected]>
  • Loading branch information
sp1ker and Akryum committed Jan 25, 2019
1 parent ada7f58 commit 8035e4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cypress/integration/vuex-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite('vuex tab', () => {

it('should filter state & getters', () => {
cy.get('.right .search input').clear().type('cou')
cy.get('.data-field').should('have.length', 1)
cy.get('.data-field').should('have.length', 2)
cy.get('.right .search input').clear().type('no value')
cy.get('.data-field').should('have.length', 0)
cy.get('.right .search input').clear()
Expand Down Expand Up @@ -59,6 +59,11 @@ suite('vuex tab', () => {
expect(el.text()).to.include('type:"INCREMENT"')
expect(el.text()).to.include('count:2')
})
cy.get('.data-field .key').contains('lastCountPayload').click()
cy.get('.vuex-state-inspector').then(el => {
expect(el.text()).to.include('a:1')
expect(el.text()).to.include('b:Object')
})
cy.get('#target').iframe().then(({ get }) => {
get('#counter p').contains('1')
})
Expand Down
11 changes: 9 additions & 2 deletions shells/dev/target/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default new Vuex.Store({
state: {
inited: 0,
count: 0,
lastCountPayload: null,
date: new Date(),
set: new Set(),
map: new Map(),
Expand All @@ -23,8 +24,14 @@ export default new Vuex.Store({
},
mutations: {
TEST_INIT: state => state.inited++,
INCREMENT: state => state.count++,
DECREMENT: state => state.count--,
INCREMENT: (state, payload) => {
state.count++
state.lastCountPayload = payload
},
DECREMENT: (state, payload) => {
state.count--
state.lastCountPayload = payload
},
UPDATE_DATE: state => {
state.date = new Date()
},
Expand Down
2 changes: 1 addition & 1 deletion src/backend/vuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function initVuexBackend (hook, bridge) {
// Replay mutations
for (let i = snapshot.index + 1; i <= index; i++) {
const mutation = mutations[i]
mutation.handlers.forEach(handler => handler(state, mutation.payload))
mutation.handlers.forEach(handler => handler(mutation.payload))
if (i !== index && i % SharedData.cacheVuexSnapshotsEvery === 0) {
takeSnapshot(i, state)
}
Expand Down

0 comments on commit 8035e4c

Please sign in to comment.