0.1.1 • Published 5 years ago

clean-redux-reducer v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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;
0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago