clean-redux-reducer
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Clean Redux Reducer

Create reducer without messy looking switch statements.

Installation

NPM:

npm install clean-redux-reducer

Yarn:

yarn add clean-redux-reducer

Usage

// reducer.js
import CreateReducer from 'clean-redux-reducer';
 
const initialState = {
    // ...
    tick: 0,
};
 
function onIncrement(state, action) {
    return {
        ...state,
        tick: state.tick + (action.incrementBy || 1),
    };
}
 
function onDecrement(state, action) {
    return {
        ...state,
        tick: state.tick - (action.incrementBy || 1),
    };
}
 
const reducer = CreateReducer
    .fromInitialState(initialState)
    .addCase('INCREMENT', onIncrement)
    .addCase('DECREMENT', onDecrement)
    .finalizeReducer();
 
export default reducer;

Readme

Keywords

Package Sidebar

Install

npm i clean-redux-reducer

Weekly Downloads

4

Version

0.1.1

License

MIT

Unpacked Size

6.14 kB

Total Files

15

Last publish

Collaborators

  • vivek.brohma