rxjs

Extending (mapped) tuple types

∥☆過路亽.° 提交于 2020-01-15 09:05:50
问题 When using tuple types in generic functions, how can you 'extend' the source type? Let's say we want to make a rxjs mapping operator that returns the source observable value(s) together with another mapped value: export function mapExtended<T, R>(mapping: (input: [T]) => R): OperatorFunction<[T], [T, R]>; export function mapExtended<T1, T2, R>(mapping: (input: [T1, T2]) => R): OperatorFunction<[T1, T2], [T1, T2, R]>; export function mapExtended<T1, T2, T3, R>(mapping: (input: [T1, T2, T3]) =>

Extending (mapped) tuple types

混江龙づ霸主 提交于 2020-01-15 09:04:41
问题 When using tuple types in generic functions, how can you 'extend' the source type? Let's say we want to make a rxjs mapping operator that returns the source observable value(s) together with another mapped value: export function mapExtended<T, R>(mapping: (input: [T]) => R): OperatorFunction<[T], [T, R]>; export function mapExtended<T1, T2, R>(mapping: (input: [T1, T2]) => R): OperatorFunction<[T1, T2], [T1, T2, R]>; export function mapExtended<T1, T2, T3, R>(mapping: (input: [T1, T2, T3]) =>

Angular2 : Chain http requests with concat()

让人想犯罪 __ 提交于 2020-01-15 08:45:08
问题 I have some difficulties to chain several HTTP requests. First, the request is defined in this service method that returns a cold Observable. FormPartService submitFormPart(id: string, part: string, data: any) { let body = JSON.stringify({ claimFileId: claimFileId, part: part, data: data }); return this.http.post('/form-part', body) .map( (res) => { let body = res.json(); if (body.data){ return body.data; } } ); } I have a variable number of form part to submit depending if they are dirty or

Polling server after each server response + delay

巧了我就是萌 提交于 2020-01-15 07:45:11
问题 I am working on an effect, that will be polling server. What I want to achieve is as follows: 1) Send GET request to server 2) After response is received, wait 3 seconds 3) Send same GET request 4) After response is received, wait 3 seconds 5) Send same GET request ... and so on. The code that I have now, doesn't quite work, as it polls server every 3 seconds, no matter if response was received or not: @Effect() pollEntries$ = this.actions$.pipe( ofType(SubnetBrowserPageActions

Why Observable.race not working if one of observable stop emit events?

主宰稳场 提交于 2020-01-15 04:54:17
问题 I'd like to implement websocket reconnect in webapp if internet connection is lost. In order to detect that internet is lost I use ping-pong approach, which means that I send from client ping-message and server returns me pong-message. When webapp loaded I send init ping message and start to listen a reply on socket some kind of this: this.websocket.onmessage = (evt) => { try { const websocketPayload: any = JSON.parse(evt.data); if (websocketPayload.pong !== undefined && websocketPayload.pong

Why Observable.race not working if one of observable stop emit events?

对着背影说爱祢 提交于 2020-01-15 04:54:06
问题 I'd like to implement websocket reconnect in webapp if internet connection is lost. In order to detect that internet is lost I use ping-pong approach, which means that I send from client ping-message and server returns me pong-message. When webapp loaded I send init ping message and start to listen a reply on socket some kind of this: this.websocket.onmessage = (evt) => { try { const websocketPayload: any = JSON.parse(evt.data); if (websocketPayload.pong !== undefined && websocketPayload.pong

Type 'boolean' is not assignable to type 'ObservableInput<{}>'

余生长醉 提交于 2020-01-15 04:40:39
问题 I am working on angular 6 project. I am using canDeactivate for my routeGuards and a popup to show route leave message. But the issue is coming at my price-list-guard-service on hover .flatMap(isAllow)=> { Error: Argument of type '(isAllow: boolean) => boolean' is not assignable to parameter of type '(value: boolean, index: number) => ObservableInput<{}>'.. I wanted to do something like this in price-list-guard.service.ts: price-list-guard.service.ts @Injectable() export class

RXJS - multiple consecutive http requests

限于喜欢 提交于 2020-01-15 04:40:09
问题 source<http> .pipe( switchMap(d => this.http.get(d)) .pipe( switchMap(j => this.http.get(j)) ) ) .subscribe() Hello, I need to make 3 http requests consecutively where each call contains data for the next call.. are nested switch maps the best practice for this case? 回答1: You don't need to nest them. You can simply chain them: source<http> .pipe( switchMap(d => this.http.get(d)), switchMap(j => this.http.get(j)) ) .subscribe() Apart from that, using multiple switchMap is the way to go. 回答2:

Take first elements of stream after previous element matches condition

核能气质少年 提交于 2020-01-15 03:31:05
问题 I'm new to reactive extensions (rx) and try to do the following thing in .NET (but should be the same in JS and other languages.): I have a stream incoming with objects containing a string and a bool property. The stream would be infinite. I have the following conditions: The first object should always be printed. Now all incoming objects should be skipped until an object arrives with the bool property set to "true". When an object arrives with the bool property set to "true", this object

Loading indicator on Http requests

三世轮回 提交于 2020-01-15 02:37:28
问题 The root of my problem is displaying a loading indicator on http requests, and I want to do it at the service level without having to write code for each component. What I did was implement an http wrapper that basically does this: getMyHttpObservable(...) { setLoadingIndicator(true); const myHttpObservable = createRequestObservable().finally(()=> { console.log('http done'); setLoadingIndicator(false); }); return myHttpObservable; } I have a sequence of observables which I chain using