Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rxjs: map method doesn't execute on combineLatest

I'm trying to combine 2 Observable streams to 1 stream with combineLatest. Only, the .map() function doesn't work on the resulting stream. And with doesn't work, I mean that nothing is logged in the example below. On the other had, if I switch out the .map() function for a .subscribe() function, then everything works just fine. My observables come from firebase using the angularfire2 library. I have also imported the map function and it works on other Observable streams.

const placeList = this._db.list(URL)
    .map(this.flattenJSON);
const placeImages = this._db.list(URL);
Observable.combineLatest(placeList, placeImages)
    .map(response => {
         console.log(response);
         return response;
    });

Does anyone know why the subscribe function works, and the map does not? And does anyone have advice on how I can merge 2 firebase Observable streams and map this stream. Mind you that the Observable streams resulting from angularfire2 do not finish.

like image 802
sjbuysse Avatar asked Sep 18 '25 03:09

sjbuysse


1 Answers

You should always subscribe to an observable if you want it to actually get executed. Just chain subscribe() after the map:

const placeList = this._db.list(URL)
    .map(this.flattenJSON);
const placeImages = this._db.list(URL);
Observable.combineLatest(placeList, placeImages)
    .map(response => {
         console.log(response);
         return response;
    })
    .subscribe();
like image 189
Catalyst Avatar answered Sep 20 '25 17:09

Catalyst