I have a parent observable that, once it has a subscriber, will do a lookup and emit a single value, then complete.
I\'d like to convert that into an observable (or
I've implemented a method to convert Observables to BehaviorSubjects, as I think that the shareReplay method isn't very readable for future reference.
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
export function convertObservableToBehaviorSubject(observable: Observable, initValue: T): BehaviorSubject {
const subject = new BehaviorSubject(initValue);
observable.subscribe(
(x: T) => {
subject.next(x);
},
(err: any) => {
subject.error(err);
},
() => {
subject.complete();
},
);
return subject;
}