Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { createStore, combineReducers } = require('redux')
- const ActionType = {
- Inc: Symbol(),
- Dec: Symbol(),
- Pow: Symbol(),
- }
- const inc = () =>
- ({ type: ActionType.Inc })
- const dec = () =>
- ({ type: ActionType.Dec })
- const pow = n =>
- ({ type: ActionType.Pow, payload: n })
- const counter = (state = 0, action) => {
- switch (action.type) {
- case ActionType.Inc:
- return state + 1
- case ActionType.Dec:
- return state - 1
- case ActionType.Pow:
- return state ** action.payload
- default:
- return state
- }
- }
- const reducer = combineReducers({ counter })
- const store = createStore(reducer)
- store.dispatch(inc())
- store.dispatch(inc())
- store.dispatch(inc())
- store.dispatch(pow(3))
- console.log(store.getState())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement