Last active
February 13, 2018 21:53
-
-
Save collin/7249a9dce1a76da9df692cd1b4f08488 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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