Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (25 sloc) 808 Bytes

Using a predicate, decide which Observable to provide at the time of subscription

const { rxObserver } = require('api/v0.3');
const { iif, of } = require('rxjs');

// decides later which observable to return
const source$ = iif(
  ()=> Date.now() < 3 // predicate
  , of('🐦')          // true
  , of('🦉')          // false
);

// subsctibe at T0
source$.subscribe(rxObserver('Early bird'));

// delayed subscription
setTimeout(()=>{
  source$.subscribe(rxObserver('Night owl'));
}, 5);

To switch between many Observables see defer function

You can’t perform that action at this time.