Skip to content

Commit

Permalink
Fix regression for not setting state if reduce returns undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Oct 21, 2015
1 parent 9dd8e09 commit cebd8e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/alt/store/AltStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class AltStore {

if (model.reduce) {
handleDispatch(() => {
this.state = model.reduce(this.state, payload)
const value = model.reduce(this.state, payload)
if (value !== undefined) this.state = value
}, payload)
if (!this.preventDefault) this.emitChange()
}
Expand Down
2 changes: 2 additions & 0 deletions test/functional-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ export default {
state: { x: 0 },

reduce(state) {
if (state.x >= 3) return
return { x: state.x + 1 }
}
})

actions.fire()
actions.fire()
actions.fire()
actions.fire()

assert(store.getState().x === 3, 'counter was incremented')
},
Expand Down

0 comments on commit cebd8e8

Please sign in to comment.