0

What is the best way to write following code in RxJs. Assuming getSomethingFromDb( ) returns an observable. Note: I do not want to use IF from my RXJS code

let something:any = getSomethingFromDatabsae( )

if(<value inside something observable is not undefined>){
   doThis( );
} else {
   doThat( );
}

Edit: I am going to make my question more interesting. What if my code is more complex like this, how to implement this without using if statements in RxJS. ( more declartively )

let observable:any = getSomethingFromDatabsae( )

if(<value inside observable is not undefined>){
   doThis( );
} else if(<value inside observable is "one">) {
   doFirstThing( );
}else if(<value inside observable is "two">) {
   doSecondThing( );
}
ATHER
  • 3,254
  • 5
  • 40
  • 63

1 Answers1

0

I thought what are you looking for is the operator 'Partition '

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-partition

provide the condition, and you will get the 'pass' stream and the 'fail' stream

VincentGuo
  • 247
  • 2
  • 9