rxjs

FormControl distinctUntilChanged() not working

跟風遠走 提交于 2019-12-11 06:29:24
问题 I'm having a hard time making distinctUntilChanged work in this next scenario. I made an asynchronous validator, which uses a service to check if a user exists with the given username. This validator is bound, as a directive, to an input. class ValidateUniqueUsernameDirective implements AsyncValidator { constructor(private userService: UserService) {} validate( control: AbstractControl ): Promise<ValidationErrors> | Observable<ValidationErrors> { return control.valueChanges.pipe( debounceTime

Combining multiple FirebaseListObservables

牧云@^-^@ 提交于 2019-12-11 06:27:33
问题 const placeId = this.getPlaceId(); this.af.database.list(`placeUsers/${placeId}`).subscribe((userKeys) => { for (let index = 0; index < userKeys.length; index++) { let userKey = userKeys[index]; this.af.database.list(`userDevices/${userKey.$key}`).subscribe((deviceKeys) => { for (let index = 0; index < deviceKeys.length; index++) { let deviceKey = deviceKeys[index]; this.af.database.object(`devices/${deviceKey.$key}`).subscribe((device) => { console.log(device); // Device received. }); } });

How to refactor a subscribe inside a subscribe in rxjs

左心房为你撑大大i 提交于 2019-12-11 06:20:00
问题 For example: this.saveSubscription$ = this.ds.onSave$.subscribe(x => this.sb.updateMachineTool(this.viewEditModel.viewEditModel).subscribe(x = { console.log('alert results', x) }) ) this.ds.onSave$ is a subject that triggers when a save button on a different component is clicked. this.sb.updateMachineTool is an httpClient post that updates a specific tool should I be using some type of map so i'm not subscribing to both areas? How can I refactor this code? 回答1: To Refactor your code You can

RxJS: Backpressure with switchMap producing N values

折月煮酒 提交于 2019-12-11 06:18:14
问题 I am talking to some RESTful search endpoint that involves pagination. The query is triggered by user typing in a search field, and as a result it produces an Observable with N values, corresponding to the N result pages. The code looks somewhat like the following: function runQueries(queryObservable) { return queryObservable .debounceTime(500) .distinctUntilChanged() .switchMap(search); } function search(query) { return Observable.create(observer => searchInto(observer, query, 0)); }

Migration Angular 5 to angular 7

牧云@^-^@ 提交于 2019-12-11 06:08:35
问题 I have migrated from angular 5 to Angular 7. After that I have a problem with my RxJs operation like observable and my @ngrx/store. Here is my error: ERROR in node_modules/@ngrx/store/src/actions_subject.d.ts(2,10): error TS2305: Module C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'. node_modules/@ngrx/store/src/reducer_manager.d.ts(2,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye

Angular RxJs timer pausing on IE11

陌路散爱 提交于 2019-12-11 06:03:50
问题 I have a timer that periodically pumps data into the main page of my Angular4 app. For Chrome, everything is working just fine. However, IE11 will sometimes get into a mode where the Observable, and actually even the Observables that are not on a timer (on other pages), will pump out old data. While Chrome is going along just fine getting new data, IE is stuck with numbers it had from a period of time in the past. When I navigate to other pages, everything is stuck in the past, so all the

Rx.js, handling Chrome Extension webrequest API callback functions

99封情书 提交于 2019-12-11 06:01:25
问题 I'm trying to use Rx.js to handle the flow of Chrome extension webrequest API. Each webrequest addListener() call takes a mandatory callback function as the first parameter. This sends request objects to the function. However, the callback can return a webRequest.BlockingResponse that determines the further life cycle of the request. I'm struggling to handle the blocking response as part of the observable. This code works well for examining all image requests, for example

Posting mutipart/form-data with RxJS ajax

别等时光非礼了梦想. 提交于 2019-12-11 05:53:00
问题 Is it possible to post multipart/form-data with RxJS Ajax observable? I tried to do so by setting Content-Type in ajax settings object like so. import { ajax } from 'rxjs/observable/dom/ajax'; let data = { ad = 'ad_id', image = <HTML5 File object> } let settings = { url: '/some-url', body: data, method: 'post', headers: { 'Content-Type': 'multipart/form-data; boundary=---------2e50046', ... } ... } And used ajax(settings) to post the form However, it does not seem to work when sent to backend

How do I groupBy on a HTTP response?

让人想犯罪 __ 提交于 2019-12-11 05:48:50
问题 I'm getting an array of objects as a HTTP response and I'm trying to group them by a value in the object. As an example let's say I get the following: [ {player: 'Jordy Nelson', team: 'Packers'}, {player: 'Aaron Rogers', team: 'Packers'}, {player: 'Dak Prescott', team: 'Cowboys'}, {player: 'Ezekiel Elliot', team: 'Cowboys'}, {player: 'Joe Flacco', team: 'Ravens'}, {player: 'Julio Jones', team: 'Falcons'}, ] I'm trying to take that response and convert it to an array of objects, containing an

How to convert a sequence of Promises into Rx.Observable with RxJS?

只愿长相守 提交于 2019-12-11 05:47:36
问题 I'm trying to create an Rx.Observable from a chain of Promises with RxJS. The difference from this question is that I have unknown number of Promises, and every Promise depends on the result of the previous one. Basically I have a sequence of pages, connected with "next page" links. What I want the function to do is: Wait for Promise<> Provide the result (fire observer.onNext()) Check if there is a next page link Create next Promise<> with that link Repeat until there are pages remained I