title: Ngrx Effects: Conditionally return action inside switchMap instead of http response
body: <p>I'm currently working in an Angular 5 app that is going to use some cache strategies with ngrx-store, for allowing users to view an item and go back to the main list without having to make the request again.</p>
  
  <p>I'm using an Effect to request data and using a reducer to update my global state based on my htp response. As you can see, for success the RequestPartnersSuccess action is triggered, and for errors the RequestPartnersFail is triggered.</p>
  
  <p>The property 'internalAppDynamic.searchPartners.recoverLatest' from my global state indicates if I should recover my list from cache, and in this case the effect should return a method inside this 'if' statement and finishes my stream.</p>
  
  <pre><code>@Effect()
    loadPartners$ = this.actions$
      .ofType(SearchPartnersActions.REQUEST_PARTNERS)
      .withLatestFrom(this.store$, (action, state) =&gt; {
        action = Object.assign(action, {recoverLatest: state.internalAppDynamic.searchPartners.recoverLatest})
        return action
      })
      .pipe(switchMap((action: any) =&gt; {
        if (action.recoverLatest) {
          return new SearchPartnersActions.RequestPartnersRecoverCache()
        }
        return this.internalPartnersService.getPartners(action.payload).pipe(
          map(partners =&gt; new SearchPartnersActions.RequestPartnersSuccess(partners)),
          catchError(error =&gt; of(new SearchPartnersActions.RequestPartnersFail(error)))
        )
      }))
  </code></pre>
  
  <p>And this is the getPartners() function from my service:</p>
  
  <pre><code>getPartners (body): Observable&lt;any&gt; {
      return this.http
      .post(this._baseUrl + 'internal-app/get-partners', body, this.httpOptions)
      .pipe(catchError((error: any) =&gt; this.errorHandler(error)))
    }
  </code></pre>
  
  <p>The thing is that I couldn't find a way to achieve this result. I'm new to rxjs and Observables, and I think the switchMap operator expects another kind of return instead of a new instance of my SearchPartnersActions.RequestPartnersRecoverCache() class.</p>
  
  <p>What could I do to achieve the desired result? Could someone explain to me better what is expected from this stream of Observables?</p>
  
  <p>Thanks!</p>