diff --git a/apps/rxjs/11-high-order-operator-bug/src/app/app.service.ts b/apps/rxjs/11-high-order-operator-bug/src/app/app.service.ts index df2269a89..514d5c312 100644 --- a/apps/rxjs/11-high-order-operator-bug/src/app/app.service.ts +++ b/apps/rxjs/11-high-order-operator-bug/src/app/app.service.ts @@ -1,5 +1,5 @@ import { inject, Injectable } from '@angular/core'; -import { merge, Observable, of } from 'rxjs'; +import { filter, from, map, mergeMap, Observable, of, toArray } from 'rxjs'; import { LocalDBService, TopicType } from './localDB.service'; @Injectable({ providedIn: 'root' }) @@ -10,10 +10,16 @@ export class AppService { deleteOldTopics(type: TopicType): Observable { const infoByType = this.dbService.searchByType(type); - return infoByType.length > 0 - ? infoByType - .map((t) => this.dbService.deleteOneTopic(t.id)) - .reduce((acc, curr) => merge(acc, curr), of(true)) - : of(true); + + if (!infoByType.length) { + return of(true); + } + + return from(infoByType).pipe( + mergeMap((topic) => this.dbService.deleteOneTopic(topic.id)), + filter((topic) => !topic), + toArray(), + map((t) => t.length === 0), + ); } }