Skip to content

Commit 8e7d0c3

Browse files
committed
Move data populating to initializer
1 parent e468581 commit 8e7d0c3

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

WooCommerce/Classes/ViewRelated/Coupons/UsageDetails/CouponUsageDetailsViewModel.swift

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,54 @@ final class CouponUsageDetailsViewModel: ObservableObject {
99

1010
let currencySymbol: String
1111

12-
@Published var minimumSpend: String = ""
12+
@Published var minimumSpend: String
1313

14-
@Published var maximumSpend: String = ""
14+
@Published var maximumSpend: String
1515

16-
@Published var usageLimitPerCoupon: String = ""
16+
@Published var usageLimitPerCoupon: String
1717

18-
@Published var usageLimitPerUser: String = ""
18+
@Published var usageLimitPerUser: String
1919

20-
@Published var limitUsageToXItems: String = ""
20+
@Published var limitUsageToXItems: String
2121

22-
@Published var allowedEmails: String = ""
22+
@Published var allowedEmails: String
2323

24-
@Published var individualUseOnly: Bool = false
24+
@Published var individualUseOnly: Bool
2525

26-
@Published var excludeSaleItems: Bool = false
26+
@Published var excludeSaleItems: Bool
2727

2828
init(coupon: Coupon,
2929
currencySettings: CurrencySettings = ServiceLocator.currencySettings) {
3030
self.coupon = coupon
3131
self.currencySymbol = currencySettings.symbol(from: currencySettings.currencyCode)
32-
populateDetails()
33-
}
34-
}
3532

36-
// MARK: - Private helpers
37-
//
38-
private extension CouponUsageDetailsViewModel {
39-
func populateDetails() {
40-
minimumSpend = coupon.minimumAmount
41-
maximumSpend = coupon.maximumAmount
33+
self.minimumSpend = coupon.minimumAmount
34+
self.maximumSpend = coupon.maximumAmount
4235
if let perCoupon = coupon.usageLimit {
43-
usageLimitPerCoupon = "\(perCoupon)"
36+
self.usageLimitPerCoupon = "\(perCoupon)"
4437
} else {
45-
usageLimitPerCoupon = ""
38+
self.usageLimitPerCoupon = ""
4639
}
4740

4841
if let perUser = coupon.usageLimitPerUser {
49-
usageLimitPerUser = "\(perUser)"
42+
self.usageLimitPerUser = "\(perUser)"
5043
} else {
51-
usageLimitPerUser = ""
44+
self.usageLimitPerUser = ""
5245
}
5346

5447
if let limitUsageItemCount = coupon.limitUsageToXItems {
55-
limitUsageToXItems = "\(limitUsageItemCount)"
48+
self.limitUsageToXItems = "\(limitUsageItemCount)"
5649
} else {
57-
limitUsageToXItems = ""
50+
self.limitUsageToXItems = ""
5851
}
5952

6053
if coupon.emailRestrictions.isNotEmpty {
61-
allowedEmails = coupon.emailRestrictions.joined(separator: ", ")
54+
self.allowedEmails = coupon.emailRestrictions.joined(separator: ", ")
6255
} else {
63-
allowedEmails = ""
56+
self.allowedEmails = ""
6457
}
6558

66-
individualUseOnly = coupon.individualUse
67-
excludeSaleItems = coupon.excludeSaleItems
59+
self.individualUseOnly = coupon.individualUse
60+
self.excludeSaleItems = coupon.excludeSaleItems
6861
}
6962
}

0 commit comments

Comments
 (0)