-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not trigger change detection on
scroll
events (#429)
- Loading branch information
Showing
6 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
libs/ngu/carousel/src/lib/ngu-carousel/ngu-window-scroll-listener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { Inject, Injectable, NgZone, OnDestroy, PLATFORM_ID } from '@angular/core'; | ||
import { Subject, fromEvent } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class NguWindowScrollListener extends Subject<Event> implements OnDestroy { | ||
private readonly _destroy$ = new Subject<void>(); | ||
|
||
constructor(@Inject(PLATFORM_ID) platformId: string, ngZone: NgZone) { | ||
super(); | ||
|
||
// Note: this service is shared between multiple `NguCarousel` components and each instance | ||
// doesn't add new events listener for the `window`. | ||
if (isPlatformBrowser(platformId)) { | ||
ngZone.runOutsideAngular(() => | ||
fromEvent(window, 'scroll').pipe(takeUntil(this._destroy$)).subscribe(this) | ||
); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this._destroy$.next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"strictPropertyInitialization": false, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"target": "es2020" | ||
}, | ||
"angularCompilerOptions": { | ||
"strictInjectionParameters": true, | ||
"strictInputAccessModifiers": true, | ||
"strictTemplates": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters