• 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

8.51
/src/shared/directives/view-outlet.directive.ts
1
import {
2
    ComponentRef,
3
    Directive,
4
    Input,
5
    ChangeDetectorRef,
6
    EmbeddedViewRef,
7
    OnChanges,
8
    SimpleChanges,
1✔
9
    Type,
10
    ViewContainerRef,
×
11
    TemplateRef,
×
12
    KeyValueDiffer,
×
13
    KeyValueDiffers
14
} from '@angular/core';
15
import { SafeAny } from 'ngx-tethys/types';
×
16

×
17
/**
×
18
 * 视图 Outlet 组件,取代 NgComponentOutlet 和 NgTemplateOutlet
×
19
 * @name thyViewOutlet
×
20
 * @order 10
×
21
 */
×
22
@Directive({
×
23
    selector: '[thyViewOutlet]',
24
    standalone: true
25
})
×
26
export class ThyViewOutletDirective implements OnChanges {
27
    private componentRef: ComponentRef<SafeAny> | undefined;
28

29
    private embeddedViewRef: EmbeddedViewRef<SafeAny> | undefined;
30

31
    /**
×
32
     * 组件或者模板 TemplateRef
×
33
     */
×
34
    @Input() thyViewOutlet: Type<SafeAny> | TemplateRef<SafeAny> | null = null;
×
35

×
36
    /**
×
37
     * 组件和模板上下文传递数据
38
     */
39
    @Input() thyViewOutletContext?: SafeAny;
×
40

×
41
    private keyValueDiffer: KeyValueDiffer<SafeAny, SafeAny>;
×
42

43
    constructor(private viewContainerRef: ViewContainerRef, private keyValueDiffers: KeyValueDiffers) {}
44

×
45
    ngOnChanges(changes: SimpleChanges) {
×
46
        const { viewContainerRef: viewContainerRef } = this;
×
47
        if (changes['thyViewOutlet']) {
48
            viewContainerRef.clear();
×
49
            this.componentRef = undefined;
×
50
            this.embeddedViewRef = undefined;
×
51

52
            if (this.thyViewOutlet) {
53
                if (this.thyViewOutlet instanceof TemplateRef) {
54
                    this.embeddedViewRef = viewContainerRef.createEmbeddedView(this.thyViewOutlet, this.thyViewOutletContext);
55
                } else {
×
56
                    this.componentRef = viewContainerRef.createComponent(this.thyViewOutlet, {
×
57
                        index: viewContainerRef.length
58
                    });
59
                }
1✔
60
            }
61
        }
62

63
        if (changes['thyViewOutletContext']) {
1✔
64
            let updatedKeys: string[] = [];
65
            if (changes['thyViewOutletContext'].isFirstChange()) {
66
                this.keyValueDiffer = this.keyValueDiffers.find(this.thyViewOutletContext).create();
67
                this.keyValueDiffer.diff(this.thyViewOutletContext);
68
                updatedKeys = Object.keys(this.thyViewOutletContext);
1✔
69
            } else {
70
                const diffChanges = this.keyValueDiffer.diff(this.thyViewOutletContext);
71
                diffChanges?.forEachChangedItem(item => {
72
                    updatedKeys.push(item.key);
73
                });
74
            }
75
            if (this.componentRef) {
76
                this.updateContext(this.componentRef.instance, updatedKeys);
77
                this.componentRef.injector.get(ChangeDetectorRef).markForCheck();
78
            } else if (this.embeddedViewRef) {
79
                this.updateContext(this.embeddedViewRef.context, updatedKeys);
80
                this.embeddedViewRef.markForCheck();
81
            }
82
        }
83
    }
84

85
    private updateContext(context: SafeAny, updatedKeys: string[]) {
86
        updatedKeys.forEach(key => {
87
            context[key] = this.thyViewOutletContext[key];
88
        });
89
    }
90
}
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