Skip to content

Commit

Permalink
Fix state after returning new state object from reduce.
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgenEvens committed Apr 26, 2016
1 parent e1bb8f6 commit 37b8e1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/store/AltStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AltStore {
if (model.reduce) {
handleDispatch(() => {
const value = model.reduce(this.state, payload)
if (value !== undefined) this.state = value
if (value !== undefined) this.state = model.state = value
}, payload)
if (!this.preventDefault) this.emitChange()
}
Expand Down
19 changes: 19 additions & 0 deletions test/functional-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,24 @@ export default {
assert(store.reduce(store.state).x === 0)
assert(store2.reduce(store2.state).x === 1)
},

'state returned from reduce is set correctly'() {
const alt = new Alt()
const actions = alt.generateActions('test');

const store = alt.createStore({
displayName: 'store',

state: { x: 0 },

reduce(state) {
assert(state === this.state, 'state matches this.state');
return { ...state };
}
})

actions.test();
actions.test();
},
}
}

0 comments on commit 37b8e1b

Please sign in to comment.