Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asn007/reducio
Functional reducers for everybody
https://github.com/asn007/reducio
functional-programming reducer-composition reducer-creation reducer-enhancer reducers redux
Last synced: 10 days ago
JSON representation
Functional reducers for everybody
- Host: GitHub
- URL: https://github.com/asn007/reducio
- Owner: asn007
- Created: 2017-04-23T09:10:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-23T06:18:41.000Z (over 7 years ago)
- Last Synced: 2024-11-30T10:04:22.746Z (about 1 month ago)
- Topics: functional-programming, reducer-composition, reducer-creation, reducer-enhancer, reducers, redux
- Language: JavaScript
- Size: 50.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
reducio
=======A library for getting rid of switch-case boilerplate in redux reducers
## How does it help me
Ever noticed how your reducers mostly do repetitive tasks, like updating fetched data, toggling something, stuff like this? I bet you did, and __reducio__ may help you get rid of it. How? Reducio allows you to create a reducer creator - a function, which takes some parameters and returns a fully featured reducer, which you can later plug where your architecture allows you to. Reducio also provides you with utilities to compose reducers (by reducer I mean a function which takes two parameters, old state and action and returns new state based on action) into one combined reducer function.Let's see how it works in [Usage](#usage)
## Installation
`npm install reducio`## Usage
```js
import { createReducer } from 'reducio';
import { filter } from 'lodash';const basicReducer = createReducer(
// this reducer will only get invoked when action.type equals SOMETHING
(action) => action.type === 'SOMETHING',
// this reducer sets the `key` property of state to action.payload. Yes, just like your reducers
(state, action) => Object.assign({}, state, { key: action.payload })
// the third argument is the action modifier
// it accepts an action and the result of that function is 'Object.assign'ed
// to a new action, which initially has the props of an old action
// Resulting action is then passed to a 2nd argument of createReducer
(action) => ({ payload: action.data.filter(item => item.hasThisVariable))}
)
```