diff --git a/package.json b/package.json index 74252e3..756f8ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "handy-thunks", - "version": "1.0.0", + "version": "1.0.1", "description": "Tools for coding with redux-thunk", "main": "lib/index.js", "module": "es/index.js", @@ -50,7 +50,7 @@ "coveralls": "^3.0.2", "eslint": "^5.7.0", "eslint-plugin-jest": "^21.26.0", - "jest": "^23.6.0", + "jest": "^24.8.0", "redux": "^4.0.1", "redux-actions": "^2.6.3", "redux-thunk": "^2.3.0" diff --git a/src/chain.js b/src/chain.js index cdfba16..661ff0c 100644 --- a/src/chain.js +++ b/src/chain.js @@ -1,14 +1,21 @@ import { compose } from 'redux'; import { ensureAsync } from './helpers/promises'; -const chain = thunks => (...args) => dispatch => { - const first = thunks[0]; - const initial = ensureAsync(compose(dispatch, first)); - - return thunks.slice(1).reduce( - (promise, thunk) => promise.then(compose(dispatch, thunk)), - initial(...args) - ); -}; +const chain = (...thunks) => { + if (Array.isArray(thunks[0])) { + // supporting previous interface of the chain decorator + thunks = thunks[0]; + } + + return (...args) => dispatch => { + const first = thunks[0]; + const initial = ensureAsync(compose(dispatch, first)); + + return thunks.slice(1).reduce( + (promise, thunk) => promise.then(compose(dispatch, thunk)), + initial(...args) + ); + }; +} export default chain; \ No newline at end of file diff --git a/src/loading.js b/src/loading.js index 165e56a..165cfcc 100644 --- a/src/loading.js +++ b/src/loading.js @@ -14,7 +14,8 @@ const loading = (start, end) => (...loadingArgs) => thunk => ( const promise = asyncThunk(...args); if (typeof end === 'function') { - promise.finally( + // Prventing promise leaks by returning new promise + return promise.finally( () => dispatch(end(...loadingArgs)) ); }