https://github.com/maxim-kolesnikov/redux-ramda-reducer
One of the various of create reducer with Ramda & Redux
https://github.com/maxim-kolesnikov/redux-ramda-reducer
ramda reducer reducer-redux redux
Last synced: 8 months ago
JSON representation
One of the various of create reducer with Ramda & Redux
- Host: GitHub
- URL: https://github.com/maxim-kolesnikov/redux-ramda-reducer
- Owner: maxim-kolesnikov
- License: mit
- Created: 2018-10-21T12:38:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-20T17:18:37.000Z (almost 7 years ago)
- Last Synced: 2025-02-10T23:29:55.298Z (8 months ago)
- Topics: ramda, reducer, reducer-redux, redux
- Language: JavaScript
- Homepage:
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# redux-ramda-reducer
[](https://badge.fury.io/js/redux-ramda-reducer)
[](https://npmcharts.com/compare/redux-ramda-reducer?minimal=true)
[](https://travis-ci.org/maxim-kolesnikov/redux-ramda-reducer)
[](https://david-dm.org/maxim-kolesnikov/redux-ramda-reducer)
[](https://github.com/maxim-kolesnikov/redux-ramda-reducer/blob/master/LICENSE.md)Simple `createReducer` in functional style for Ramda library.
## Installation
```bash
npm install redux-ramda-reducer
```## Reducer with redux library
```javascript
export default (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
```## Reducer with redux-ramda-reducer
Without STATE in handler arguments
```javascript
import * as R from 'ramda';
import { createReducer } from 'redux-ramda-reducer';
import { COUNTER_ACTIONS } from './constants';const INITIAL_STATE = {
value: 1,
};const incrementHandler = () => R.evolve({ value: R.inc });
const decrementHandler = () => R.evolve({ value: R.dec });
const setValueHandler = ({ value }) => R.assoc('value', value);
const HANDLERS = {
[COUNTER_ACTIONS.SET_VALUE]: setValueHandler,
[COUNTER_ACTIONS.INCREMENT]: incrementHandler,
[COUNTER_ACTIONS.DECREMENT]: decrementHandler,
}export default createReducer(INITIAL_STATE, HANDLERS);
```If you need STATE in handler:
```javascript
...const setSameValueHandler = () => (state) => R.assoc('value', state.value)(state);
const HANDLERS = {
[COUNTER_ACTIONS.SET_SAME_VALUE]: setSameValueHandler,
}export default createReducer(INITIAL_STATE, HANDLERS);
```### License
This module is [MIT licensed](./LICENSE.md).