angular - get stream of merged observables from another observable in rxjs -
i've simple app which, based on list of cities, retrieves weather information service every x seconds , displays info.
i'm using angular 4 ngrx accomplish , have working, i'd refactor things more reactive.
so piece of code want change:
@effect() weather$: observable<action> = this.actions$ .oftype(load_weather_action) .switchmap(() => { const cityobservables = this.cities.map(city => this.service.getweatherbycityid(city.id, city.name) ); return observable.merge(...cityobservables); }) .map(weather => new cityweatherloadedaction(weather)); so syntax here not important. doing is, every time action of type load_weather_action, create list of observables, 1 each city want data for, , use merge combine them all, , use switchmap replace initial observable stream new one.
all good, if list of cities, instead of simple array, observable? how that?
thanks!
then .switchmap observable, , merge() inside:
weather$: observable<action> = this.actions$ .oftype(load_weather_action) .switchmap(() => { return this.cities.switchmap((cities) => { return observable.merge(...cities.map(city => this.service.getweatherbycityid(city.id, city.name))) }) }) .map(weather => new cityweatherloadedaction(weather));
Comments
Post a Comment