Skip to content

Commit

Permalink
refactor: fix possible memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Mar 7, 2024
1 parent 4556b42 commit fa85894
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
4 changes: 3 additions & 1 deletion projects/addon-mobile/directives/ripple/ripple.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class TuiRippleDirective {
const touchEnd$ = tuiTypedFromEvent(this.el, 'touchend');
const touchMove$ = tuiTypedFromEvent(this.el, 'touchmove');

this.end$.subscribe(element => this.renderer.removeChild(this.el, element));
this.end$
.pipe(takeUntil(this.destroy$))
.subscribe(element => this.renderer.removeChild(this.el, element));

this.start$
.pipe(
Expand Down
10 changes: 6 additions & 4 deletions projects/core/components/link/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import {MODE_PROVIDER} from '@taiga-ui/core/providers';
import {TUI_MODE} from '@taiga-ui/core/tokens';
import type {TuiHorizontalDirection} from '@taiga-ui/core/types';
import {map, merge} from 'rxjs';
import {map, merge, takeUntil} from 'rxjs';

// @bad TODO: Think about extending Interactive
@Component({
Expand Down Expand Up @@ -70,9 +70,11 @@ export class TuiLinkComponent implements TuiFocusableElementAccessor {
protected readonly mode$ = inject(TUI_MODE);

constructor() {
inject(TuiFocusVisibleService).subscribe(visible => {
this.focusVisible = visible;
});
inject(TuiFocusVisibleService)
.pipe(takeUntil(inject(TuiDestroyService, {self: true})))
.subscribe(visible => {
this.focusVisible = visible;
});
}

public get nativeFocusableElement(): TuiNativeFocusableElement {
Expand Down
7 changes: 4 additions & 3 deletions projects/kit/components/action/action.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TuiFocusVisibleService,
tuiIsNativeFocused,
} from '@taiga-ui/cdk';
import {takeUntil} from 'rxjs';

@Component({
selector: 'button[tuiAction], a[tuiAction]',
Expand All @@ -41,9 +42,9 @@ export class TuiActionComponent extends AbstractTuiInteractive {
constructor() {
super();

inject(TuiFocusVisibleService).subscribe(visible => {
this.updateFocusVisible(visible);
});
inject(TuiFocusVisibleService)
.pipe(takeUntil(inject(TuiDestroyService, {self: true})))
.subscribe(visible => this.updateFocusVisible(visible));
}

public get nativeFocusableElement(): TuiNativeFocusableElement | null {
Expand Down
17 changes: 10 additions & 7 deletions projects/kit/components/stepper/step/step.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {RouterLinkActive} from '@angular/router';
import {TuiDestroyService, TuiFocusVisibleService} from '@taiga-ui/cdk';
import {TUI_COMMON_ICONS} from '@taiga-ui/core';
import type {Observable} from 'rxjs';
import {EMPTY, filter} from 'rxjs';
import {EMPTY, filter, takeUntil} from 'rxjs';

import {TuiStepperComponent} from '../stepper.component';

Expand Down Expand Up @@ -46,13 +46,16 @@ export class TuiStepComponent {
protected readonly icons = inject(TUI_COMMON_ICONS);

constructor() {
this.routerLinkActive$.pipe(filter(Boolean)).subscribe(() => {
this.activate();
});
this.routerLinkActive$
.pipe(filter(Boolean))
.pipe(takeUntil(inject(TuiDestroyService, {self: true})))
.subscribe(() => this.activate());

this.focusVisible$.subscribe(visible => {
this.focusVisible = visible;
});
this.focusVisible$
.pipe(takeUntil(inject(TuiDestroyService, {self: true})))
.subscribe(visible => {
this.focusVisible = visible;
});
}

@HostBinding('class._active')
Expand Down

0 comments on commit fa85894

Please sign in to comment.