Created
March 7, 2016 20:04
-
-
Save nkt/6f7109f860e564d5bf22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 isFunction from 'lodash/isFunction'; | |
function createAsyncAction(type, promise) { | |
return (dispatch) => { | |
dispatch({ | |
type, | |
meta: { | |
pending: true | |
} | |
}); | |
promise.then( | |
(payload) => isFunction(payload) ? payload(dispatch) : dispatch({type, payload}), | |
(payload) => dispatch({type, payload, error: true}) | |
); | |
}; | |
} | |
export default createAsyncAction; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment