Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getCategories() // Wraps ajax call and returns payload with array of categories
- .switchMap(categories => Observable.from(categories))
- .mergeMap(category =>
- getSubCategories(category) // Wraps ajax call and returns payload with array of sub categories
- .catch(err => {
- console.error('Error when fetching sub categories for category:', category);
- console.error(err);
- return Observable.empty();
- })
- )
- .mergeMap(subCategories => Observable.from(subCategories))
- .mergeMap(subCategory =>
- getProducts(subCategory) // Wraps ajax call and returns payload with array of products
- .catch(err => {
- console.error('Error when fetching products for sub category:', subCategory);
- console.error(err);
- return Observable.empty();
- })
- )
- .mergeMap(products => Observable.from(products))
- .mergeMap(product =>
- getProductDetails(product) // Wraps ajax call and returns payload with product details
- .catch(err => {
- console.error('Error when fetching product details for product:', product);
- console.error(err);
- return Observable.empty();
- })
- )
- .mergeMap(productDetails => saveToDb(productDetails))
- .catch(err => {
- console.error(err);
- })
- .subscribe();
Add Comment
Please, Sign In to add comment