Skip to content

Commit

Permalink
Merge pull request #8 from NisanurBulut/dev-harrypotterrefactor
Browse files Browse the repository at this point in the history
avoided memory link with takeuntil
  • Loading branch information
NisanurBulut authored May 1, 2021
2 parents 0ae1f59 + 3fe2487 commit 3e01e9e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions HarryPotter/src/app/components/books/books.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IBookType } from 'src/app/models';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-books',
Expand All @@ -9,8 +11,12 @@ import { IBookType } from 'src/app/models';
})
export class BooksComponent implements OnInit {
books:Array<IBookType>=[];
unSubscribeAll = new Subject<any>();
constructor(private appService:AppService) {
this.appService.getBooks()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe(data => {
this.books=data;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IPersonType } from 'src/app/models/personItem.model';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-characters',
Expand All @@ -9,8 +11,12 @@ import { IPersonType } from 'src/app/models/personItem.model';
})
export class CharactersComponent implements OnInit {
characters:Array<IPersonType>=[];
unSubscribeAll = new Subject<any>();
constructor(private appService:AppService) {
this.appService.getCharacters()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe(data => {
this.characters=data;
});
Expand Down
9 changes: 8 additions & 1 deletion HarryPotter/src/app/components/films/films.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IFilmType } from 'src/app/models';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-films',
Expand All @@ -9,8 +11,13 @@ import { IFilmType } from 'src/app/models';
})
export class FilmsComponent implements OnInit {
films: Array<IFilmType> = [];
unSubscribeAll = new Subject<any>();
constructor(private appService: AppService) {
this.appService.getFilms().subscribe((data) => (this.films = data));
this.appService.getFilms()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe((data) => (this.films = data));
}

ngOnInit(): void {}
Expand Down
7 changes: 7 additions & 0 deletions HarryPotter/src/app/components/houses/houses.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IHouseType } from 'src/app/models';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-houses',
Expand All @@ -9,8 +11,13 @@ import { IHouseType } from 'src/app/models';
})
export class HousesComponent implements OnInit {
houses:Array<IHouseType>=[];
unSubscribeAll = new Subject<any>();

constructor(private appService:AppService) {
this.appService.getHouses()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe(data => {
this.houses=data;
});
Expand Down
7 changes: 7 additions & 0 deletions HarryPotter/src/app/components/staff/staff.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IPersonType } from 'src/app/models/personItem.model';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-staff',
Expand All @@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
})
export class StaffComponent implements OnInit {
staff:Array<IPersonType>=[];
unSubscribeAll = new Subject<any>();

constructor(private appService:AppService) {
this.appService.getStaff()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe(data => {
this.staff=data;
});
Expand Down
7 changes: 7 additions & 0 deletions HarryPotter/src/app/components/students/students.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from 'src/app/app.service';
import { IPersonType } from 'src/app/models/personItem.model';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Component({
selector: 'app-students',
Expand All @@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
})
export class StudentsComponent implements OnInit {
students:Array<IPersonType>=[];
unSubscribeAll = new Subject<any>();

constructor(private appService:AppService) {
this.appService.getStudents()
.pipe(
takeUntil(this.unSubscribeAll)
)
.subscribe(data => {
this.students=data;
});
Expand Down

0 comments on commit 3e01e9e

Please sign in to comment.