Created
February 22, 2021 20:23
-
-
Save TaylorAckley/28b1a7d4e1a26bdda870e6b61a97dc9a to your computer and use it in GitHub Desktop.
Return value from nested observable using Observable.create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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