Skip to content

Instantly share code, notes, and snippets.

@TaylorAckley
Created February 22, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaylorAckley/28b1a7d4e1a26bdda870e6b61a97dc9a to your computer and use it in GitHub Desktop.
Save TaylorAckley/28b1a7d4e1a26bdda870e6b61a97dc9a to your computer and use it in GitHub Desktop.
Return value from nested observable using Observable.create
import { Observable, of, Subject } from "rxjs";
class DataFactory {
static getSetupData() {
return of({ param1: "someparam" });
}
static getUsefulData(setupData: any) {
// pretend we use setupData in some fancy way
return of({ datapoint: "x" });
}
static getData(): Observable<string> {
return Observable.create(function (observer) {
DataFactory.getSetupData().subscribe((setupData) => {
DataFactory.getUsefulData(setupData).subscribe((usefulData) => {
observer.next(usefulData.datapoint);
});
});
});
}
}
DataFactory.getData().subscribe((d) => console.log("Recieved Value", d));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment