Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active August 17, 2018 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/ef7293182f5e8ee8ed811f784575eb65 to your computer and use it in GitHub Desktop.
Save robwormald/ef7293182f5e8ee8ed811f784575eb65 to your computer and use it in GitHub Desktop.
function toResponseActions(successSelector, errorSelector){
return (requests$) => requests$.pipe(
catchError(err, => errorSelector(err)),
map(res => successSelector(res))
)
}
const buttonClicks = fromEvent('button', 'click');
const requests = buttonClicks.pipe(switchMap(() => http.get('foo.json')));
const responses = requests.pipe(
toResponseActions(
res => ({type: 'SUCCESS', payload: res.data })),
err => ({type: 'ERROR', payload: error }))
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment