├── .gitignore ├── index.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | export function createTypes(prefix, ...args) { 2 | return args.reduce((types, type) => { 3 | [].concat(type).map(v => types[v] = prefix + v) 4 | return types 5 | }, {}) 6 | } 7 | 8 | export function asyncAction(type, subTypes = ["REQUEST", "SUCCESS", "FAIL"]) { 9 | return [].concat(subTypes.map(t => `${type}_${t}`)); 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redux-action-types", 3 | "version": "2.0.0", 4 | "description": "Shortcut for creating redux action constants.", 5 | "main": "lib/index.js", 6 | "files": [ 7 | "lib/" 8 | ], 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1", 11 | "prepublish": "mkdir -p lib && babel --presets es2015 index.js -o lib/index.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/ripeworks/redux-action-types.git" 16 | }, 17 | "keywords": [ 18 | "redux", 19 | "react" 20 | ], 21 | "author": "Ripeworks", 22 | "license": "ISC", 23 | "bugs": { 24 | "url": "https://github.com/ripeworks/redux-action-types/issues" 25 | }, 26 | "homepage": "https://github.com/ripeworks/redux-action-types#readme", 27 | "devDependencies": { 28 | "babel": "^6.1.18", 29 | "babel-cli": "^6.2.0", 30 | "babel-preset-es2015": "^6.1.18" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # redux-action-types 2 | shortcut for making action types 3 | 4 | [![npm version](https://badge.fury.io/js/redux-action-types.svg)](https://badge.fury.io/js/redux-action-types) 5 | 6 | ```js 7 | import { createTypes, asyncAction } from 'redux-action-types' 8 | 9 | export const types = createTypes('my-app/module/', 10 | 'SORT', 11 | 'ADD', 12 | asyncAction('LOAD'), 13 | asyncAction('SAVE'), 14 | asyncAction('UPDATE'), 15 | asyncAction('REMOVE', ['REQUEST', 'COMPLETE']) 16 | ) 17 | 18 | /* 19 | types = { 20 | SORT: "my-app/module/SORT" 21 | ADD: "my-app/module/ADD" 22 | LOAD_REQUEST: "my-app/module/LOAD_REQUEST" 23 | LOAD_SUCCESS: "my-app/module/LOAD_SUCCESS" 24 | LOAD_FAIL: "my-app/module/LOAD_FAIL" 25 | SAVE_REQUEST: "my-app/module/SAVE_REQUEST" 26 | SAVE_SUCCESS: "my-app/module/SAVE_SUCCESS" 27 | SAVE_FAIL: "my-app/module/SAVE_FAIL" 28 | UPDATE_REQUEST: "my-app/module/UPDATE_REQUEST" 29 | UPDATE_SUCCESS: "my-app/module/UPDATE_SUCCESS" 30 | UPDATE_FAIL: "my-app/module/UPDATE_FAIL" 31 | REMOVE_REQUEST: "my-app/module/REMOVE_REQUEST" 32 | REMOVE_COMPLETE: "my-app/module/REMOVE_COMPLETE" 33 | } 34 | */ 35 | 36 | 37 | 38 | ``` 39 | --------------------------------------------------------------------------------