refactor(header): use takeUntil to unsubscribe

And remove commented lines and unnecessary imports.
This commit is contained in:
Sergey Andrievskiy 2020-10-30 13:40:37 +03:00
parent c643a46b50
commit a381ac2524

View file

@ -4,11 +4,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*/ */
import { Component, HostBinding, Input, OnDestroy } from '@angular/core'; import { OnInit, Component, HostBinding, Input, OnDestroy } from '@angular/core';
import { takeWhile } from 'rxjs/operators'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NbSidebarService } from '@nebular/theme'; import { NbSidebarService } from '@nebular/theme';
/*import { NgxAnalytics } from '../../services/analytics.service';*/
import { NgxVersionService } from '../../services/version.service'; import { NgxVersionService } from '../../services/version.service';
import { HeaderMenuService } from '../../../@core/data/service/header-menu.service'; import { HeaderMenuService } from '../../../@core/data/service/header-menu.service';
@ -17,9 +17,9 @@ import { HeaderMenuService } from '../../../@core/data/service/header-menu.servi
styleUrls: ['./header.component.scss'], styleUrls: ['./header.component.scss'],
templateUrl: './header.component.html', templateUrl: './header.component.html',
}) })
export class NgxLandingHeaderComponent implements OnDestroy { export class NgxLandingHeaderComponent implements OnInit, OnDestroy {
private alive = true; private destroy$ = new Subject<void>();
@HostBinding('class.docs-page') @Input() isDocs = false; @HostBinding('class.docs-page') @Input() isDocs = false;
@ -28,25 +28,25 @@ export class NgxLandingHeaderComponent implements OnDestroy {
currentVersion: string; currentVersion: string;
headerMenu = []; headerMenu = [];
constructor(/*private analytics: NgxAnalytics,*/ constructor(private sidebarService: NbSidebarService,
private sidebarService: NbSidebarService,
private versionService: NgxVersionService, private versionService: NgxVersionService,
private headerMenuService: HeaderMenuService) { private headerMenuService: HeaderMenuService) {
}
ngOnInit() {
this.currentVersion = this.versionService.getNgxVersion(); this.currentVersion = this.versionService.getNgxVersion();
this.headerMenuService.getHeaderMenu() this.headerMenuService.getHeaderMenu()
.pipe(takeWhile(() => this.alive )) .pipe(takeUntil(this.destroy$))
.subscribe((headerMenu) => this.headerMenu = headerMenu); .subscribe((headerMenu) => this.headerMenu = headerMenu);
} }
trackEmailClick() {
}
toggleSidebar() { toggleSidebar() {
this.sidebarService.toggle(false, this.sidebarTag); this.sidebarService.toggle(false, this.sidebarTag);
} }
ngOnDestroy() { ngOnDestroy() {
this.alive = false; this.destroy$.next();
this.destroy$.complete();
} }
} }