Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dsch] update for chain signature -- supproting arguments list [dsch] fix for loading decorator - prevent promise leaks [dsch] dependencies update
- Loading branch information
Showing
3 changed files
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters