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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

16.67
/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 { coerceBooleanProperty } from 'ngx-tethys/util';
5
import { normalizePassiveListenerOptions } from '@angular/cdk/platform';
6
import { InputBoolean } from 'ngx-tethys/core';
7

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

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

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

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

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

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

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

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

82
    getElementRef(): ElementRef<HTMLElement> {
83
        return this.elementRef;
84
    }
85
}
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