Skip to content

Commit

Permalink
fix: subscription cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
makiJS committed Jul 10, 2019
1 parent b28597e commit 42890e4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions projects/ng-slider/src/lib/slides/slides.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class SlidesComponent implements OnInit, AfterViewInit, OnDestroy {

private _manager: any;
private _slideTimeInterval: Subscription;
private _mouseEnterSubscription: Subscription;
private _mouseLeaveSubscription: Subscription;

@HostListener('mouseover')
onMouseOver() {
Expand Down Expand Up @@ -142,9 +144,15 @@ export class SlidesComponent implements OnInit, AfterViewInit, OnDestroy {
this._manager.destroy();
}

if (this._slideTimeInterval) {
this._slideTimeInterval.unsubscribe();
}
[
this._slideTimeInterval,
this._mouseEnterSubscription,
this._mouseLeaveSubscription
]
.filter(subscription => subscription)
.forEach(subscription => {
subscription.unsubscribe();
});
}

ngAfterViewInit() {
Expand Down Expand Up @@ -389,8 +397,8 @@ export class SlidesComponent implements OnInit, AfterViewInit, OnDestroy {
/**
* Detect if mouse is inside/outside of page
*/
fromEvent(this.document, 'mouseenter').subscribe(() => this.blockAutoSlide = false);
fromEvent(this.document, 'mouseleave').subscribe(() => this.blockAutoSlide = true);
this._mouseEnterSubscription = fromEvent(this.document, 'mouseenter').subscribe(() => this.blockAutoSlide = false);
this._mouseLeaveSubscription = fromEvent(this.document, 'mouseleave').subscribe(() => this.blockAutoSlide = true);

this._slideTimeInterval = merge(
this.timerReset$,
Expand Down

0 comments on commit 42890e4

Please sign in to comment.