Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update virtualScroll.component.ts #6

Merged
merged 5 commits into from
Dec 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/virtualScroll.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {
ChangeDetectionStrategy, ChangeDetectorRef, Component,
ComponentFactory, ComponentFactoryResolver, ContentChild,
ElementRef, Input, OnDestroy, OnInit,
Renderer, TemplateRef, ViewChild,
ViewContainerRef
TemplateRef, ViewChild,
ViewContainerRef, NgZone
} from '@angular/core';

import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import {animationFrame as animationScheduler} from 'rxjs/scheduler/animationFrame';
import {Subscription} from 'rxjs/Subscription';

Expand Down Expand Up @@ -85,7 +86,8 @@ export class VirtualScrollComponent implements OnInit, OnDestroy {

constructor(
private _elem: ElementRef, private _cdr: ChangeDetectorRef,
private _componentFactoryResolver: ComponentFactoryResolver, private _obsService: ScrollObservableService) {}
private _componentFactoryResolver: ComponentFactoryResolver, private _obsService: ScrollObservableService,
private _zone: NgZone) {}

ngOnInit() {
const getContainerRect = () => this._elem.nativeElement.getBoundingClientRect();
Expand All @@ -110,8 +112,17 @@ export class VirtualScrollComponent implements OnInit, OnDestroy {
.startWith(getContainerRect())
.map(({width, height}) => ({width, height}));

const scrollTop$ = Observable.fromEvent(this._elem.nativeElement, 'scroll')
.debounceTime(this.vsDebounceTime, animationScheduler)
const scroll$ = new Subject<void>();
this._zone.runOutsideAngular(() => {
this._subs.push(
Observable.fromEvent(this._elem.nativeElement, 'scroll')
.debounceTime(this.vsDebounceTime, animationScheduler)
.subscribe(() => {
this._zone.run(() => scroll$.next())
}))
});

const scrollTop$ = scroll$
.map(() => getScrollTop())
.startWith(0);

Expand Down