From d4c671dc7a48f003194aedfe597b1de1c69fcc01 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Fri, 17 Jul 2026 13:47:40 -0300 Subject: [PATCH] refactor(product-row-card): move variant selection logic into constructor for better clarity --- .../product-row-card.component.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/shared/components/product-row-card/product-row-card.component.ts b/src/app/shared/components/product-row-card/product-row-card.component.ts index b3a6114..456a414 100644 --- a/src/app/shared/components/product-row-card/product-row-card.component.ts +++ b/src/app/shared/components/product-row-card/product-row-card.component.ts @@ -27,22 +27,24 @@ export class ProductRowCardComponent { readonly quantity = model(1); readonly selectedVariant = model(null); - private readonly selectFirstVariant = effect(() => { - const variants = this.variants(); - const selectedVariant = this.selectedVariant(); - - if ( - variants.length > 0 && - !variants.some((variant) => Object.is(variant.value, selectedVariant)) - ) { - this.selectedVariant.set(variants[0].value); - } - }); - // Interactive events readonly buy = output(); readonly addToCart = output<{ quantity: number; variant: any }>(); + constructor() { + effect(() => { + const variants = this.variants(); + const selectedVariant = this.selectedVariant(); + + if ( + variants.length > 0 && + !variants.some((variant) => Object.is(variant.value, selectedVariant)) + ) { + this.selectedVariant.set(variants[0].value); + } + }); + } + // Formatted string for price: "$ 10.000" readonly formattedPrice = computed(() => { return this.formatCurrency(this.price());