Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active Aug 17, 2018
Embed
What would you like to do?
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