Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function counter(state = 0, action) {
- switch (action.type) {
- case 'INCREMENT':
- return state + 1
- case 'DECREMENT':
- return state - 1
- default:
- return state
- }
- }
- //change to
- const counter = (state = 0, action) =>
- action.type === 'INCREMENT' ? state + 1
- : action.type === 'DECREMENT' ? state - 1
- : state
- // change to
- const switchcase = cases => defaultCase => key =>
- cases.hasOwnProperty(key) ? cases[key] : defaultCase
- const counter = (state = 0, action) =>
- switchcase({
- 'INCREMENT': state + 1,
- 'DECREMENT': state -1
- })(state)(action.type)
- // change to
- const switchcaseF = cases => defaultCase => key =>
- switchcase(cases)(defaultCase)(key)()
- const counter = (state = 0, action) =>
- switchcaseF({
- 'INCREMENT': () => state + 1,
- 'DECREMENT': () => state -1
- })(() => state)(action.type)
- // change to
- const executeIfFunction = f =>
- f instanceof Function ? f() : f
- const switchcaseF = cases => defaultCase => key =>
- executeIfFunction(switchcase(cases)(defaultCase)(key))
- const counter = (state = 0, action) =>
- switchcaseF({
- 'INCREMENT': () => state + 1,
- 'DECREMENT': () => state -1
- })(state)(action.type)
- const counter = (state = 0, action) =>
- switchcaseF({
- 'RESET': 0,
- 'INCREMENT': () => state + 1,
- 'DECREMENT': () => state -1
- })(state)(action.type)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement