From 6e5c9f4487d4f5a2633c13812c4ad4e2b221b5b3 Mon Sep 17 00:00:00 2001 From: Maksim Ivanov Date: Tue, 20 Aug 2024 16:04:36 +0300 Subject: [PATCH] fix(core): do not call resolver multiple time (#8578) --- projects/core/components/icon/icon.component.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/projects/core/components/icon/icon.component.ts b/projects/core/components/icon/icon.component.ts index 9969f88f3d93..7a3e5ae13076 100644 --- a/projects/core/components/icon/icon.component.ts +++ b/projects/core/components/icon/icon.component.ts @@ -6,6 +6,7 @@ import { ViewEncapsulation, } from '@angular/core'; import type {TuiStringHandler} from '@taiga-ui/cdk/types'; +import {tuiPure} from '@taiga-ui/cdk/utils/miscellaneous'; import {TUI_ICON_END, TUI_ICON_START, tuiInjectIconResolver} from '@taiga-ui/core/tokens'; @Component({ @@ -16,8 +17,8 @@ import {TUI_ICON_END, TUI_ICON_START, tuiInjectIconResolver} from '@taiga-ui/cor encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, host: { - '[style.--t-icon]': '"url(" + resolver(icon) + ")"', - '[style.--t-icon-bg]': 'background ? "url(" + resolver(background) + ")" : null', + '[style.--t-icon]': 'getUrl(icon)', + '[style.--t-icon-bg]': 'getBackground(background)', }, }) export class TuiIcon { @@ -31,4 +32,14 @@ export class TuiIcon { @Input() public background = ''; + + @tuiPure + protected getUrl(icon: string): string { + return `url(${this.resolver(icon)})`; + } + + @tuiPure + protected getBackground(background: string): string | null { + return background ? `url(${this.resolver(background)})` : null; + } }