1- import { Component , Inject , InjectionToken , OnInit , AfterViewInit , ChangeDetectionStrategy } from '@angular/core' ;
2- import { trigger , state , style , animate , transition } from '@angular/animations' ;
1+ import {
2+ Component ,
3+ Inject ,
4+ InjectionToken ,
5+ OnInit ,
6+ ChangeDetectionStrategy
7+ } from '@angular/core' ;
8+ import {
9+ trigger ,
10+ state ,
11+ style ,
12+ animate ,
13+ transition
14+ } from '@angular/animations' ;
315import { Router , ActivatedRoute } from '@angular/router' ;
416import { BreakpointObserver } from '@angular/cdk/layout' ;
517import { Subscription } from 'rxjs/Subscription' ;
@@ -21,7 +33,7 @@ interface OperatorDocMap {
2133 styleUrls : [ './operators.component.scss' ] ,
2234 animations : [
2335 trigger ( 'growInOut' , [
24- state ( 'in' , style ( { opacity : 1 } ) ) ,
36+ state ( 'in' , style ( { opacity : 1 } ) ) ,
2537 transition ( 'void => *' , [
2638 style ( {
2739 opacity : 0 ,
@@ -30,55 +42,29 @@ interface OperatorDocMap {
3042 animate ( `150ms ease-in` )
3143 ] ) ,
3244 transition ( '* => void' , [
33- animate ( `150ms ease-out` , style ( {
34- opacity : 0 ,
35- transform : 'scale3d(.3, .3, .3)'
36- } ) )
45+ animate (
46+ `150ms ease-out` ,
47+ style ( {
48+ opacity : 0 ,
49+ transform : 'scale3d(.3, .3, .3)'
50+ } )
51+ )
3752 ] )
3853 ] )
3954 ]
4055} )
41- export class OperatorsComponent implements OnInit , AfterViewInit {
56+ export class OperatorsComponent implements OnInit {
4257 public groupedOperators : OperatorDocMap ;
4358 public categories : string [ ] ;
4459
45- private _subscription : Subscription ;
46-
4760 constructor (
4861 private _breakpointObserver : BreakpointObserver ,
49- private _router : Router ,
50- private _activatedRoute : ActivatedRoute ,
5162 @Inject ( OPERATORS_TOKEN ) public operators : OperatorDoc [ ]
52- ) { }
63+ ) { }
5364
5465 ngOnInit ( ) {
5566 this . groupedOperators = groupOperatorsByType ( this . operators ) ;
5667 this . categories = Object . keys ( this . groupedOperators ) ;
57- this . _subscription = this . _activatedRoute
58- . fragment
59- . subscribe ( name => this . scrollToOperator ( name ) ) ;
60- }
61-
62- ngAfterViewInit ( ) {
63- // scroll initial param when applicable
64- const name = this . _activatedRoute . snapshot . fragment ;
65-
66- if ( name ) {
67- // slight delay for scroll to be accurate
68- setTimeout ( ( ) => this . scrollToOperator ( name ) , 100 ) ;
69- }
70- }
71-
72- updateUrl ( name : string ) {
73- this . _router . navigate ( [ '/operators' ] , { fragment : name } ) ;
74- }
75-
76- scrollToOperator ( name : string ) {
77- const element = document . getElementById ( name ) ;
78-
79- if ( element ) {
80- element . scrollIntoView ( ) ;
81- }
8268 }
8369
8470 get extraSmallScreen ( ) {
@@ -90,20 +76,21 @@ export class OperatorsComponent implements OnInit, AfterViewInit {
9076 }
9177
9278 get operatorMenuGap ( ) {
93- return this . extraSmallScreen ? OPERATOR_MENU_GAP_SMALL : OPERATOR_MENU_GAP_LARGE ;
79+ return this . extraSmallScreen
80+ ? OPERATOR_MENU_GAP_SMALL
81+ : OPERATOR_MENU_GAP_LARGE ;
9482 }
9583
9684 get sidenavMode ( ) {
9785 return this . smallScreen ? 'over' : 'side' ;
9886 }
99-
10087}
10188
10289export function groupOperatorsByType ( operators : OperatorDoc [ ] ) : OperatorDocMap {
10390 return operators . reduce ( ( acc : OperatorDocMap , curr : OperatorDoc ) => {
10491 if ( acc [ curr . operatorType ] ) {
105- return { ...acc , [ curr . operatorType ] : [ ...acc [ curr . operatorType ] , curr ] } ;
92+ return { ...acc , [ curr . operatorType ] : [ ...acc [ curr . operatorType ] , curr ] } ;
10693 }
107- return { ...acc , [ curr . operatorType ] : [ curr ] } ;
94+ return { ...acc , [ curr . operatorType ] : [ curr ] } ;
10895 } , { } ) ;
10996}
0 commit comments