title: What is the cleanest way of structuring multiple HTTP calls within one @Effect using ngrx
body: <p>I am using ngrx and have an @Effect hooked up to a LOAD_CONTRACT action, which then makes 3 HTTP calls to get data. Private variables are used to store the data from each GET, so that at the end the LoadContractSuccessAction can be called with a payload containing the 3 retrieved objects.</p>
  
  <p>My code below works fine, and the error handling works as well... but I feel like there may be a neater or better way of structuring things.</p>
  
  <p>I don't know if all the nesting is necessary, or if things could be flattened out in some way. I also am not sure if using switchMap is the best operator.</p>
  
  <p>Could someone with better knowledge of ngrx best practices comment on how the below could be improved/simplified...?</p>
  
  <pre class="lang-js prettyprint-override"><code>private clientContractIds: IClientContractIds;
  private contract: Contract;
  private contractSummaryMonths: ContractSummaryMonth[];
  private contractSummaryTotals: ContractSummaryTotals;
  
  // Loads a contract and its summary months and totals.
  @Effect()
  loadContract$ = this.actions$.pipe(
    ofType(ContractActionTypes.LOAD_CONTRACT),
      map((action: IActionWithPayload&lt;IClientContractIds&gt;) =&gt; {
        this.clientContractIds = {
          client_id: action.payload.client_id,
          contract_id: action.payload.contract_id
        };
      }),
  
      // Get the contract.
      switchMap(() =&gt; {
        return this.contractService.getContract$(this.clientContractIds).pipe(
          map(contract =&gt; (this.contract = contract)),
          catchError(error =&gt; throwError(error)),
  
          // Get the summary months.
          switchMap(() =&gt; {
            return this.contractService
              .getContractSummaryMonths$(this.clientContractIds)
              .pipe(
                map(
                  contractSummaryMonths =&gt;
                    (this.contractSummaryMonths = contractSummaryMonths)
                ),
                catchError(error =&gt; throwError(error))
              );
          }),
  
          // Get the summary totals.
          switchMap(() =&gt; {
            return this.contractService
              .getContractSummaryTotals$(this.clientContractIds)
              .pipe(
                map(
                  contractSummaryTotals =&gt;
                    (this.contractSummaryTotals = contractSummaryTotals)
                ),
                catchError(error =&gt; throwError(error))
              );
          }),
  
          // Call the success action with the payload objects.
          switchMap(() =&gt; {
            return of(
              new LoadContractSuccessAction({
                contract: this.contract,
                contractSummaryMonths: this.contractSummaryMonths,
                contractSummryTotals: this.contractSummaryTotals
              })
            );
          })
      );
    }),
    catchError(error =&gt; {
      return of(new LoadContractFailAction(error));
    })
  );
  </code></pre>