Skip to content

Commit 3e01e9e

Browse files
authored
Merge pull request #8 from NisanurBulut/dev-harrypotterrefactor
avoided memory link with takeuntil
2 parents 0ae1f59 + 3fe2487 commit 3e01e9e

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

HarryPotter/src/app/components/books/books.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IBookType } from 'src/app/models';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-books',
@@ -9,8 +11,12 @@ import { IBookType } from 'src/app/models';
911
})
1012
export class BooksComponent implements OnInit {
1113
books:Array<IBookType>=[];
14+
unSubscribeAll = new Subject<any>();
1215
constructor(private appService:AppService) {
1316
this.appService.getBooks()
17+
.pipe(
18+
takeUntil(this.unSubscribeAll)
19+
)
1420
.subscribe(data => {
1521
this.books=data;
1622
});

HarryPotter/src/app/components/characters/characters.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IPersonType } from 'src/app/models/personItem.model';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-characters',
@@ -9,8 +11,12 @@ import { IPersonType } from 'src/app/models/personItem.model';
911
})
1012
export class CharactersComponent implements OnInit {
1113
characters:Array<IPersonType>=[];
14+
unSubscribeAll = new Subject<any>();
1215
constructor(private appService:AppService) {
1316
this.appService.getCharacters()
17+
.pipe(
18+
takeUntil(this.unSubscribeAll)
19+
)
1420
.subscribe(data => {
1521
this.characters=data;
1622
});

HarryPotter/src/app/components/films/films.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IFilmType } from 'src/app/models';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-films',
@@ -9,8 +11,13 @@ import { IFilmType } from 'src/app/models';
911
})
1012
export class FilmsComponent implements OnInit {
1113
films: Array<IFilmType> = [];
14+
unSubscribeAll = new Subject<any>();
1215
constructor(private appService: AppService) {
13-
this.appService.getFilms().subscribe((data) => (this.films = data));
16+
this.appService.getFilms()
17+
.pipe(
18+
takeUntil(this.unSubscribeAll)
19+
)
20+
.subscribe((data) => (this.films = data));
1421
}
1522

1623
ngOnInit(): void {}

HarryPotter/src/app/components/houses/houses.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IHouseType } from 'src/app/models';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-houses',
@@ -9,8 +11,13 @@ import { IHouseType } from 'src/app/models';
911
})
1012
export class HousesComponent implements OnInit {
1113
houses:Array<IHouseType>=[];
14+
unSubscribeAll = new Subject<any>();
15+
1216
constructor(private appService:AppService) {
1317
this.appService.getHouses()
18+
.pipe(
19+
takeUntil(this.unSubscribeAll)
20+
)
1421
.subscribe(data => {
1522
this.houses=data;
1623
});

HarryPotter/src/app/components/staff/staff.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IPersonType } from 'src/app/models/personItem.model';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-staff',
@@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
911
})
1012
export class StaffComponent implements OnInit {
1113
staff:Array<IPersonType>=[];
14+
unSubscribeAll = new Subject<any>();
15+
1216
constructor(private appService:AppService) {
1317
this.appService.getStaff()
18+
.pipe(
19+
takeUntil(this.unSubscribeAll)
20+
)
1421
.subscribe(data => {
1522
this.staff=data;
1623
});

HarryPotter/src/app/components/students/students.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AppService } from 'src/app/app.service';
33
import { IPersonType } from 'src/app/models/personItem.model';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { Subject } from 'rxjs';
46

57
@Component({
68
selector: 'app-students',
@@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
911
})
1012
export class StudentsComponent implements OnInit {
1113
students:Array<IPersonType>=[];
14+
unSubscribeAll = new Subject<any>();
15+
1216
constructor(private appService:AppService) {
1317
this.appService.getStudents()
18+
.pipe(
19+
takeUntil(this.unSubscribeAll)
20+
)
1421
.subscribe(data => {
1522
this.students=data;
1623
});

0 commit comments

Comments
 (0)