From c9030228788424187c2a200f9466af9f874f510d Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sun, 8 Mar 2026 13:05:04 +0700 Subject: [PATCH] feat(lib): take until destroyed --- .../lib/tags-selector/tags-selector.component.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/libs/ui/src/lib/tags-selector/tags-selector.component.ts b/libs/ui/src/lib/tags-selector/tags-selector.component.ts index 42f52d4b3..0f7e9cd16 100644 --- a/libs/ui/src/lib/tags-selector/tags-selector.component.ts +++ b/libs/ui/src/lib/tags-selector/tags-selector.component.ts @@ -7,11 +7,11 @@ import { ElementRef, Input, OnChanges, - OnDestroy, OnInit, signal, ViewChild } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ControlValueAccessor, FormControl, @@ -30,7 +30,7 @@ import { IonIcon } from '@ionic/angular/standalone'; import { Tag } from '@prisma/client'; import { addIcons } from 'ionicons'; import { addCircleOutline, closeOutline } from 'ionicons/icons'; -import { BehaviorSubject, Subject, takeUntil } from 'rxjs'; +import { BehaviorSubject, Subject } from 'rxjs'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, @@ -57,7 +57,7 @@ import { BehaviorSubject, Subject, takeUntil } from 'rxjs'; templateUrl: 'tags-selector.component.html' }) export class GfTagsSelectorComponent - implements ControlValueAccessor, OnChanges, OnDestroy, OnInit + implements ControlValueAccessor, OnChanges, OnInit { @Input() hasPermissionToCreateTag = false; @Input() readonly = false; @@ -71,11 +71,9 @@ export class GfTagsSelectorComponent public readonly tagInputControl = new FormControl(''); public readonly tagsSelected = signal([]); - private unsubscribeSubject = new Subject(); - public constructor() { this.tagInputControl.valueChanges - .pipe(takeUntil(this.unsubscribeSubject)) + .pipe(takeUntilDestroyed()) .subscribe((value) => { this.filteredOptions.next(this.filterTags(value ?? '')); }); @@ -154,11 +152,6 @@ export class GfTagsSelectorComponent this.updateFilters(); } - public ngOnDestroy() { - this.unsubscribeSubject.next(); - this.unsubscribeSubject.complete(); - } - private filterTags(query: string = ''): Tag[] { const tags = this.tagsSelected() ?? []; const tagIds = tags.map(({ id }) => {