From 3fe2487d9228df7e092c14b9f7e2d9da7f88a1d8 Mon Sep 17 00:00:00 2001 From: Nisanur BULUT Date: Sat, 1 May 2021 20:58:27 +0300 Subject: [PATCH] avoided memory link with takeuntil --- HarryPotter/src/app/components/books/books.component.ts | 6 ++++++ .../app/components/characters/characters.component.ts | 6 ++++++ HarryPotter/src/app/components/films/films.component.ts | 9 ++++++++- .../src/app/components/houses/houses.component.ts | 7 +++++++ HarryPotter/src/app/components/staff/staff.component.ts | 7 +++++++ .../src/app/components/students/students.component.ts | 7 +++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/HarryPotter/src/app/components/books/books.component.ts b/HarryPotter/src/app/components/books/books.component.ts index d19376c..61fefdb 100644 --- a/HarryPotter/src/app/components/books/books.component.ts +++ b/HarryPotter/src/app/components/books/books.component.ts @@ -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', @@ -9,8 +11,12 @@ import { IBookType } from 'src/app/models'; }) export class BooksComponent implements OnInit { books:Array=[]; + unSubscribeAll = new Subject(); constructor(private appService:AppService) { this.appService.getBooks() + .pipe( + takeUntil(this.unSubscribeAll) + ) .subscribe(data => { this.books=data; }); diff --git a/HarryPotter/src/app/components/characters/characters.component.ts b/HarryPotter/src/app/components/characters/characters.component.ts index ab19303..7685d2c 100644 --- a/HarryPotter/src/app/components/characters/characters.component.ts +++ b/HarryPotter/src/app/components/characters/characters.component.ts @@ -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', @@ -9,8 +11,12 @@ import { IPersonType } from 'src/app/models/personItem.model'; }) export class CharactersComponent implements OnInit { characters:Array=[]; + unSubscribeAll = new Subject(); constructor(private appService:AppService) { this.appService.getCharacters() + .pipe( + takeUntil(this.unSubscribeAll) + ) .subscribe(data => { this.characters=data; }); diff --git a/HarryPotter/src/app/components/films/films.component.ts b/HarryPotter/src/app/components/films/films.component.ts index d15a52f..0a7c82f 100644 --- a/HarryPotter/src/app/components/films/films.component.ts +++ b/HarryPotter/src/app/components/films/films.component.ts @@ -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', @@ -9,8 +11,13 @@ import { IFilmType } from 'src/app/models'; }) export class FilmsComponent implements OnInit { films: Array = []; + unSubscribeAll = new Subject(); 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 {} diff --git a/HarryPotter/src/app/components/houses/houses.component.ts b/HarryPotter/src/app/components/houses/houses.component.ts index 7e3eb0a..eae509b 100644 --- a/HarryPotter/src/app/components/houses/houses.component.ts +++ b/HarryPotter/src/app/components/houses/houses.component.ts @@ -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', @@ -9,8 +11,13 @@ import { IHouseType } from 'src/app/models'; }) export class HousesComponent implements OnInit { houses:Array=[]; + unSubscribeAll = new Subject(); + constructor(private appService:AppService) { this.appService.getHouses() + .pipe( + takeUntil(this.unSubscribeAll) + ) .subscribe(data => { this.houses=data; }); diff --git a/HarryPotter/src/app/components/staff/staff.component.ts b/HarryPotter/src/app/components/staff/staff.component.ts index 03f87fc..e59b5a1 100644 --- a/HarryPotter/src/app/components/staff/staff.component.ts +++ b/HarryPotter/src/app/components/staff/staff.component.ts @@ -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', @@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model'; }) export class StaffComponent implements OnInit { staff:Array=[]; + unSubscribeAll = new Subject(); + constructor(private appService:AppService) { this.appService.getStaff() + .pipe( + takeUntil(this.unSubscribeAll) + ) .subscribe(data => { this.staff=data; }); diff --git a/HarryPotter/src/app/components/students/students.component.ts b/HarryPotter/src/app/components/students/students.component.ts index f3be718..8448f68 100644 --- a/HarryPotter/src/app/components/students/students.component.ts +++ b/HarryPotter/src/app/components/students/students.component.ts @@ -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', @@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model'; }) export class StudentsComponent implements OnInit { students:Array=[]; + unSubscribeAll = new Subject(); + constructor(private appService:AppService) { this.appService.getStudents() + .pipe( + takeUntil(this.unSubscribeAll) + ) .subscribe(data => { this.students=data; });