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

1.0.6 • Public • Published

redux-helper

Action creator, promise action creator and checked promise middleware.

npm version build

dependency devDep

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

Readme

Keywords

none

Package Sidebar

Install

npm i redux-helper

Weekly Downloads

47

Version

1.0.6

License

MIT

Unpacked Size

22.9 kB

Total Files

14

Last publish

Collaborators

  • vgmr-admin
  • smulas
  • jodan-pz
  • ruska-dev