rxjs

ui.bootstrap.typeahead: how to combine $http with debounce

我怕爱的太早我们不能终老 提交于 2019-12-07 13:40:20
问题 I'd like to take advantage of ui.bootstrap.typeahead because it is excellent. I'm implementing a search of a database that could contain millions of users, so I would really like to be able to debounce keystrokes in the search box before making a call to $http. Otherwise every keystroke will result in a search, and early keystrokes will generate slower searches than later keystrokes, resulting in a clunky user experience. My current effort, which doesn't work, looks like this: JavaScript:

Benefits of async pipe with angular http request

给你一囗甜甜゛ 提交于 2019-12-07 13:09:21
问题 A lot of angular tutorial has suggest to use async pipe for auto unsubsribing observable. What they claim: async pipe is used for auto unsubscribing observer, or else you need to unsubscribe manually What they did: They use angular http to call REST api as an example for async pipe. However, from my understanding, angular HTTP auto unsubscribe the observable. So, async pipe actually did not serve the intended purpose here as the observable will auto unsubscribe even without async pipe. Is

How to start immediately an Angular 2 Observable when using interval

房东的猫 提交于 2019-12-07 12:44:56
问题 I have the following Angular 2 service that is fetching data every 5 seconds: import { Observable } from "rxjs/Rx"; import { Http, Response } from '@angular/http'; @Injectable() export class DataService{ getData():{ return Observable .interval(5000) .flatMap(() => this.http.get('http://some_url')) .map((res: Response) => res.json()) } Is there a way to have this service executing the request at the start? Otherwise it will wait for 5 seconds before the first execution. 回答1: Replace interval

Denormalizing ngrx store- setting up selectors?

冷暖自知 提交于 2019-12-07 12:35:03
问题 I am currently working with a somewhat complicated (deep) structure within an ngrx project. It can be thought of as an array of parent objects, with multiple levels of child objects. It is normalized/flattened on the server side, and my the feature within my store looks something like this: rootObjs: { level1: { byId: { 'lvl1_1': {id: 'lvl1_1', label: '[Lvl 1]: 1', ui_open: true, children: ['lvl2_1', 'lvl2_3']}, 'lvl1_2': {id: 'lvl1_2', label: '[Lvl 1]: 2', ui_open: false, children: ['lvl2_2'

Angular 2 Http RetryWhen

此生再无相见时 提交于 2019-12-07 10:58:31
问题 I'm trying to use retryWhen in HTTP calls. It works perfectly when try to use like this: return this.http.get(`${environment.apiUrl}/track/${this.user.instance._id}/${this.currentPlayer.playlist.id}/next?s=${this.playerCounter}`, options) .timeout(500, new TimeoutError(`Timeout trying to get next track. [instanceId=${this.user.instance._id}]`)) .retryWhen(attempts => { return Observable.range(1, 3).zip(attempts, i => i).flatMap(i => 3 === i ? Observable.throw(attempts) : Observable.timer(i *

What are the differences between Array map and rxjs map

[亡魂溺海] 提交于 2019-12-07 10:48:52
问题 I was wondering what the map on both rxjs and array works the same way. What are the differences between the uses of both the array map method and rxjs map operator? 回答1: Array.map transforms each element of a single array. console.log( [ 1, 2, 3 ].map(x => x * x) ) // log: [ 1, 4, 9 ] In general, RXJS Observables are more like a stream of data, but each data is its own entity. You may choose to store arrays in your Observable, but still, each array is treated like a single entity. Every time

rxjs rate limit (requests per second) and concurrency

这一生的挚爱 提交于 2019-12-07 10:32:30
I am trying to figure out how to write a rate limiter in rxjs. Used to access most apis (twitter, facebook, etc) If not supported by out of the box methods, i would assume a scheduler could be written. For instance highland.js has ratelimit . I don't want to drop any items like with window, sample, etc. var source = Rx.Observable.create(function (observer) { // queue of requests _.each(requests, function(r) { observer.onNext(r); }); observer.onCompleted(); // Any cleanup logic might go here return function () { console.log('disposed'); } }) // what goes here, if built in (e.g. 2 requests per 2

Angular 5 Interceptor - Only call second interceptor after failed retry on first interceptor

别来无恙 提交于 2019-12-07 10:05:26
问题 I am building an angular 5 app where I have 2 interceptors: One to retry failed 504 requests Another to show error messages to users about failed requests I want that the second interceptor only gets called when the error is not 504 or when it is 504 and has already been retried by the first interceptor. I have created a sample with both interceptors: https://stackblitz.com/edit/angular-interceptors-ckbvsb Hope to get some assistance! Thanks UPDATE: Thanks everyone for your assistance! I have

Angular2 rxjs http.request.catch has strange behaviour for some http errors

て烟熏妆下的殇ゞ 提交于 2019-12-07 09:22:55
问题 My http service does not catch correctly some http errors. The catch method has 2 different response objects ( see below ). private fireRequest(request: Request): Observable<any> { return this.http.request(request) .switchMap((response: Response) => { const responseData = response.json() || []; return Observable.of(responseData); }) .catch((response: Response) => { const res2 = response.json(); // filters http errors from status 0 errors if (response.status && response.status > 0) { const res

How to test observables which emit grouped events with rxjs marbles?

六月ゝ 毕业季﹏ 提交于 2019-12-07 09:11:47
问题 According to rxjs marbles documentation the current behaviour for the sync groupings is the following: '(ab)-(cd)': on frame 0, emits a and b then on frame 50, emits c and d From the docs: While it can be unintuitive at first, after all the values have synchronously emitted time will progress a number of frames equal to the number of ASCII characters in the group, including the parentheses Ok, but how do I test an observable like this (using marbles or any other technique): const observable$