1
- import 'rxjs/add/operator/switchMap' ;
2
- import 'rxjs/add/observable/of' ;
3
-
4
1
import {
5
2
Component ,
6
3
ElementRef ,
9
6
Input ,
10
7
NgModule ,
11
8
OnChanges ,
12
- OnDestroy ,
13
9
OnInit ,
14
10
Output ,
15
11
Renderer ,
@@ -18,8 +14,6 @@ import {
18
14
} from '@angular/core' ;
19
15
20
16
import { CommonModule } from '@angular/common' ;
21
- import { Observable } from 'rxjs/Observable' ;
22
- import { Subject } from 'rxjs/Subject' ;
23
17
24
18
export interface ChangeEvent {
25
19
start ?: number ;
@@ -55,7 +49,7 @@ export interface ChangeEvent {
55
49
}
56
50
` ]
57
51
} )
58
- export class VirtualScrollComponent implements OnInit , OnDestroy , OnChanges {
52
+ export class VirtualScrollComponent implements OnInit , OnChanges {
59
53
60
54
@Input ( )
61
55
items : any [ ] = [ ] ;
@@ -87,9 +81,6 @@ export class VirtualScrollComponent implements OnInit, OnDestroy, OnChanges {
87
81
@ViewChild ( 'content' , { read : ElementRef } )
88
82
contentElementRef : ElementRef ;
89
83
90
- scroll$ : Subject < Event > = new Subject < Event > ( ) ;
91
-
92
- onScrollListener : Function ;
93
84
topPadding : number ;
94
85
scrollHeight : number ;
95
86
previousStart : number ;
@@ -100,15 +91,10 @@ export class VirtualScrollComponent implements OnInit, OnDestroy, OnChanges {
100
91
101
92
@HostListener ( 'scroll' )
102
93
onScroll ( e : Event ) {
103
- this . scroll$ . next ( ) ;
94
+ this . refresh ( ) ;
104
95
}
105
96
106
97
ngOnInit ( ) {
107
- this . scroll$ . switchMap ( ( ) => {
108
- this . refresh ( ) ;
109
- return Observable . of ( ) ;
110
- } ) . subscribe ( ) ;
111
-
112
98
this . scrollbarWidth = 0 ; // this.element.nativeElement.offsetWidth - this.element.nativeElement.clientWidth;
113
99
this . scrollbarHeight = 0 ; // this.element.nativeElement.offsetHeight - this.element.nativeElement.clientHeight;
114
100
}
@@ -123,16 +109,6 @@ export class VirtualScrollComponent implements OnInit, OnDestroy, OnChanges {
123
109
this . refresh ( ) ;
124
110
}
125
111
126
- ngOnDestroy ( ) {
127
- // Check that listener has been attached properly:
128
- // It may be undefined in some cases, e.g. if an exception is thrown, the component is
129
- // not initialized properly but destroy may be called anyways (e.g. in testing).
130
- if ( this . onScrollListener !== undefined ) {
131
- // this removes the listener
132
- this . onScrollListener ( ) ;
133
- }
134
- }
135
-
136
112
refresh ( ) {
137
113
requestAnimationFrame ( ( ) => this . calculateItems ( ) ) ;
138
114
}
0 commit comments