rxjs5

Observable forkJoin not firing

纵然是瞬间 提交于 2019-12-30 18:24:09
问题 I'm trying to user forkJoin on two Observables. One of them starts as a stream... If I subscribe to them directly I get a response, forkJoin isn't firing though. Any ideas? private data$: Observable<any[]>; private statuses$: Observable<any[]>; private queryStream = new Subject<string>(); .... this.data$ = this.queryStream .startWith('') .flatMap(queryInput => { this.query = queryInput return this._companyService.getCompanies(this.queryRequired + ' ' + this.query, this.page, this.sort); })

RxJS Refactor nested map statement

試著忘記壹切 提交于 2019-12-29 07:42:42
问题 I have a service which uses @angular/http to load data from an API. I want to create a projection of the retrieved data for my Components using this data. Therefore I wrote the following code: getById(id: string) { return this.http .get(`https://my-api.io/${id}`) .map(response => response.json()) .map(contracts => contracts.map(contract => # <- Nested map new Contract( contract['id'], contract['description'] ) ) ); } In the 6th line I have a nested map -Statement reducing the readability of

Trying to understand RxJS imports

时光总嘲笑我的痴心妄想 提交于 2019-12-29 06:17:29
问题 I'm having a hard time figuring out how exactly this import statement works (in an Angular application written in Typescript): import 'rxjs/add/operator/toPromise'; I get that rxjs is mapped to the respective node_modules subfolder in the SystemJS config file, but then I'm stuck. I see that there is an index.js file but I don't see whether or how this helps to resolve the add/operator/... part. Similarly, I don't understand this one: import {Observable} from 'rxjs/Observable'; Again, there is

Trying to understand RxJS imports

不羁的心 提交于 2019-12-29 06:17:09
问题 I'm having a hard time figuring out how exactly this import statement works (in an Angular application written in Typescript): import 'rxjs/add/operator/toPromise'; I get that rxjs is mapped to the respective node_modules subfolder in the SystemJS config file, but then I'm stuck. I see that there is an index.js file but I don't see whether or how this helps to resolve the add/operator/... part. Similarly, I don't understand this one: import {Observable} from 'rxjs/Observable'; Again, there is

How does the RxJs 5 share() operator work?

随声附和 提交于 2019-12-28 16:30:15
问题 Its not 100% clear for me how the RxJs 5 share() operator works, see here the latest docs. Jsbin for the question here. If I create an observable with a series of 0 to 2, each value separated by one second: var source = Rx.Observable.interval(1000) .take(5) .do(function (x) { console.log('some side effect'); }); And if I create two subscribers to this observable: source.subscribe((n) => console.log("subscriptor 1 = " + n)); source.subscribe((n) => console.log("subscriptor 2 = " + n)); I get

Angular 2 - Rxjs Intelligent with VS 2015 update 3

你离开我真会死。 提交于 2019-12-25 07:59:00
问题 I am learning the Angular 2. I am following exactly the tutorial Tour of Heroes (https://angular.io/docs/ts/latest/tutorial/), I have everything work just fine. Just one thing, it looks like the VS 2015 (with update 3) doesn't recognize extension functions from the Rxjs, can you advise how to fix it? I have all imported as in the tutorial // Observable class extensions import 'rxjs/add/observable/of'; import 'rxjs/add/observable/throw'; // Observable operators import 'rxjs/add/operator/catch'

Angular getting Authorization token asynchronously before HTTP calls

こ雲淡風輕ζ 提交于 2019-12-24 21:33:27
问题 before posting this i went to many other similar questions and not able to find solutions. like Angular 2 - Inject authorization token before each Http request I am using AWS session which provides me Authorization token for makeing HTTP request. Now getting session can be asynchronous operation depending on need to refresh token. Problem: I am not able to chain getting session and then making HTTP calls. Versions Angular 5, RxJs 5.5.2 AuthService's get session function. getSession():

convert rjxs map and flatten/reduce to flatMap

心不动则不痛 提交于 2019-12-24 20:55:34
问题 I believe the following code can be refactored using a flatMap but I cant seem to get it working as desired. I understand flatMap essentially maps and then flattens, which is perfect for me as I'm using forkJoin so get an array of responses back from getAutocompleteSuggestions(). I want a single array of results upon subscription (which is what the code below produces), but changing the top level map to flatMap sends multiple single objects to the subscription. How can this code be better

RxJs: updating values in a list from an other stream identified by an ID

早过忘川 提交于 2019-12-24 09:12:46
问题 I have two RX infinite streams (let's call them mainValues and decoratorValues ). The one called mainValues are adding elements to a list called valueList . The other stream ( decoratorValues ) should assign properties to these elements in the list. Elements in the two streams are arriving at random times in random order , and I need to solve it in either order that mainValues are put into the list as soon as available , while decoratorValues are not lost until their corresponding elements

Observable subscription not getting called

喜夏-厌秋 提交于 2019-12-24 07:47:43
问题 I have an Observable that I'm using to convert a promise into a subscription. This results in a collection that I need to iterate through to call an HTTP Service on each element. I'm using forkJoin to wait for all those calls to finish so that I can do something else, but unfortunately, my subscription is not being called. Do you see what I'm missing here? Observable.fromPromise(this.users.getElements()).subscribe(results => { Observable.forkJoin( results.map( aUser => this.HttpService