How can you simplify your code?

  • 0
    observable$.subscribe(result => {
      of(result).pipe(
        mergeMap(x => {...}),
        catchError(err => throwError(err))
      ).subscribe(...)
    }

    New events on click arrive in observable $, which generate the result object. Inside mergeMap, the logic of requests to the server with data from result. Each such request needs to be handled with errors.
    How can you get rid of nested subscribes?
    JavaScript Anonymous, Mar 27, 2019

  • 1 Answers
  • 0
    use switchMap

    observable$.pipe(
    switchMap((result) => {
    return of(result).pipe(.....)
    })
    ).subscribe(...)
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!