Skip to content

Commit 804dc4c

Browse files
committed
fix: show an error message if there is an error
1 parent a1e81c4 commit 804dc4c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inject, Injectable } from '@angular/core';
2-
import { merge, Observable, of } from 'rxjs';
3-
import { LocalDBService, TopicType } from './localDB.service';
2+
import { forkJoin, map, Observable, of } from 'rxjs';
3+
import { Info, LocalDBService, TopicType } from './localDB.service';
44

55
@Injectable({ providedIn: 'root' })
66
export class AppService {
@@ -9,11 +9,16 @@ export class AppService {
99
getAllInfo = this.dbService.infos;
1010

1111
deleteOldTopics(type: TopicType): Observable<boolean> {
12+
const deleteTopics = (infoByType: Info[]) => {
13+
const results$ = infoByType.map((t) =>
14+
this.dbService.deleteOneTopic(t.id),
15+
);
16+
return forkJoin(results$).pipe(
17+
map((results) => results.every((value) => value === true)),
18+
);
19+
};
20+
1221
const infoByType = this.dbService.searchByType(type);
13-
return infoByType.length > 0
14-
? infoByType
15-
.map((t) => this.dbService.deleteOneTopic(t.id))
16-
.reduce((acc, curr) => merge(acc, curr), of(true))
17-
: of(true);
22+
return infoByType.length > 0 ? deleteTopics(infoByType) : of(true);
1823
}
1924
}

apps/rxjs/11-high-order-operator-bug/src/app/localDB.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { of } from 'rxjs';
55

66
export type TopicType = 'food' | 'book' | 'sport';
77

8-
interface Info {
8+
export interface Info {
99
id: number;
1010
topic: TopicType;
1111
}

0 commit comments

Comments
 (0)