Skip to content

Instantly share code, notes, and snippets.

@collin
Last active February 13, 2018 21:53
Show Gist options
  • Save collin/7249a9dce1a76da9df692cd1b4f08488 to your computer and use it in GitHub Desktop.
Save collin/7249a9dce1a76da9df692cd1b4f08488 to your computer and use it in GitHub Desktop.
class Increment {
constructor (by) {
this.by = by
}
getNextState (count) {
return count + this.by
}
}
class Decrement = {
constructor (by) {
this.by = by
}
getNextState (count) {
return count - this.by
}
}
const reducer = (state = 0, action) => action.getNextState(state)
const store = createStore(reducer)
plusTen = new Increment(10)
minusFive = new Decrement(5)
store.dispatch(plusTen)
store.dispatch(plusTen)
store.dispatch(minusFive)
store.getState() // 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment