rxjs

How to handle/queue multiple same http requests with RxJs?

点点圈 提交于 2020-01-01 06:00:13
问题 I am making an Angular 4 app. Components are subscribing Observable. Sometimes Observable call the same url. For example 'refresh Access Token' if needed before any http request. But if I make different 3 http requests, it will "refresh if needed" 3 times the refresh token. So how to make only one http get to get a refreshed access token, and make the other observables 'wait' for the first one ? (I know 'wait' is not the good word for Observables). public get(url: string, options?:

Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'

我怕爱的太早我们不能终老 提交于 2020-01-01 05:22:06
问题 Im Getting following error while trying to pass header in HTTP.POST/GET request Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'. Property 'null' is missing in the type '{header:Header;}' I have try many solutions but no lock on it. here my code : import { Injectable } from '@angular/core'; import { Response, RequestOptions, Headers, Http, URLSearchParams} from '@angular/http'; import { Observable, Subject } from 'rxjs/Rx'; import {Company} from

Is RxJS faster than imperative? [closed]

我怕爱的太早我们不能终老 提交于 2020-01-01 04:44:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I'm newer in functional programming and functional reactive programming. I read a lot of times the great power of functional reactive programming . Okey; is readable, avoid side effects, etc. But... I don't know how to improve my code in functional/reactive way to execute faster

How to load RxJS in a minimal Angular 2 app using systemjs?

末鹿安然 提交于 2020-01-01 04:29:09
问题 I'm unable to get a minimal Angular 2 application using RxJS off the ground. I'm using Typescript (tsc 1.6.2) and systemjs for module loading. How do I get systemjs to load the Rx module correctly? I've run out of ideas to try and I'd appreciate any pointer to what I'm doing wrong. Module loading is a bit of magic to me. Very frustrating. index.html : <!DOCTYPE html> <html> <head> <title>Title</title> <script src="../node_modules/es6-shim/es6-shim.js"></script> <script src="../node_modules

How to return value inside subscribe Angular 4

给你一囗甜甜゛ 提交于 2020-01-01 04:04:28
问题 I'm new to observables in angular. I have a problem wanting to return a value inside a subscribe method. I have the following method ( getFirebaseData(idForm:string):observable <any[]> ): getTotalQuestions(idForm:string){ let totalQuestions:number; this.getFirebaseData(idForm+"/Metadatos") .subscribe(items => { items.map(item => { totalQuestions=item.Total; console.log(totalQuestions); }); } ); console.log(totalQuestions); return totalQuestions; } the firts console.log(totalQuestions) print 4

Angular 4 display current time

随声附和 提交于 2019-12-31 20:43:34
问题 What is the correct (canonical) way to display current time in angular 4 change detection system? The problem is as follows: current time changes constantly, each moment, by definition. But it is not detectable by Angular 4 change detection system. For this reason, in my opinion, it's necessary to explicitly call ChangeDetectorRef::detectChanges . However, in the process of calling this method, current time naturally changes its value. This leads to ExpressionChangedAfterItHasBeenCheckedError

Angular 4 display current time

橙三吉。 提交于 2019-12-31 20:41:26
问题 What is the correct (canonical) way to display current time in angular 4 change detection system? The problem is as follows: current time changes constantly, each moment, by definition. But it is not detectable by Angular 4 change detection system. For this reason, in my opinion, it's necessary to explicitly call ChangeDetectorRef::detectChanges . However, in the process of calling this method, current time naturally changes its value. This leads to ExpressionChangedAfterItHasBeenCheckedError

RxJs: poll until interval done or correct data received

无人久伴 提交于 2019-12-31 12:18:44
问题 How do i execute the following scenario in the browser with RxJs: submit data to queue for processing get back the job id poll another endpoint every 1s until result is available or 60seconds have passed(then fail) Intermediate solution that i've come up with: Rx.Observable .fromPromise(submitJobToQueue(jobData)) .flatMap(jobQueueData => Rx.Observable .interval(1000) .delay(5000) .map(_ => jobQueueData.jobId) .take(55) ) .flatMap(jobId => Rx.Observable.fromPromise(pollQueueForResult(jobId)))

What does the `map` method mean in RxJS?

做~自己de王妃 提交于 2019-12-31 09:16:10
问题 I'm learning RxJS by reading this tutorial http://reactive-extensions.github.io/learnrx/ . I have a hard time understanding the map method of Observable . The Array version of map is really simple and straightforward. I have no idea about what exactly the map means in case of a Observable (and why does it have a alias named select ?!). Here is what the documentation told me. Might not be helpful for most beginners... Projects each element of an observable sequence into a new form by

What does the `map` method mean in RxJS?

…衆ロ難τιáo~ 提交于 2019-12-31 09:16:02
问题 I'm learning RxJS by reading this tutorial http://reactive-extensions.github.io/learnrx/ . I have a hard time understanding the map method of Observable . The Array version of map is really simple and straightforward. I have no idea about what exactly the map means in case of a Observable (and why does it have a alias named select ?!). Here is what the documentation told me. Might not be helpful for most beginners... Projects each element of an observable sequence into a new form by