Created
October 19, 2015 12:42
-
-
Save grabbou/b88847cf20298596cc5e 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
// will be caught by promise-middleware | |
function makeASandwichWithSecretSauce(name) { | |
return { | |
types: [], | |
payload: fetch(...) | |
} | |
}; | |
// This is complex one | |
// BTW, you don't have redux-thunk | |
// our injectDependencies middleware does that anyway | |
// because steida wanted it! Check it out | |
function makeSandwichesForEverybody() { | |
return ({dispatch, getState}) => { | |
if (!getState().sandwiches.isShopOpen) { | |
// You don’t have to return Promises, but it’s a handy convention | |
// so the caller can always call .then() on async dispatch result. | |
return Promise.resolve(); | |
} | |
return dispatch( | |
makeASandwichWithSecretSauce('My Grandma') | |
).then(() => | |
Promise.all([ | |
dispatch(makeASandwichWithSecretSauce('Me')), | |
dispatch(makeASandwichWithSecretSauce('My wife')) | |
]) | |
).then(() => | |
dispatch(makeASandwichWithSecretSauce('Our kids')) | |
).then(() => | |
dispatch(getState().myMoney > 42 ? | |
withdrawMoney(42) : | |
apologize('Me', 'The Sandwich Shop') | |
) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment