rxjs

Why Aren't FormControl#valueChanges' Subscriptions Garbage Collected?

北城以北 提交于 2020-05-13 07:10:35
问题 I have gone through plenty of threads saying that one needs to unsubscribe from FormControl#valueChanges to prevent memory leaks. I understood the "when" and "how" to unsubscribe from Observable s. As I understand, Observables that produce infinite number of values need to be unsubscribed and FormControl#valueChanges is one such Observable . But my question is, why aren't these Observables s garbage collected? I mean when an Angular component gets destroyed, the references are dead right? The

Why Aren't FormControl#valueChanges' Subscriptions Garbage Collected?

心已入冬 提交于 2020-05-13 07:10:30
问题 I have gone through plenty of threads saying that one needs to unsubscribe from FormControl#valueChanges to prevent memory leaks. I understood the "when" and "how" to unsubscribe from Observable s. As I understand, Observables that produce infinite number of values need to be unsubscribed and FormControl#valueChanges is one such Observable . But my question is, why aren't these Observables s garbage collected? I mean when an Angular component gets destroyed, the references are dead right? The

Angular - RxJs ForkJoin How To Continue Multiple Requests Even After A Error

走远了吗. 提交于 2020-05-13 04:56:05
问题 I am querying a single API endpoint multiple times except with different parameters. For what ever reason some of these requests may fail and return a 500 error. If they do i still want the other requests to carry on and return me the data of all the successfull requests. let terms = []; terms.push(this.category.category); terms = terms.concat(this.category.interests.map((x) => x.category)); for (let i = 0; i < terms.length; i++) { const params = { term: terms[i], mode: 'ByInterest' }; const

Observable.combineLatest continue even if one fails

有些话、适合烂在心里 提交于 2020-05-13 04:39:25
问题 I have a function that needs to resolve multiple documents from firebase fetchDocuments(documentIds: string[]): Observable<TreeNodeDocument[]> { const observables = []; for(let id of documentIds){ observables.push(this.fetchDocument(id)); } return Observable.combineLatest(observables, (...docs: TreeNodeDocument[]) => { //some transformations on the resolved documents return docs; }); } this.fetchDocument(id) returns an observable of type TreeNodeDocument . This function works as long as all

What is the difference between the isStopped and closed property of the Subject class?

筅森魡賤 提交于 2020-05-12 15:48:23
问题 The class Subject has 2 properties closed and isStopped . I know that closed can be used to check whether the Subject can still be subscribed to, but what should isStopped be used for exactly? I am asking this because i am trying to find a way to know when a next operation of a BehaviourSubject is completed. Can i use isStopped for that or is it used for something else? 回答1: The compared behavior of closed and isStopped can be seen in terms of resultant values after each operation: On error:

What is the difference between the isStopped and closed property of the Subject class?

牧云@^-^@ 提交于 2020-05-12 15:47:51
问题 The class Subject has 2 properties closed and isStopped . I know that closed can be used to check whether the Subject can still be subscribed to, but what should isStopped be used for exactly? I am asking this because i am trying to find a way to know when a next operation of a BehaviourSubject is completed. Can i use isStopped for that or is it used for something else? 回答1: The compared behavior of closed and isStopped can be seen in terms of resultant values after each operation: On error:

SwitchMap operator with an array

跟風遠走 提交于 2020-05-12 04:54:48
问题 I'm trying to learn rxjs and the Observable concept in general and have a scenario where I have a class of <Room>{} where <Player>{} can join in many-to-many relationship style. In Firestore I have collection of rooms where each room has a property called players which is an array of user uid s. When a rooms component is created I subscribe to _roomService.getPlayersInRoom(roomId) which looks like below: getPlayersInRoom(roomId: string) { return this._db.doc<Room>(`rooms/${roomId}`)

How to propagate errors through catchError() properly?

柔情痞子 提交于 2020-05-10 03:58:50
问题 I wrote a function that is pipe -able: HandleHttpBasicError<T>() { return ((source:Observable<T>) => { return source.pipe( catchError((err:any) => { let msg = ''; if(err && err instanceof HttpErrorResponse) { if(err.status == 0) msg += "The server didn't respond"; } throw { err, msg } as CustomError }) ) }) } I can use this function this way in my HttpService : checkExist(id:string) { return this.http.head<void>(environment.apiUrl + 'some_url/' + id) .pipe( HandleHttpBasicError(), catchError(

How to propagate errors through catchError() properly?

送分小仙女□ 提交于 2020-05-10 03:58:05
问题 I wrote a function that is pipe -able: HandleHttpBasicError<T>() { return ((source:Observable<T>) => { return source.pipe( catchError((err:any) => { let msg = ''; if(err && err instanceof HttpErrorResponse) { if(err.status == 0) msg += "The server didn't respond"; } throw { err, msg } as CustomError }) ) }) } I can use this function this way in my HttpService : checkExist(id:string) { return this.http.head<void>(environment.apiUrl + 'some_url/' + id) .pipe( HandleHttpBasicError(), catchError(

How to use valueChanges() instead of get() to download data with JSON string?

∥☆過路亽.° 提交于 2020-04-30 06:31:25
问题 I have a form with two different buttons, one to download data (from Firestore) and one to display it in realtime. For this I have two functions (Angular 8), where one uses valueChanges() to display data in realtime and the other uses get() to get the same data and download it. The user can choose to specify search more or less, so I have quite a lot of code for making the query and this needs to be doubled if I am to use both get() and valueChanges() . I am therefore wondering if someone can