0.1.1 • Published 6 years ago

reducer-in-action v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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;