redux-helper
v1.0.6
Published
Redux reducer and action helper
Downloads
143
Readme
redux-helper
Action creator, promise action creator and checked promise middleware.
This library is written in order to support development of projects using redux in typescript.
The goal is to try to get as much advantage as possible form the strong typing system that typescript provide in order to reduce errors and catch them early.
For example actions will be defined once and they will provide a matchAction function that reducers can use to match the received action and get the typed payload.
Usage
npm i 'redux-helper' --save
Simple action creator
//actions.ts
import {createAction} from 'redux-helper';
export const addProduct = createAction<{name:string}> ('ADD_TODO'); // ADD_TODO literal is written only here.
//reducer.ts
import {Action} from 'redux-helper';
import {addProduct} from './actions.ts';
const reducer = (state: IProductsModel = defaultState, action: Action<any>) => {
if (actions.addProduct.matchAction(action)) {
...
// the type of action payload here is {name:string}
// no need to cast or test string literals
}
//dispatch action..
import {addProduct} from './actions.ts';
...
//event handler,
const onAddTodo = (name:string) =>{
this.props.dispatch(addProduct({name:name}));
}
...
Promise action creator
//actions.ts
import {createPromiseAction} from 'redux-helper';
Configure middleware
Development
'run unit test'
npm test
'build'
npm run build
'release to npm repository (only authorized members)'
npm run release