rxjs5

Having trouble calling RxJS share using the recommended operator import

落花浮王杯 提交于 2019-12-24 02:56:12
问题 I'm trying to understand the best practice for importing rxjs operators It seems like I should import share this way, but, the following doesn't work because it says share expects 0 arguments. I'm not quite sure how to call share correctly. import { share } from 'rxjs/operators'; ... public currentUser: Observable<User> = share(this.currentUser$.asObservable()); Doing it the old way causes no problems. However I seemed to have read that's not the preferred way to import https://www.learnrxjs

What is switchMap equivalent to in unflattened form?

扶醉桌前 提交于 2019-12-24 02:26:03
问题 If flatMap() is equivalent to map().mergeAll() , then what is switchMap() equivalent to ? 回答1: The switchMap() operator is equivalent to using map().switch() . Since the switch() operator works only with higher-order Observables the preceding map() has to return an Observable. There's no switchAll() operator because the switch() operator already works with higher-order Observables(just like all *all() operators). 来源: https://stackoverflow.com/questions/43165848/what-is-switchmap-equivalent-to

Angular 5.2 & RxJS 5.5 HttpInterceptor retryWhen, but update request?

隐身守侯 提交于 2019-12-24 02:07:27
问题 I am trying to intercept a 401 response, send a refresh token request before trying request again (but with a different header). I have it working except retryWhen does not give me to modify the original request header. So I've been trying to use catchError instead but I cannot seem to execute the request again. Here is my current retryWhen : import {Injectable} from '@angular/core'; import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpErrorResponse } from '@angular/common/http'

Dynamically filtering rxjs stream

泄露秘密 提交于 2019-12-24 01:27:29
问题 I'm using RXJS and I'm looking to dynamically filter the data, but I'm having problems: let numberSource: ReplaySubject<Number> = new ReplaySubject<Number>(); let numberFilter: BehaviorSubject<Number> = new BehaviorSubject<Number>(5); let filteredData = numberSource.filter(n => n < numberFilter.value); numberFilter.subscribe(newFilter => { filteredData = numberSource.filter(n => n < newFilter); filteredData.subscribe(console.log); // <- I think this is wrong }); console.log("A"); filteredData

Debounce and buffer an rxjs subscription

自作多情 提交于 2019-12-24 01:01:36
问题 I have a message queue processor that feeds messages to a service... q.on("message", (m) => { service.create(m) .then(() => m.ack()) .catch(() => n.nack()) }) The service uses an RxJS Observable and subscription to debounceTime() those requests. class Service { constructor() { this.subject = new Subject() this.subject.debounceTime(1000) .subscribe(({ req, resolve, reject }) => someOtherService.doWork(req) .then(() => resolve()) .catch(() => reject()) ) } create(req) { return new Promise(

RxJS subscribe inside subscribe with actions on error

爱⌒轻易说出口 提交于 2019-12-23 22:20:09
问题 I have code with subscribe inside subscribe : this.http.post('/update1', newData).subscribe( (response) => { const r = response.json; const id = r['id']; this.http.post('/update2?id=' + id, newData).subscribe( () => { this.http.post('/update3?id=' + id, newData).subscribe( () => { console.log('success'); }, () => { // revert changes made to update2 this.http.post('/update2', previousValues).subscribe(); // revert changes made to update1 this.http.post('/update1', previousValues).subscribe();

Why button click trigger is different from setTimeout() trigger?

二次信任 提交于 2019-12-23 17:57:57
问题 Consider the following, almost identical, two snippets. The difference is: the first one uses setTimeout() to trigger the event the second one triggers the event when the button is clicked If you check the console, you'll see that the last two lines in Snippet 1 are: App rendering 1 folder(s) Observed js and in Snippet 2 are: Observed js App rendering 1 folder(s) Question: Why is the order reversed? setTimeout() playground Button playground Snippet 1: setTimeout() trigger class App extends

rxjs created observable timeout always errors

主宰稳场 提交于 2019-12-23 17:33:32
问题 ok, so now I'm really puzzled. Executing the following code const created = Rx.Observable.create(observer => { observer.next(42) }) const ofd = Rx.Observable.of(42) const createSub = name => [ val => console.log(`${name} received ${val}`), error => console.log(`${name} threw ${error.constructor.name}`) ] created .timeout(100) .subscribe( ...createSub('created') ) ofd .timeout(100) .subscribe( ...createSub('ofd') ) Prints "created received 42" "ofd received 42" "created threw TimeoutError" I

rxjs bundle from unpkg

て烟熏妆下的殇ゞ 提交于 2019-12-23 15:35:42
问题 I have an angular 2.0.0 (same issue in 2.2.0) project. The current dev build generates > 100 http requests. This is due to it loading non-bundled versions of rxjs.. When I have the following : map: { // our app is within the app folder app: 'app', // angular bundles // snip 'rxjs': 'npm:rxjs', 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api', }, The app works but we have 1000+ http requsts , so I try to load rxjs from the bundle, todo this I remove rxjs': 'npm:rxjs' and I add the

RXJS: TypeError: this._subscribe is not a function

核能气质少年 提交于 2019-12-23 07:36:12
问题 I'm migrating an ionic 3.8 app to 3.9.2. This migration includes an update to RXJS 5.5 I'm now experiencing this error: TypeError: this._subscribe is not a function. (In 'this._subscribe(sink)', 'this._subscribe' is an instance of t) After hours of debugging, I found out that this code portion is related to the error: protected observeConnectionState() { // rxjs/observable/of of(new Event('disconnect')) .pipe( // rxjs/operators/merge merge(connect$), merge(disconnect$), // Map eventname to