6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { Component , OnDestroy , OnInit , inject } from '@angular/core' ;
9
+ import { Component , inject , signal } from '@angular/core' ;
10
10
import { ActivatedRoute , RouterLink } from '@angular/router' ;
11
11
import { MatRipple } from '@angular/material/core' ;
12
- import { combineLatest , Subscription } from 'rxjs' ;
12
+ import { combineLatest } from 'rxjs' ;
13
13
14
14
import {
15
15
DocItem ,
@@ -19,40 +19,42 @@ import {
19
19
import { NavigationFocus } from '../../shared/navigation-focus/navigation-focus' ;
20
20
21
21
import { ComponentPageTitle } from '../page-title/page-title' ;
22
+ import { map , switchMap } from 'rxjs/operators' ;
23
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
22
24
23
25
@Component ( {
24
26
selector : 'app-component-category-list' ,
25
27
templateUrl : './component-category-list.html' ,
26
28
styleUrls : [ './component-category-list.scss' ] ,
27
29
imports : [ NavigationFocus , RouterLink , MatRipple ] ,
28
30
} )
29
- export class ComponentCategoryList implements OnInit , OnDestroy {
31
+ export class ComponentCategoryList {
30
32
private readonly _docItems = inject ( DocumentationItems ) ;
31
33
private readonly _componentPageTitle = inject ( ComponentPageTitle ) ;
32
34
private readonly _route = inject ( ActivatedRoute ) ;
33
35
34
- items : DocItem [ ] = [ ] ;
35
- section = '' ;
36
- routeParamSubscription : Subscription = new Subscription ( ) ;
37
- _categoryListSummary : string | undefined ;
38
-
39
- ngOnInit ( ) {
40
- this . routeParamSubscription = combineLatest (
41
- this . _route . pathFromRoot . map ( route => route . params ) ,
42
- Object . assign ,
43
- ) . subscribe ( async params => {
44
- const sectionName = params [ 'section' ] ;
45
- const section = SECTIONS [ sectionName ] ;
46
- this . _componentPageTitle . title = section . name ;
47
- this . _categoryListSummary = section . summary ;
48
- this . section = sectionName ;
49
- this . items = await this . _docItems . getItems ( sectionName ) ;
50
- } ) ;
51
- }
36
+ readonly items = signal < DocItem [ ] > ( [ ] ) ;
37
+ readonly section = signal < string > ( '' ) ;
38
+ readonly _categoryListSummary = signal < string | undefined > ( undefined ) ;
39
+
40
+ constructor ( ) {
41
+ combineLatest ( this . _route . pathFromRoot . map ( route => route . params ) )
42
+ . pipe (
43
+ map ( paramsArray => Object . assign ( { } , ...paramsArray ) ) ,
44
+ switchMap ( params => {
45
+ const sectionName = params [ 'section' ] ;
46
+ const section = SECTIONS [ sectionName ] ;
47
+
48
+ this . _componentPageTitle . title = section . name ;
49
+ this . _categoryListSummary . set ( section . summary ) ;
50
+ this . section . set ( sectionName ) ;
52
51
53
- ngOnDestroy ( ) {
54
- if ( this . routeParamSubscription ) {
55
- this . routeParamSubscription . unsubscribe ( ) ;
56
- }
52
+ return this . _docItems . getItems ( sectionName ) ;
53
+ } ) ,
54
+ takeUntilDestroyed ( ) ,
55
+ )
56
+ . subscribe ( items => {
57
+ this . items . set ( items ) ;
58
+ } ) ;
57
59
}
58
60
}
0 commit comments