Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment