rxjs

ReduxObservable cancellation based on action type and its data

我的梦境 提交于 2019-12-11 16:54:47
问题 I have React app which uses redux-observable with typescript. In this scenario, FetchAttribute Action gets triggered with a id and then make an ajax call. In certain case, I would want to cancel the ajax request if "FETCH_ATTRIBUTE_CANCEL" action was triggered with the same id as of "FetchAttributeAction" action. action$.ofType(FETCH_ATTRIBUTE) .switchMap((request: FetchAttributeAction) => { return ajax.getJSON(`/api/fetch-attribute?id=${request.id}`) .flatMap((fetchUrl) => { // return new

Queuing function using RxJS

萝らか妹 提交于 2019-12-11 16:36:55
问题 I'm using rxjs with NodeJS in backend. I have a Rest API which allow consumers to run remote yarn installation process. The install function returns an observable of the process. So when the module is installed successfully it emits a value in the observable and complete. At this point, the Rest API will returns a response to the user to say that the installation is successful. In case that the installation fails, the process will throw an Error in the stream and the Rest API returns another

Redux-observable: how to wait for multiple async requests then perform action in an epic

让人想犯罪 __ 提交于 2019-12-11 16:15:26
问题 I'd like to wait for the two http requests below to finish before triggering another action. However, the http requests were not fired. Only the DASHBOARD_INIT action was triggered: export const dashboardInitEpic = (action$: any) => action$.ofType(InitActionTypes.DASHBOARD_INIT) .switchMap((action: ActionDashboardInit) => zip$( of$(fetchConfig(action.payload)), of$(fetchPermission(action.payload)) ).switchMap(() => zip$( action$.ofType(ActionTypes.FETCH_CONFIG_FULFILLED).take(1), action$

AngularFire2 group data into array of objects Firestore collection

╄→гoц情女王★ 提交于 2019-12-11 15:52:33
问题 I have a collection called addons . The collection contains fields namely, name , desc , price and type . I am straight away fetching the data with this.afs.collection<AddOns>('addons'); which returns AngularFirestoreCollection<AddOns> . I have below class file defined for data from Firestore Collection. AddOns.ts export class AddOns{ name?: string; desc?: string; price?: number; type?: string; } export class AddOnId extends AddOns{ aid?: string; } Since I need metadata too from that

passing concatMap result in to next concatMap in rxjs

扶醉桌前 提交于 2019-12-11 15:45:30
问题 You can see I have a method , which is working fine as I expected loadTemplates(configUrl: any, templateId: string): Observable<any> { this.getConfiguration(configUrl) .pipe( concatMap(configResponse => this.getTemplate( CONFIGURATION_URL + "templates/" + configResponse.TemplateSettings.RootTemplate.Path, configResponse ) ), concatMap(rootTemplate => this.templateEngine.getAllChildTemplates(rootTemplate) ), concatMap(childTemplates=>this.templateEngine.createTemplateToRender(childTemplates,""

Angular RxJS: two nested https and update component when first one is reach

吃可爱长大的小学妹 提交于 2019-12-11 15:40:05
问题 I need to perform two http requests. One after first one, since values provided by first one are going to be used to make the other http calls. I also need to update my component when first http is resolved. And also, updated it when second http is also resolved . interface Vehicle { readonly id: string; readonly name: string; readonly brand: string; } First http call is getting name , and the other one the brand . Guess this html component: <div *ngFor='let vehicle of vehicles$ | async'> {

Unsubscribe from Angular's Location service

*爱你&永不变心* 提交于 2019-12-11 15:37:54
问题 I'm using Angular's (v5.2.2) Location service to track URL changes in a specific component. ngOnInit(): void { this.location.subscribe(event => { if (event.type === 'hashchange') { this.doSomething(); } }); } I want to unsubscribe from the Location events when the component is destroyed. ngOnDestroy(): void { this.location.unsubscribe(); } But I get the error: this.location.unsubscribe is not a function The problem is that the code continues to be executed when the URL is changed, even

rxjs unit test with retryWhen

南楼画角 提交于 2019-12-11 15:35:40
问题 I have the following method and I need to write some unit tests for it, but I cannot mock the response, I've tried using the TestScheduler but it was not successful, any help would be appreciated. I'm using jest. protected waitForResponse(id: number, requestId: string) { return this.service.getData(id, requestId) .pipe( mergeMap((resp: ResponseModel) => { if (resp.status !== 'WAITING') { return of(resp); } return throwError(resp); }), retryWhen(errors => errors.pipe( concatMap((e, i) => iif(

RXjs groupBy - Group AngularFire Firestore collection

拜拜、爱过 提交于 2019-12-11 15:29:40
问题 I'm trying to group a AngularFire Firestore Collection (Observable[]) by a field, say userId . I have a collection of items, each with varying userId values, and I need to group them into a multidimensional array. So, convert.. [ {userID:1, color:'blue' }, {userId:2, color:'green'}, {userId:1, color:'orange'} ] into [ [ {userID:1, color:'blue' }, {userId:1, color:'orange'} ], [ {userId:2, color:'green'} ] ] I'm totally new to RxJs, I get how the groupBy operator works when making an

Share data between components with Subject

僤鯓⒐⒋嵵緔 提交于 2019-12-11 15:15:40
问题 I am trying to share data between two components in Angular 6 with Subject. Somehow it does not work and I can not find out why. I need to pass data from compare.component to profile.component with click. When I click, data is not passed. But somehow when I go back and then click again, it works. What do I do wrong? data.service import {Subject} from 'rxjs'; export class DataService { data = new Subject(); } profile.component export class ProfileComponent implements OnInit { constructor