Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Created September 10, 2018 17:06
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 vkarpov15/75cba89dcdcfa7f1b4726e25d889ecb4 to your computer and use it in GitHub Desktop.
Save vkarpov15/75cba89dcdcfa7f1b4726e25d889ecb4 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
// ...
const fetchEpic = action$ => action$.pipe(
filter(action => action.type === 'FETCH_STOCK_PRICE'),
mergeMap(async (action) => {
const url = `https://api.iextrading.com/1.0/stock/${action.symbol}/price`;
const price = await fetch(url).then(res => res.text());
return Object.assign({}, action, { type: 'FETCH_STOCK_PRICE_SUCCESS', price });
}),
catchError(err => Promise.resolve({ type: 'FETCH_STOCK_PRICE_ERROR', message: err.message }))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment