Yet, one more of those pretentious projects that are offering to solve the very few incovenients that can be found with redux-thunk.
-
Higly repetitive
-
Tightly coupled to redux store
When it comes to test
- Most action creator can be modelised
{
const initialAction = getInitialActionSynchronous(...someArguments);
dispatch(initialAction)
let resultAction;
try {
resultAction = await getSuccessActionAsynchronous(...successArgs);
} catch(e) {
resultAction = getFailureActionSynchronous();
}
dispatch()
}
for more details I invite you to dive into the source code or my blog post ! enjoy !
- Use
npm install --save redux-thunk-functional
import asyncActionCreator from 'redux-thunk-functional'
- asyncActionCreator
({ asyncTask, actionCreators: { initial, success, failure }, extra }) => (dispatch, getState, customArg) => any
- asyncTask: the asynchronous tash generating data
({ intialState: Object, getState: function, extra: any }) => Data: Object
- actionCreators: an object with three fields whose values are action creators
a. initial
({ intialState: Object, extra: any }) => Action
b. success
({ intialState: Object, getState: function, data: any, extra: any }) => Action
c. failure
({ intialState: Object, getState: function, error: any, extra: any }) => Action
Prototype: {}