Created
May 22, 2018 17:58
-
-
Save caub/d55d87751a096ef176d96507793b1b56 to your computer and use it in GitHub Desktop.
Don't use redux-saga
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
const promiseMiddleware = store => next => action => { | |
if (typeof action.then === 'function') { | |
return Promise.resolve(action).then(next); | |
} else if (action.value && typeof action.value.then === 'function') { | |
return Promise.resolve(action.value).then(value => next({ type: action.type, value })); | |
} | |
// else, not a promise | |
try { | |
return next(action); | |
} catch (e) { | |
return Promise.reject(e); | |
} | |
}; | |
// dispatch(someQuery()) | |
// dispatch(fechApi('/foos').then(foos => ({type: FOOS, value: foos}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment