reducer-in-action
v0.1.1
Published
A clean way to manage actions and reducers
Downloads
3
Readme
reducer-in-action
A clean way to manage actions and reducers, it's works !
Install
yarn add reducer-in-action
npm install reducer-in-action --save
Usage
In your actions.js:
import actionTypes from '../actionTypes';
export function increment() {
return {
type: actionTypes.INCREMENT,
initialState: {
counter: 1
},
reducer: (state, action) => ({
[actionTypes.INCREMENT]: {
...state,
count: state.count + 1
}
})
};
}
export function decrement() {
return {
type: actionTypes.DECREMENT,
reducer: (state, action) => ({
[actionTypes.DECREMENT]: {
...state,
count: state.count - 1
}
})
};
}
export const initialState = {
count: 1
};
In your reducers file:
import { combineReducers } from 'redux';
import ReducerInAction from 'reducer-in-action';
import * as reducers from '../actions.reducers';
const rootReducer = combineReducers({
counter: ReducerInAction(reducers)
});
export default rootReducer;