title: RxJS 6 conditionally pipe an observable
body: <p>I have an existing function which does some amount of work calling HTTP endpoints that takes care of managing some logic in my Angular component.  A requirement comes in so that in a certain instance we need to all of the existing logic to be called, but also another HTTP call to be made.  Below is an annotated version of my attempt.</p>
  
  <pre><code>public resolveComponent(action: string) {
          //if called with no parameters, don't do anything
          //otherwise, call one of the two endpoints.     
          let preAction = (x: any) =&gt; {
              if (action === "replay") {
                  return this.remediationService
                             .replayRemediation(this.workflow.Id);
              }
              else if (action === "remove") {
                  return this.remediationService
                             .removeRemediation(this.workflow.Id);
              }
              else {
                  return of([]);
              }
          }
  
          this.remediationService
              .resolveComponent(component)
              .pipe(
                  //the line below was what I added after new requirement
                  mergeMap(preAction),
                  mergeMap(x =&gt; {
                      //grabs updated data from server
                      return this.remediationService.remediationComponent(component.Id);
                  })
              )
              .subscribe((x: SomeModel) =&gt; {
                      //logic happens
                  });
  }
  </code></pre>
  
  <p>This performs the work as expected, but is this the best way to go about conditionally chaining observables?</p>