• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / f28eef4a-884b-4687-b4bb-b99f1a93022d

21 Aug 2024 03:02AM UTC coverage: 90.462% (-0.005%) from 90.467%
f28eef4a-884b-4687-b4bb-b99f1a93022d

Pull #3163

circleci

wangyuan-ky
build: fix comment  #TINFR-396
Pull Request #3163: build: solve scss warnings #TINFR-396 @wumeimin @xinglu

5497 of 6721 branches covered (81.79%)

Branch coverage included in aggregate %.

13245 of 13997 relevant lines covered (94.63%)

996.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.86
/src/shared/directives/thy-scroll.directive.ts
1
import { Directive, ElementRef, OnInit, NgZone, OnDestroy, Output, EventEmitter, Input } from '@angular/core';
2
import { Subject, Observable, Observer, fromEvent, Subscription } from 'rxjs';
3
import { takeUntil } from 'rxjs/operators';
4
import { normalizePassiveListenerOptions } from '@angular/cdk/platform';
5
import { coerceBooleanProperty } from 'ngx-tethys/util';
6

7
const passiveEventListenerOptions = <AddEventListenerOptions>normalizePassiveListenerOptions({ passive: true });
1✔
8

9
/**
10
 * @name thyScroll
11
 */
1✔
12
@Directive({
13
    selector: '[thyScroll]',
72✔
14
    standalone: true
72!
15
})
×
16
export class ThyScrollDirective implements OnInit, OnDestroy {
×
17
    private _destroyed = new Subject<void>();
18
    private _enable = true;
19
    private _initialled = false;
×
20
    private _subscription: Subscription;
×
21

×
22
    private _elementScrolled: Observable<Event> = new Observable((observer: Observer<Event>) =>
23
        this.ngZone.runOutsideAngular(() =>
24
            fromEvent(this.elementRef.nativeElement, 'scroll', passiveEventListenerOptions)
25
                .pipe(takeUntil(this._destroyed))
26
                .subscribe(observer)
27
        )
72✔
28
    );
72✔
29

72✔
30
    @Input({ transform: coerceBooleanProperty })
72✔
31
    set thyEnable(value: boolean) {
72✔
32
        this._enable = value;
72✔
33
        if (this._initialled) {
34
            if (this._enable && this._subscription === null) {
35
                this._subscription = this._elementScrolled.subscribe(() => this.thyOnScrolled.emit(this.elementRef));
72✔
36
            } else {
37
                if (this._subscription) {
38
                    this._subscription.unsubscribe();
72✔
39
                    this._subscription = null;
6✔
40
                }
41
            }
72✔
42
        }
43
    }
44

72✔
45
    /**
72✔
46
     * @description
47
     *
48
     * Note: the `thyOnScrolled` emits outside of the Angular zone since the `scroll` listener
×
49
     * is installed within the `<root>` zone.
50
     *
1✔
51
     * Consumers need to re-enter the Angular zone theirselves when the change detection is needeed to be run:
52
     * ```ts
53
     * @Component({
54
     *   template: '<div thyScroll (thyOnScrolled)="onScrolled()"></div>'
1✔
55
     * })
56
     * class ThyScrollComponent {
57
     *   onScrolled(): void {
58
     *     console.log(Zone.current); // <root>
59
     *     console.log(NgZone.isInAngularZone()); // false
1✔
60
     *   }
61
     * }
62
     * ```
63
     */
64
    @Output() thyOnScrolled: EventEmitter<ElementRef> = new EventEmitter<ElementRef>();
65

66
    constructor(
67
        private elementRef: ElementRef<any>,
68
        private ngZone: NgZone
69
    ) {}
70

71
    ngOnInit() {
72
        if (this._enable) {
73
            this._subscription = this._elementScrolled.subscribe(() => this.thyOnScrolled.emit(this.elementRef));
74
        }
75
        this._initialled = true;
76
    }
77

78
    ngOnDestroy() {
79
        this._destroyed.next();
80
        this._destroyed.complete();
81
    }
82

83
    getElementRef(): ElementRef<HTMLElement> {
84
        return this.elementRef;
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc