Created
March 9, 2020 12:34
-
-
Save desphilboy/f8cb7abfef38db52faa8344fd237d1d6 to your computer and use it in GitHub Desktop.
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
import 'regenerator-runtime/runtime'; | |
/** | |
* @param { object or function } dependencyMap maps dependencies into sideEffec parameter names. If it is | |
* a function will be called with Redux state and dispatch if non-function object will be added to | |
* parameters as is | |
* | |
* @param { function } sideEffect is a function that does the actual work. It will be called | |
* with all the parameters including mapped ones and the third param. | |
* | |
* @param { object } params additional parameters passed by caller of the effect. the params | |
* will be passed to the sideEffect funcion as is | |
* | |
* @params { function } dispatch and getState this will be provided by thunk middleware from Redux store | |
*/ | |
export const thunkify = dependencyMap => sideEffect => params => async (dispatch, getState) => | |
await sideEffect({ | |
...params, | |
...(typeof dependencyMap === 'function' ? dependencyMap(dispatch, getState) : dependencyMap), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment