refactor(product-row-card): move variant selection logic into constructor for better clarity
This commit is contained in:
@@ -27,7 +27,12 @@ export class ProductRowCardComponent {
|
|||||||
readonly quantity = model<number>(1);
|
readonly quantity = model<number>(1);
|
||||||
readonly selectedVariant = model<any>(null);
|
readonly selectedVariant = model<any>(null);
|
||||||
|
|
||||||
private readonly selectFirstVariant = effect(() => {
|
// Interactive events
|
||||||
|
readonly buy = output<void>();
|
||||||
|
readonly addToCart = output<{ quantity: number; variant: any }>();
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
const variants = this.variants();
|
const variants = this.variants();
|
||||||
const selectedVariant = this.selectedVariant();
|
const selectedVariant = this.selectedVariant();
|
||||||
|
|
||||||
@@ -38,10 +43,7 @@ export class ProductRowCardComponent {
|
|||||||
this.selectedVariant.set(variants[0].value);
|
this.selectedVariant.set(variants[0].value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Interactive events
|
|
||||||
readonly buy = output<void>();
|
|
||||||
readonly addToCart = output<{ quantity: number; variant: any }>();
|
|
||||||
|
|
||||||
// Formatted string for price: "$ 10.000"
|
// Formatted string for price: "$ 10.000"
|
||||||
readonly formattedPrice = computed(() => {
|
readonly formattedPrice = computed(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user