npm

Need private packages and team management tools?Check out npm Orgs. »

redux-bind-action-groups

2.1.0 • Public • Published

bind redux action to group, avoid action generate function name conflict, and compatibility redux bindActionCreators

Build Status

install

npm i -S redux-bind-action-groups

example

my two action creator files

// post.js
export function getList(){
    return {
        type: 'POST_GETLIST'
    }
}
 
 
// photo.js
export function getList(){
    return {
        type: 'PHOTO_GETLIST'
    }
}

bind action creator with redux bindActionCreators

import * as postActions from './post';
import * as photoActions from './photo';
import {bindActionCreators} from 'redux';
 
function mapDispatchToProps(dispatch){
    return bindActionCreators({
        ...postActions,
        ...photoActions
    }, dispatch)
}
 
// in React Component
this.props.getList();  // which getList will exec in post and photo

useage

import bindActionGroups from 'redux-bind-action-groups';
 
function mapDispatchToProps(dispatch){
    return bindActionGroups({
        post: postActions,
        photo: photoActions,
        foo: () => ({type: 'DO_SOMETHING'})
    }, dispatch)
}
 
// in React Component, work fine
this.props.post.getList();
this.props.photo.getList();
this.props.foo()

install

npm i redux-bind-action-groups

Downloadsweekly downloads

4

version

2.1.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability