1.0.0 • Published 6 years ago

@zcorky/rematch v1.0.0

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

rematch

NPM version Coverage Status Dependencies Build Status license issues

Stop switch, love rematch with Redux.

Install

$ npm install @zcorky/rematch

Usage

import rematch from '@zcorky/rematch';

// before
export function app(state, action) {
	switch(action.type) {
		case '+':
			return { ...state, value: state.value + action.payload };
		case '-':
			return { ...state, value: state.value - action.payload };
		case 'x':
			return { ...state, value: state.value * action.payload };
		case '/':
			return { ...state, value: state.value / action.payload };
		// ....
		default:
			return state;
	}
}

// after
export const app = rematch({
	'+': (state, action) => ({ ...state, value: state.value + action.payload }),
	'-': (state, action) => ({ ...state, value: state.value - action.payload }),
	'x': (state, action) => ({ ...state, value: state.value * action.payload }),
	'/': (state, action) => ({ ...state, value: state.value / action.payload }),
	// ...
});