├── .npmignore ├── .gitignore ├── README.md ├── src └── index.js └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | src/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | .eslintrc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # redux-chain-middleware 2 | redux middleware which allows dispatching promise action creators sequentially 3 | 4 | 5 | ## Usage 6 | --- 7 | sequentially 8 | ```js 9 | dispatch([ 10 | a(), 11 | b(), 12 | c() 13 | ]) 14 | ``` 15 | 16 | concurrently 17 | ```js 18 | dispatch(a()) 19 | dispatch(b()) 20 | dispatch(c()) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export default function chainMiddleware() { 2 | return next => async action => { 3 | if (Array.isArray(action)) { 4 | let actions = action; 5 | let prev = Promise.resolve(); 6 | for (let i = 0; i < actions.length; i++) { 7 | try { 8 | let curr = actions[i]; 9 | await prev; 10 | prev = next(curr); 11 | } catch (failAction) { 12 | if (failAction instanceof Error) { 13 | throw failAction; 14 | } 15 | next(failAction); 16 | break; 17 | } 18 | } 19 | } else { 20 | next(action); 21 | } 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redux-chain-middleware", 3 | "version": "1.0.0", 4 | "description": "redux middleware which allows dispatching promise action creators sequentially", 5 | "license": "MIT", 6 | "main": "lib/index.js", 7 | "author": { 8 | "name": "Terpil Jenya", 9 | "url": "https://github.com/terpiljenya" 10 | }, 11 | "keywords": [ 12 | "redux", 13 | "redux-promise", 14 | "async waterfall" 15 | ], 16 | "scripts": { 17 | "compile": "babel --presets es2015,stage-0 -d lib/ src/", 18 | "prepublish": "npm run compile" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/terpiljenya/redux-chain-middleware" 23 | }, 24 | "devDependencies": { 25 | "babel-cli": "^6.7.5", 26 | "babel-preset-es2015": "^6.6.0", 27 | "babel-preset-stage-0": "^6.5.0" 28 | } 29 | } 30 | --------------------------------------------------------------------------------