rxjs

Recursive function with timeout and check RxJs Observable value polling

牧云@^-^@ 提交于 2020-06-16 17:57:51
问题 I have the recursive function: repeatAlert that is called again if data.answered === null : .... Edit this.repeatAlert(id).subscribe( val => console.log(val)); console.log('1stCall Alert: ', new Date().getMinutes()); .... find(id: number): Observable<any> { return this.http.get(`${this.resourceUrl}ByAlertId/${id}` } repeatAlert(id: number) { this.find(id).subscribe((data: AlertInt) => { if (data.answered === null ) { this.sendNotification('Alert ', data.text); console.log('Call Alert: ', new

Recursive function with timeout and check RxJs Observable value polling

狂风中的少年 提交于 2020-06-16 17:57:50
问题 I have the recursive function: repeatAlert that is called again if data.answered === null : .... Edit this.repeatAlert(id).subscribe( val => console.log(val)); console.log('1stCall Alert: ', new Date().getMinutes()); .... find(id: number): Observable<any> { return this.http.get(`${this.resourceUrl}ByAlertId/${id}` } repeatAlert(id: number) { this.find(id).subscribe((data: AlertInt) => { if (data.answered === null ) { this.sendNotification('Alert ', data.text); console.log('Call Alert: ', new

You provided `undefined` where a stream was expected in Redux Observable

那年仲夏 提交于 2020-06-16 17:17:49
问题 Trying to wrap my head around RxJS and redux observable I have this: export const getSomeData = (action$) => action$.pipe( ofType(GET_USER_DATA), mergeMap((action) => getData(action.id)), map(fetchUserFulfilled), catchError((e) => of({ type: 'FAILED_TO_FETCH_DATA', e, }), ), ) which works good, but now I want to actually fire 2 observables when I get the data back so I tried this: export const getSomeData = (action$) => action$.pipe( ofType(GET_USER_DATA), mergeMap((action) => getData(action

You provided `undefined` where a stream was expected in Redux Observable

情到浓时终转凉″ 提交于 2020-06-16 17:17:38
问题 Trying to wrap my head around RxJS and redux observable I have this: export const getSomeData = (action$) => action$.pipe( ofType(GET_USER_DATA), mergeMap((action) => getData(action.id)), map(fetchUserFulfilled), catchError((e) => of({ type: 'FAILED_TO_FETCH_DATA', e, }), ), ) which works good, but now I want to actually fire 2 observables when I get the data back so I tried this: export const getSomeData = (action$) => action$.pipe( ofType(GET_USER_DATA), mergeMap((action) => getData(action

Parallel http requests via forkJoin and response identification

和自甴很熟 提交于 2020-06-16 17:01:11
问题 I would like to make parallel independent calls to an endpoint. First I construct my calls then I call forkJoin . getAllDirections(data: Object, date: string) { let urls = []; for (let elm in data) { let url = `http:XXXXX?date=${date}&directions=${data[elm].All.join()}`; urls.push(this.http.get<ISchedules>(url)); } return forkJoin(urls).pipe( map(dirData => { let dataSorted = dirData.map(elm => _.groupBy(elm.data, 'direction')); return dataSorted; }) ); } the data params is an objects of

Using rxjs to throttle a callback

ⅰ亾dé卋堺 提交于 2020-06-16 02:23:07
问题 I am consuming an API in which I register a callback that occurs frequently. function myCallback(event) { // do things with event, something computationally intensive } const something = createSomething({ onSomethingHappened: myCallback }) I'd like to limit the rate at which this callback fires, probably using throttle . This project uses Angular which bundles rx. How can I adapt my code so myCallback it throttled at 300ms using rx? I have a basic grasp on how observables work but it's been a

Best way to chain observable subscriptions in Angular?

半腔热情 提交于 2020-06-14 06:41:07
问题 I have always nested subscriptions when I need to call a resource after getting the result of another one, like so: this.paymentService.getPayment(this.currentUser.uid, this.code) .valueChanges() .subscribe(payment => { this.payment = payment; this.gymService.getGym(this.payment.gym) .valueChanges() .subscribe(gym => { this.gym = gym; }); }); I am using Angular v6 and AngularFire2. Both endpoints (getPayment and getGym) return objects. Is there any more elegant way to do this without nesting

Why rxjs debounceTime does not work on observables created using 'of' operator?

为君一笑 提交于 2020-06-12 10:39:22
问题 Using angular 7 and rxjs 6 : <input (input)="onChange($event.target.value)"> Why the following does not debounce? onChange(val: string) { of(val) .pipe( debounceTime(300) ).subscribe(valx => { console.log(valx); }); } But this does: searchTerm$: Subject<string> = new Subject(); this.searchTerm$.pipe( debounceTime(300), ).subscribe(val => { console.log(val); }); onChange(val: string) { this.searchTerm$.next(val); } 回答1: This isn't because of of() . In your first example every time you call

RxJS, Observable, how to preserve value and switch map to another one

这一生的挚爱 提交于 2020-06-11 01:22:11
问题 // ticker$ will update every 3s // showHand$ will only triger after user click button // I would like to take last ticker price as user order price when user click button let lastPrice: number; this.ticker$ // What I am doing now is preserve value to vairable here. .do(ticker => lastPrice = ticker.closePrice) .switchMap(() => this.showHand$) .subscribe(showHand => { // use value here this.order.price = lastPrice; this.order.amount = showHand.amount; this.order.type = showHand.type; this

Combine two or more (boolean) observables on single ngIf using async pipe

半腔热情 提交于 2020-06-10 09:09:33
问题 Without observables I can write the following line in the HTML template: <div *ngIf="(myVarA || myVarB) && myVarC !== x"></div> How do I translate this line if all myVar variables are now actually observables? <div *ngIf="((myVarA | async) || (myVarB | async)) && (myVarC | async) !== x"> does not work. In another question (Putting two async subscriptions in one Angular *ngIf statement) the possibility to combine two or more observables into one ngIf can be achieved like <div *ngIf="{ a: