rxjs

rxjs condition inside flatmap

主宰稳场 提交于 2019-12-11 02:49:43
问题 I want to have a condition inside flatMap that checks what was returned by first observable. If condition is not met I would like to break and navigate to different page. this.service.getData(id) .flatMap((data) => { if (!data) { return Observable.throw(new NoDataFoundError()); } return Observable.forkJoin( this.service.getData2(id2), this.service.getData3(id3), ); }) .subscribe( ([data2, data3]) => { this.data2= data2; this.data3= data3; }, (err) => { if (err instanceof NoDataFoundError) {

rx.js how to chain observables

*爱你&永不变心* 提交于 2019-12-11 02:14:08
问题 I have an observable that is pulling events off of a server, filtering events for the application type, then subscribing and dispatching the event to one or more handlers to handle. The handlers then go off and do some async update to the db, and I find that the observable will crank out events so fast that the updates are stepping on each other. Which I should have expected. So I think I need my handlers to each employ it's own observable to act as a queue which will handle one event and

How to retry only on certain error emitted by the source observable in RxJs

為{幸葍}努か 提交于 2019-12-11 02:03:42
问题 A srcObservable.retry() will catch the error emitted by the srcObservable and resubscribe to the srcObservable regardless of the type of the error. However, on certain scenario, it is wanted to only retry on certain type of error emitted by the srcObservable. Is there a way to do so in RxJs neatly? 回答1: Try using retryWhen: src.retryWhen(function (errors) { // retry for some errors, end the stream with an error for others return errors.do(function (e) { if (!canRetry(e)) { throw e; } }); });

How to preserve object property casing when using Rxjs map function

白昼怎懂夜的黑 提交于 2019-12-11 01:52:06
问题 I am new to Angular2 and using http service to get data from asp.net mvc webapi. API returns data which is in format shown below RequestResponse{ public string Message {get;set;} public int Status {get;set;} } Http get request gets data and is fed to map function from Rxjs map(result => result.json()) which will convert result into format as shown below { message : 'success!', status : 1 } As you can see, output property names have lost case sensitivity. Have read from other SO questions that

Convert an Observable to an async generator

こ雲淡風輕ζ 提交于 2019-12-11 01:48:51
问题 I'm trying to use rxjs in conjunction with babeljs to create an async generator function that yields when next is called, throws when error is called, and finishes when complete is called. The problem I have with this is that I can't yield from a callback. I can await a Promise to handle the return/throw requirement. async function *getData( observable ) { await new Promise( ( resolve, reject ) => { observable.subscribe( { next( data ) { yield data; // can't yield here }, error( err ) {

What is cold observable in context of angular HttpClient

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:47:59
问题 While using angular HttpClient of angular I got to know that HttpClient post method used cold observable and will make 2 separate calls to post data to the server.And also unless you will not subscribe the post method it will not post data to the server. Although, Rxjs cold observable says it will hold all the sequence until the the end and fire all when it subscribed. How it will make 2 separate call to server to post data. 回答1: I don't believe that this behavior is caused by the use of

Typescript rxjs Observable array concat

天涯浪子 提交于 2019-12-11 01:28:27
问题 I am having trouble using rxjs Observable.concat function with typescript. Getting an error "Cannot read property 'apply' of undefined" The problem seems to be only within typescript and may be specific to rxjs version 5 concat. The code seems to work with rxjs V4. Here is a simplified version of the code illustrating the problem... /*jshint esnext: true */ console.clear(); console.log('started'); class test{ observableArray: Observable<any>[]=[]; constructor(){ this.observableArray.push(Rx

Cascading ajax calls with RxJs

你说的曾经没有我的故事 提交于 2019-12-11 01:27:19
问题 How can I cascade RxJs calls to retrieve data from this contrived service. First request goes to /customer/1 /customer/:id Response: { Name: "Tom", Invoices: [1,3], Orders: [5,6] } In the customer response there are 2 InvoiceIds that we use to access second service: /invoices/:id Response { Id: 1, Amount: 10 } In the customer response there are 2 OrderIds that we use to access third service: /orders/:id Response { Id:2, Date: '2016-11-12' } At the end I would like to kome up with an object

Check if publishReplay().refCount() has observers or not

↘锁芯ラ 提交于 2019-12-11 01:12:09
问题 I define an Observable like this: const obs$ = Observable.create(...) .publishReplay(1) .refCount(); So that it puts a ReplaySubject(1) between my source Observable and all observers. Since ReplaySubject has in its state the number of observers (via its observers array property), how is it possible to access the ReplaySubject from obs$ ? I actually only need to know if obs$ has any observers or not. RxJS4 had a hasObservers() method on Subject, but it got removed in RxJS5. How can I achieve

TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined

落花浮王杯 提交于 2019-12-11 00:58:41
问题 I get the following exception when a web service request fails. TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined Specifically the HTTP GET returns 400 Bad request. Here you can find the involved component: @Component({ selector: 'events-list', directives: [EventRow], changeDetection: ChangeDetectionStrategy.OnPush, providers: [HTTP_PROVIDERS], template: ` <table> <tr *ngFor="let event of events | async" [event]="event" > </tr> </table> ` }) export class EventsList