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

atinc / ngx-tethys / 881c8997-29c3-4d01-9ef1-22092f16cec2

03 Apr 2024 03:31AM UTC coverage: 90.404% (-0.2%) from 90.585%
881c8997-29c3-4d01-9ef1-22092f16cec2

Pull #3062

circleci

minlovehua
refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()
Pull Request #3062: refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()

5411 of 6635 branches covered (81.55%)

Branch coverage included in aggregate %.

217 of 223 new or added lines in 82 files covered. (97.31%)

201 existing lines in 53 files now uncovered.

13176 of 13925 relevant lines covered (94.62%)

980.1 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, booleanAttribute } 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

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

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

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

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

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

65
    constructor(private elementRef: ElementRef<any>, private ngZone: NgZone) {}
66

67
    ngOnInit() {
68
        if (this._enable) {
69
            this._subscription = this._elementScrolled.subscribe(() => this.thyOnScrolled.emit(this.elementRef));
70
        }
71
        this._initialled = true;
72
    }
73

74
    ngOnDestroy() {
75
        this._destroyed.next();
76
        this._destroyed.complete();
77
    }
78

79
    getElementRef(): ElementRef<HTMLElement> {
80
        return this.elementRef;
81
    }
82
}
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