Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aganglada/reswitcher
🍭 Functional switch case for redux reducers
https://github.com/aganglada/reswitcher
functional-programming javascript reducer redux switch-case
Last synced: 2 days ago
JSON representation
🍭 Functional switch case for redux reducers
- Host: GitHub
- URL: https://github.com/aganglada/reswitcher
- Owner: aganglada
- Created: 2017-02-24T14:51:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T15:29:04.000Z (over 7 years ago)
- Last Synced: 2024-04-27T03:00:46.362Z (7 months ago)
- Topics: functional-programming, javascript, reducer, redux, switch-case
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🍭 reswitcher
### Functional switch case for redux reducers.
Switch cases are slow, or that's what they said.
They also say, it doesn't fit in the functional paradigm.
It's also not Immutable.
It uses `break`, which is anti-functional.
...bla, bla, bla...
This is a super fast and lightweight (3 lines of code) recomposition of switch statement for functional code, which makes this statement easy and fast to read.
### Usage
Install it as dependency:
`npm i reswitcher --save`
or
`yarn add reswitcher`
And now...! Feel free to use it as your reducer.
```javascript
import reswitcher from 'reswitcher';const counter = (state = 0, action) =>
reswitcher({
'RESET': 0,
'INCREMENT': () => state + 1,
'DECREMENT': () => state -1
})(state)(action.type)
```