Skip to content

Commit 66e8e31

Browse files
committed
Update properties to limit scope and use stored properties
1 parent 0e4be1f commit 66e8e31

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/ProductRowViewModel.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,42 @@ final class ProductRowViewModel: ObservableObject, Identifiable {
1818

1919
/// Product to display
2020
///
21-
let product: Product
21+
private let product: Product
2222

2323
/// Label showing product name
2424
///
25-
var nameLabel: String {
26-
product.name
27-
}
25+
let nameLabel: String
2826

2927
/// Label showing product stock status and price.
3028
///
31-
var stockAndPriceLabel: String {
29+
lazy var stockAndPriceLabel: String = {
3230
let stockLabel = createStockText()
3331
let priceLabel = createPriceText()
3432

3533
return [stockLabel, priceLabel]
3634
.compactMap({ $0 })
3735
.joined(separator: "")
38-
}
36+
}()
3937

4038
/// Label showing product SKU
4139
///
42-
var skuLabel: String {
40+
lazy var skuLabel: String = {
4341
guard let sku = product.sku, sku.isNotEmpty else {
4442
return ""
4543
}
4644
return String.localizedStringWithFormat(Localization.skuFormat, sku)
47-
}
45+
}()
4846

4947
/// Quantity of product in the order
5048
///
51-
var quantity: Int64 = 1
49+
@Published var quantity: Int64 = 1
5250

5351
init(product: Product,
5452
canChangeQuantity: Bool,
5553
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)) {
5654
self.id = product.productID
5755
self.product = product
56+
self.nameLabel = product.name
5857
self.canChangeQuantity = canChangeQuantity
5958
self.currencyFormatter = currencyFormatter
6059
}

0 commit comments

Comments
 (0)