Skip to content

Instantly share code, notes, and snippets.

@TaylorAckley
Created February 22, 2021 20:24
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/967003c9b0fbabcaf4d6ec246f94d389 to your computer and use it in GitHub Desktop.
Save TaylorAckley/967003c9b0fbabcaf4d6ec246f94d389 to your computer and use it in GitHub Desktop.
Return from nested observable
import { Observable, of } from "rxjs";
import { switchMap, map } from "rxjs/operators";
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 DataFactory.getSetupData().pipe(
switchMap((setupData) => DataFactory.getUsefulData(setupData)),
map((usefulData) => 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