Skip to content

Creates an ES6 ./index.js file within target directories that imports all sibling action files and exports them as single object.

License

Notifications You must be signed in to change notification settings

dptoot/redux-create-action-index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-create-action-index

CLI utility to creates or update a index.js file in supplied target directories. The generated index file will import all sibling redux action files and export a single redux action object.

Installation

npm install --save-dev redux-create-action-index

Usage

redux-create-action-index ./src/actions

Example

Given the following directory structure:

> tree ./src/actions
./
├── file1.js
├── file2.js
├── file3.js
├── file4.js
└── file5.js

0 directories, 5 files

Running js redux-create-action-index ./src/actions will generate an index.js file in ./src/actions containing:

import * as file1Actions from './file1.js';
import * as file2Actions from './file2.js';
import * as file3Actions from './file3.js';
import * as file4Actions from './file4.js';
import * as file5Actions from './file5.js';

export default Object.assign({}, 
    file1Actions,
    file2Actions,
    file3Actions,
    file4Actions,
    file5Actions
);

These ActionCreators can now be accessed in any component using redux's connect via:

import {connect} from 'react-redux';
import ActionCreators from '../actions';

...

function mapDispatchToProps(dispatch) {
    return bindActionCreators(ActionCreators, dispatch);
}

...

export default connect(mapStateToProps, mapDispatchToProps)(Component);

CLI Options

  --indent, -i  set number of spaces to indent             [number] [default: 4]
  --suffix, -s  suffix to add to the import module name    [string] [default: "Actions"]
  --help        Show help                                  [boolean]

About

Creates an ES6 ./index.js file within target directories that imports all sibling action files and exports them as single object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published