Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[@angular-eslint/no-uncalled-signals] Doing logic operations on signals will give unexpected results, you probably want to invoke the signal to get its value #2574

@splincode

Description

@splincode

https://github.com/taiga-family/taiga-ui/blob/main/projects/kit/directives/lazy-loading/lazy-loading.directive.ts#L38

//...

@Directive({
    standalone: true,
    selector: 'img[loading="lazy"],img[tuiLoading="lazy"]',
    providers: [TuiLazyLoadingService, IntersectionObserverService],
    host: {
        '[style.animation]': 'animation()',
        '[style.background]': 'background()',
        '[attr.loading]': 'supported ? "lazy" : null',
        '[attr.src]': 'src()',
        '(load)': 'unset()',
        '(error)': 'unset()',
    },
})
export class TuiImgLazyLoading {
    private readonly isServer = isPlatformServer(inject(PLATFORM_ID));
    private readonly loading$ = inject(TuiLazyLoadingService);
    protected readonly supported = 'loading' in tuiInjectElement<HTMLImageElement>();
    protected src = signal<SafeResourceUrl | string | null>(null);
    protected background = signal(this.isServer ? '' : 'var(--tui-background-neutral-2)');
    protected animation = signal(
        this.isServer ? '' : 'tuiSkeletonVibe ease-in-out 1s infinite alternate',
    );

    protected readonly $ =
        !this.supported &&
        this.loading$.pipe(takeUntilDestroyed()).subscribe((src) => this.src.set(src)); // ✖ 1 problem (1 error, 0 warnings)

    @Input('src')
    public set srcSetter(src: SafeResourceUrl | string) {
        if (this.supported) {
            this.src.set(src);
        } else {
            this.loading$.next(src);
        }
    }

    protected unset(): void {
        this.background.set('');
        this.animation.set('');
    }
}
Image

Why I have an error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginAngular-specific TypeScript rulestriageThis issue needs to be looked at and categorized by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions