Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RXJS conditionally call observable

  const observable$ = iif(() => this.shippingTabModified,
      //Shipping Tab Modified True
      of(this.updateShippingInfo())
        .pipe(),
      //IF Shipping Tab Not Modified    
      of(this.shippingInfoService.getShipmentInfoByCardIdObservable(this.data.CardId))
        .pipe()
    )

    observable$.subscribe();

From above code i want to achieve following scenario

if(foo === true)
{
  updatemethod()
}
// if foo is true and update method is executed we need to wait until update method is finished then go to second method

// If foo is false we can call second method without waiting
secondmethod();

But from rxjs code which i wrote above, it always go to update method it is not considering the value of this.shippingTabModified

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can leverage on the concat function and do something like this

const observables$ = condition ? [obs$1, obs$2] : [obs$2];

concat(...observables$).subscribe();

Cheers

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading