Skip to content

Instantly share code, notes, and snippets.

@hendrikswan
Last active May 7, 2019 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrikswan/c993b1f47c3f09023487e74f82101cf3 to your computer and use it in GitHub Desktop.
Save hendrikswan/c993b1f47c3f09023487e74f82101cf3 to your computer and use it in GitHub Desktop.
function loadDataEpic(action$) {
return action$
.ofType('LOAD_DATA')
.switchMap(({ url }) =>
fetch(url)
.then(response => response.ok ? response.json() : requestFailedAction())
.then(result => result.type === 'REQUEST_FAILED' ? result : requestSuccessAction(result))
.catch(() => requestFailedAction())
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment