rxjs

RX.JS Redux Observable Multiple Get requests at same time

蓝咒 提交于 2020-05-15 10:19:10
问题 I am trying to set up an observable that currently receives an array of location IDs and then makes a get request for all of these at once and waits for the response for them all. Here is a sample: const fetchPhotosEpic = action$ => action$.ofType(LOCATIONS_RECEIVED) .map(action => action.payload) .mergeMap((data) => { let promiseArray = data.map(location => Observable.fromPromise(axios.get(photosUrl(location.id)))) return Observable.forkJoin( promiseArray ) }) .map(responses => responses.map

Filtering a BehaviorSubject

坚强是说给别人听的谎言 提交于 2020-05-15 06:43:30
问题 I have a BehaviorSubject that I'd like to be able to filter , but maintain it's behavior-subject-like quality that new subscribers always get a value when they subscribe, even if the last value emitted was filtered out. Is there a succinct way to do that using built-in functions from rxjs? For example: const isEven = (n) => n % 2 === 0; const source = new BehaviorSubject(1); const stream = source.pipe(filter(isEven)); stream.subscribe((n) => console.log(n)); // <- I want this to print `1`

Filtering a BehaviorSubject

萝らか妹 提交于 2020-05-15 06:43:06
问题 I have a BehaviorSubject that I'd like to be able to filter , but maintain it's behavior-subject-like quality that new subscribers always get a value when they subscribe, even if the last value emitted was filtered out. Is there a succinct way to do that using built-in functions from rxjs? For example: const isEven = (n) => n % 2 === 0; const source = new BehaviorSubject(1); const stream = source.pipe(filter(isEven)); stream.subscribe((n) => console.log(n)); // <- I want this to print `1`

How to make observable debounceTime conditional

时光毁灭记忆、已成空白 提交于 2020-05-15 05:34:05
问题 I have a simple debounce on an element input event like so: Observable .fromEvent(this.elInput.nativeElement, 'input') .debounceTime(2000) .subscribe(event => this.onInput(event)); I would like to make the debounce conditional based on the value of the event when emitted, is this possible? Thanks 回答1: Yes, that's completely possible. Just make use of the debounce operator instead of debounceTime . It is passed a selector function that receives the previous operators notifaction when invoked.

Sequential cascade Observables according result from previous response and remap to new data object

六月ゝ 毕业季﹏ 提交于 2020-05-15 05:09:50
问题 I have difficulties using the power of Observables i.e. RxJs 6 to correctly pipe, tap, map, mergemap or whatever my HttpClient requests. The version hell with all the different functions makes it not very easy... So what I need is to first make a REST call, then depending on the result probably do a second REST call and map the potentially two received data objects in one new data object. The function should return an Observable . So currently, I solved it with a subject that I am be able to

Sequential cascade Observables according result from previous response and remap to new data object

纵然是瞬间 提交于 2020-05-15 05:07:27
问题 I have difficulties using the power of Observables i.e. RxJs 6 to correctly pipe, tap, map, mergemap or whatever my HttpClient requests. The version hell with all the different functions makes it not very easy... So what I need is to first make a REST call, then depending on the result probably do a second REST call and map the potentially two received data objects in one new data object. The function should return an Observable . So currently, I solved it with a subject that I am be able to

Do I need to unsubscribe from an Observable if the Observable is finished with?

纵然是瞬间 提交于 2020-05-14 05:56:29
问题 Let us say I have an Observable (hot, doesn't complete), and I subscribe to it. Ordinarily when I am finished with the Subscription I have to unsubscribe it to prevent memory leaks. let subject$ = new Subject(); const sub = subject$.subscribe(...); ... // Need to call sub.unsubscribe() when we are finished sub.unsubscribe(); sub = null; But if instead of just being finished with the Subscription I am also finished with the Observable ( Subject ) and I remove all reference to both, do I need

Angular 7: Custom Async Validator

我与影子孤独终老i 提交于 2020-05-14 05:47:29
问题 I'm trying to create a custom async validator for my registration form where it checks if an email already exists. The backend returns 404 if the email does not exist and 200 if it does exist (can't change this old code). I have found a couple tutorials but didn't find one using the latest rxjs library. I created this Validation class: export class UniqueEmailValidator { static createValidator(httpClient: HttpClient, degree: number, wlId: number) { return (control: AbstractControl) => {

Angular 7: Custom Async Validator

£可爱£侵袭症+ 提交于 2020-05-14 05:45:41
问题 I'm trying to create a custom async validator for my registration form where it checks if an email already exists. The backend returns 404 if the email does not exist and 200 if it does exist (can't change this old code). I have found a couple tutorials but didn't find one using the latest rxjs library. I created this Validation class: export class UniqueEmailValidator { static createValidator(httpClient: HttpClient, degree: number, wlId: number) { return (control: AbstractControl) => {

Wait until two Observables are complete

我的未来我决定 提交于 2020-05-13 18:14:06
问题 I want to call a method after two Observables have returned values. I did some searching and it seems like forkJoin is what I want, but I can't get it to work. I know both of these Observables are returning values, as I am using the data for each individually elsewhere in the component, so clearly I'm doing something else wrong. Here is what I tried. I'm using rxjs v6.4. forkJoin( this.store.pipe(select(fromStore.getAppointmentsLoading)), this.clientStore.pipe(select(fromClientStore