Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
[dsch] update for chain signature -- supproting arguments list

[dsch] fix for loading decorator - prevent promise leaks

[dsch] dependencies update
  • Loading branch information
DScheglov committed May 28, 2019
1 parent 2f85595 commit ac03e75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions 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",
Expand Down Expand Up @@ -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"
Expand Down
25 changes: 16 additions & 9 deletions 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;
3 changes: 2 additions & 1 deletion src/loading.js
Expand Up @@ -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))
);
}
Expand Down

0 comments on commit ac03e75

Please sign in to comment.