I have problems wrapping my head around how to achieve the following Problem with Reactive programming:
I want to call a Method getSearchResults(searchterm: string): Observable<Foo[]>. In this method I normally filter data from a locally stored dataset. Only if this dataset is not loaded, I want to load my dataset from the server first:
getSearchResults(searchterm: string): Observable<Foo[]> {
if(this.dataset != null) {
return this.filter(this.dataset, searchterm);
}
// Load dataset first from server. service method returns an Observable
const obs = myService.loadDataset();
obs.subscribe(data => {
this.dataset = data;
// Now I want to call filter and return an Observable
return this.filter(this.dataset, searchterm);
});
}
Consider this as pseudocode and no full example, but I hope it makes my problem clear. I understand, that this does not work in this manner.
But I really have a hard time to find a pattern to achieve something like this.
Any help?