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

Create Observable at the time of subscription

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

// decides later what observable to return
const source$ = defer(()=>{
  if (Date.now() < 3) {
    return of('🐦');
  }

  return of('🦉');
});

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

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

To switch between two Observables see iif function

You can’t perform that action at this time.