Skip to content

Commit

Permalink
fix: memory leaks (#3000)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibing committed Jan 10, 2022
1 parent 223e001 commit d6374b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/framework/theme/components/layout/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class NbLayoutComponent implements AfterViewInit, OnDestroy {

this.scrollService
.onScrollableChange()
.pipe(filter(() => this.withScrollValue))
.pipe(filter(() => this.withScrollValue), takeUntil(this.destroy$))
.subscribe((scrollable: boolean) => {
/**
* In case when Nebular Layout custom scroll `withScroll` mode is enabled
Expand Down
14 changes: 12 additions & 2 deletions src/framework/theme/components/tabset/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { map, delay, filter } from 'rxjs/operators';
import { map, delay, filter, takeUntil } from 'rxjs/operators';
import {
Component,
Input,
Expand All @@ -16,8 +16,10 @@ import {
HostBinding,
ChangeDetectorRef,
ContentChild,
OnDestroy,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Subject } from 'rxjs';

import { convertToBoolProperty, NbBooleanInput } from '../helpers';
import { NbComponentOrCustomStatus } from '../component-status';
Expand Down Expand Up @@ -334,7 +336,7 @@ export class NbTabComponent {
<ng-content select="nb-tab"></ng-content>
`,
})
export class NbTabsetComponent implements AfterContentInit {
export class NbTabsetComponent implements AfterContentInit, OnDestroy {
@ContentChildren(NbTabComponent) tabs: QueryList<NbTabComponent>;

@HostBinding('class.full-width')
Expand Down Expand Up @@ -362,6 +364,8 @@ export class NbTabsetComponent implements AfterContentInit {
*/
@Output() changeTab = new EventEmitter<any>();

private destroy$: Subject<void> = new Subject<void>();

constructor(private route: ActivatedRoute, private changeDetectorRef: ChangeDetectorRef) {}

// TODO: refactoring this component, avoid change detection loop
Expand All @@ -374,13 +378,19 @@ export class NbTabsetComponent implements AfterContentInit {
delay(0),
map((tab: NbTabComponent) => tab || this.tabs.first),
filter((tab: NbTabComponent) => !!tab),
takeUntil(this.destroy$),
)
.subscribe((tabToSelect: NbTabComponent) => {
this.selectTab(tabToSelect);
this.changeDetectorRef.markForCheck();
});
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}

// TODO: navigate to routeParam
selectTab(selectedTab: NbTabComponent) {
if (!selectedTab.disabled) {
Expand Down

0 comments on commit d6374b1

Please sign in to comment.