redux-ramda-reducer
v1.0.0
Published
One of the various of create reducer with Ramda & Redux
Downloads
1
Maintainers
Readme
redux-ramda-reducer
Simple createReducer
in functional style for Ramda library.
Installation
npm install redux-ramda-reducer
Reducer with redux library
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
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:
...
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.