Skip to content

Commit 11a918a

Browse files
fix: handle inner subscriptions
1 parent 0f9d5f3 commit 11a918a

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

src/app/layouts/notes/components/notes-archive/notes-archive.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export class NotesArchiveComponent implements OnInit, OnDestroy {
3737
ngOnInit(): void {
3838
this.findSettings();
3939
this.findArchived();
40-
this.notesService.notesUpdated$.pipe(takeUntil(this.destroy$), switchMap(() => {
40+
this.notesService.notesUpdated$.pipe(switchMap(() => {
4141
return this.notesService.findArchived();
42-
})).subscribe(notes => this.notes = notes);
42+
}), takeUntil(this.destroy$)).subscribe(notes => this.notes = notes);
4343
this.handleBackButton();
4444
}
4545

src/app/layouts/notes/components/notes-calendar/notes-calendar.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export class NotesCalendarComponent implements OnInit, ViewWillEnter, ViewWillLe
9595
}
9696

9797
private findCreationDatesOnNotesUpdate(): void {
98-
this.notesService.notesUpdated$.pipe(takeUntil(this.destroy$),
99-
switchMap(() => this.findCreationDates()), switchMap(() => this.findByCreationDate())).subscribe();
98+
this.notesService.notesUpdated$.pipe(switchMap(() => this.findCreationDates()),
99+
switchMap(() => this.findByCreationDate()), takeUntil(this.destroy$)).subscribe();
100100
}
101101

102102
private setHighlightedDates(notesDates: { creationDate: string }[]): void {

src/app/layouts/notes/components/notes-categories-selected-header/notes-categories-selected-header.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ export class NotesCategoriesSelectedHeaderComponent implements OnInit, OnDestroy
122122
return false;
123123
}
124124
const id = this.getSelectedCategories()[0].id;
125-
this.notesCategoryService.existsByIdNotAndName(id, value.nameUpdate).pipe(takeUntil(this.destroy$), switchMap(isPresent => {
125+
this.notesCategoryService.existsByIdNotAndName(id, value.nameUpdate).pipe(switchMap(isPresent => {
126126
if (isPresent) {
127127
throw { isPresent: true };
128128
} else {
129129
return this.notesCategoryService.update(id, value.nameUpdate)
130130
}
131-
})).subscribe({
131+
}), takeUntil(this.destroy$)).subscribe({
132132
next: () => {
133133
this.getSelectedCategories()[0].name = value.nameUpdate;
134134
},

src/app/layouts/notes/components/notes-categories/notes-categories.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ export class NotesCategoriesComponent implements OnInit, OnDestroy {
5151

5252
private getAllCategories(): void {
5353
this.isLoading = true;
54-
this.notesService.count().pipe(takeUntil(this.destroy$), switchMap(notesCount => {
54+
this.notesService.count().pipe(switchMap(notesCount => {
5555
this.totalNotes = notesCount.totalNotes;
5656
return this.notesCategoryService.findAll();
57-
}), map(categories => this.mapCategories(categories)), finalize(() => this.isLoading = false))
57+
}), map(categories => this.mapCategories(categories)), finalize(() => this.isLoading = false), takeUntil(this.destroy$))
5858
.subscribe((categories) => this.categories = categories);
5959
}
6060

@@ -156,13 +156,13 @@ export class NotesCategoriesComponent implements OnInit, OnDestroy {
156156
this.showError(this.translateService.instant("categoryCannotBeEmpty"));
157157
return false;
158158
}
159-
this.notesCategoryService.existsByName(value.nameInsert).pipe(takeUntil(this.destroy$), switchMap(isPresent => {
159+
this.notesCategoryService.existsByName(value.nameInsert).pipe(switchMap(isPresent => {
160160
if (isPresent) {
161161
throw { isPresent: true };
162162
} else {
163163
return this.notesCategoryService.insert(value.nameInsert);
164164
}
165-
})).subscribe(({
165+
}), takeUntil(this.destroy$)).subscribe(({
166166
next: (id) => {
167167
this.categories.push({ id: id, name: value.nameInsert, notesCount: 0, isSelected: false });
168168
},

src/app/layouts/notes/components/notes-list/notes-list.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ export class NotesListComponent implements OnInit, ViewWillEnter, ViewWillLeave
6868
}
6969

7070
private findNotesOnCategorySelection(): void {
71-
this.notesCategoryService.selectedCategory$.pipe(takeUntil(this.destroy$), switchMap((categoryId) => {
71+
this.notesCategoryService.selectedCategory$.pipe(switchMap((categoryId) => {
7272
this.categoryId = categoryId;
7373
return this.findNotes();
74-
})).subscribe(notes => this.notes = notes);
74+
}), takeUntil(this.destroy$)).subscribe(notes => this.notes = notes);
7575
}
7676

7777
private findNotesOnNotesUpdate(): void {
78-
this.notesService.notesUpdated$.pipe(takeUntil(this.destroy$), switchMap(() => {
78+
this.notesService.notesUpdated$.pipe(switchMap(() => {
7979
return this.findNotes();
80-
})).subscribe(notes => this.notes = notes);
80+
}), takeUntil(this.destroy$)).subscribe(notes => this.notes = notes);
8181
}
8282

8383
private findNotes(): Observable<Note[]> {

src/app/layouts/notes/components/notes-save/notes-save.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ export class NotesSaveComponent implements OnInit, OnDestroy, ViewDidEnter {
167167
const creationDate = this.creationDate ? this.creationDate : new Date().toISOString();
168168
const categoryId: number | undefined = this.notesCategoryService.selectedCategory$.value;
169169
this.notesService.insert(creationDate, categoryId)
170-
.pipe(takeUntil(this.destroy$), switchMap(id => {
170+
.pipe(switchMap(id => {
171171
return this.notesService.findById(id);
172-
})).subscribe((note) => {
172+
}), takeUntil(this.destroy$)).subscribe((note) => {
173173
note = note as Note;
174174
this.id = note.id;
175175
this.note = note;
@@ -219,7 +219,7 @@ export class NotesSaveComponent implements OnInit, OnDestroy, ViewDidEnter {
219219
public share(): void {
220220
const value = this.form.value.value ? toHTML(this.form.value.value) : '';
221221
from(Share.canShare())
222-
.pipe(takeUntil(this.destroy$), switchMap((shareResult: CanShareResult) => {
222+
.pipe(switchMap((shareResult: CanShareResult) => {
223223
if (shareResult.value) {
224224
return Share.share({
225225
title: this.form.value.title,
@@ -231,7 +231,7 @@ export class NotesSaveComponent implements OnInit, OnDestroy, ViewDidEnter {
231231
this.isToastOpen = true;
232232
return of()
233233
}
234-
})).subscribe();
234+
}), takeUntil(this.destroy$)).subscribe();
235235
}
236236

237237
}

src/app/layouts/notes/components/notes-trash/notes-trash.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export class NotesTrashComponent implements OnInit, OnDestroy {
3737
ngOnInit(): void {
3838
this.findSettings();
3939
this.findDeleted();
40-
this.notesService.notesUpdated$.pipe(takeUntil(this.destroy$), switchMap(() => {
40+
this.notesService.notesUpdated$.pipe(switchMap(() => {
4141
return this.notesService.findDeleted();
42-
})).subscribe(notes => this.notes = notes);
42+
}), takeUntil(this.destroy$)).subscribe(notes => this.notes = notes);
4343
this.handleBackButton();
4444
}
4545

0 commit comments

Comments
 (0)