Guest User

Untitled

a guest
Jan 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. getCategories() // Wraps ajax call and returns payload with array of categories
  2. .switchMap(categories => Observable.from(categories))
  3. .mergeMap(category =>
  4. getSubCategories(category) // Wraps ajax call and returns payload with array of sub categories
  5. .catch(err => {
  6. console.error('Error when fetching sub categories for category:', category);
  7. console.error(err);
  8. return Observable.empty();
  9. })
  10. )
  11. .mergeMap(subCategories => Observable.from(subCategories))
  12. .mergeMap(subCategory =>
  13. getProducts(subCategory) // Wraps ajax call and returns payload with array of products
  14. .catch(err => {
  15. console.error('Error when fetching products for sub category:', subCategory);
  16. console.error(err);
  17. return Observable.empty();
  18. })
  19. )
  20. .mergeMap(products => Observable.from(products))
  21. .mergeMap(product =>
  22. getProductDetails(product) // Wraps ajax call and returns payload with product details
  23. .catch(err => {
  24. console.error('Error when fetching product details for product:', product);
  25. console.error(err);
  26. return Observable.empty();
  27. })
  28. )
  29. .mergeMap(productDetails => saveToDb(productDetails))
  30. .catch(err => {
  31. console.error(err);
  32. })
  33. .subscribe();
Add Comment
Please, Sign In to add comment