@zcorky/rematch
v1.0.0
Published
Use rematch instead of siwtch in Redux
Downloads
2
Readme
rematch
Stop
switch
, loverematch
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 }),
// ...
});