Guest User

Untitled

a guest
Feb 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. class Increment {
  2. constructor (by) {
  3. this.by = by
  4. }
  5.  
  6. getNextState (count) {
  7. return count + this.by
  8. }
  9. }
  10.  
  11. class Decrement = {
  12. constructor (by) {
  13. this.by = by
  14. }
  15.  
  16. getNextState (count) {
  17. return count - this.by
  18. }
  19. }
  20.  
  21.  
  22. const reducer = (state = 0, action) => action.getNextState(state)
  23. const store = createStore(reducer)
  24.  
  25. plusTen = new Increment(10)
  26. minusFive = new Decrement(5)
  27.  
  28. store.dispatch(plusTen)
  29. store.dispatch(plusTen)
  30. store.dispatch(minusFive)
  31.  
  32. store.getState() // 15
Add Comment
Please, Sign In to add comment