wostory
wostory

Reputation: 23

Sending independent multiple http requests in component store effect

I need to make two http calls in effect with condition.

I mean , for example , if 1st http call returns true it should sent 2nd call. Other wise it should not sent 2nd call. Both http calls using same parameter.

my aim is like

 readonly getDefinition = this.effect((id$: Observable<string>) => {
   return id$.pipe(
    switchMap((id)) => {
          firstHttpCall(id).pipe(tap(x)=> { should stop somehow } )
          secondHttpCall(id).pipe(tap(x) => {  })
 }
)

}

Upvotes: 1

Views: 320

Answers (1)

wostory
wostory

Reputation: 23

I come up with solution.

i created 2nd effect for 2nd http call. and then called 2nd effect in first one. still not sure its valid solution but it works for me. my code is something like below

readonly firstEffect= this.effect((id$: Observable<string>) => {
    return id$.pipe(
      switchMap((id) => {
        return firsthttpcall(id).pipe(
          tap((value: boolean) => {
            if (value) {
              console.log('error')
              return EMPTY
            }
            getDefinition(id)
          })
        ) 
      }),
    )
  })



readonly getDefinition = this.effect((id$: Observable<string>) => {
       return id$.pipe(
           switchMap((id)) => {
               secondHttpCall(id).pipe(tap(x) => {  
                  console.log('business logic')
       })
   })

Upvotes: 1

Related Questions