Skip to content

Commit f9a6289

Browse files
committed
fix(docs): add subject componentDestroyed$
1 parent a3ffe95 commit f9a6289

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

.ToDo

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ https://github.com/mpgp/mpgp.github.io/projects/1
33

44
In Progress:
55

6-
@critical @bug
7-
☐ use yarn instead of npm @created(18-06-12 21:28:46)
8-
96
@low @feature
107
☐ feat(compodoc): install package https://github.com/compodoc/compodoc
118

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
3-
import { filter, map } from 'rxjs/operators';
3+
import { Subject } from 'rxjs';
4+
import { filter, map, takeUntil } from 'rxjs/operators';
45

56
@Component({
67
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -9,18 +10,23 @@ import { filter, map } from 'rxjs/operators';
910
styleUrls: ['./docs-root.component.scss'],
1011
templateUrl: './docs-root.component.html',
1112
})
12-
export class DocsRootComponent implements OnInit {
13+
export class DocsRootComponent implements OnInit, OnDestroy {
14+
private readonly componentDestroyed$ = new Subject<boolean>();
15+
1316
constructor(private readonly route: ActivatedRoute) {}
1417

1518
ngOnInit(): void {
1619
this.route.params
1720
.pipe(
21+
takeUntil(this.componentDestroyed$),
1822
map(({ id }) => document.getElementById(id)),
1923
filter(element => !!element),
2024
)
21-
// FIXME: unsub.
22-
.subscribe(element => {
23-
element.scrollIntoView();
24-
});
25+
.subscribe(element => element.scrollIntoView());
26+
}
27+
28+
ngOnDestroy(): void {
29+
this.componentDestroyed$.next(true);
30+
this.componentDestroyed$.unsubscribe();
2531
}
2632
}

0 commit comments

Comments
 (0)