Skip to content

Commit bed0171

Browse files
committed
OrdersVM: Rename onShouldResynchronize* block
Mentioning `IfViewIsVisible` is more appripriate now that the block is called by multiple scenarios in the `ViewModel`.
1 parent 930452f commit bed0171

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrdersViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private extension OrdersViewController {
137137
/// Initialize ViewModel operations
138138
///
139139
func configureViewModel() {
140-
viewModel.onShouldResynchronizeAfterAppActivation = { [weak self] in
140+
viewModel.onShouldResynchronizeIfViewIsVisible = { [weak self] in
141141
guard let self = self,
142142
// Avoid synchronizing if the view is not visible. The refresh will be handled in
143143
// `viewWillAppear` instead.

WooCommerce/Classes/ViewRelated/Orders/OrdersViewModel.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ final class OrdersViewModel {
3131
///
3232
private var cancellable: ObservationToken?
3333

34-
/// The block called if self requests a resynchronization of the first page.
34+
/// The block called if self requests a resynchronization of the first page. The
35+
/// resynchronization should only be done if the view is visible.
3536
///
36-
var onShouldResynchronizeAfterAppActivation: (() -> ())?
37+
var onShouldResynchronizeIfViewIsVisible: (() -> ())?
3738

3839
/// OrderStatus that must be matched by retrieved orders.
3940
///
@@ -143,7 +144,7 @@ final class OrdersViewModel {
143144
}
144145

145146
isAppActive = true
146-
onShouldResynchronizeAfterAppActivation?()
147+
onShouldResynchronizeIfViewIsVisible?()
147148
}
148149

149150
/// Returns what `OrderAction` should be used when synchronizing.
@@ -257,7 +258,7 @@ private extension OrdersViewModel {
257258
return
258259
}
259260

260-
self?.onShouldResynchronizeAfterAppActivation?()
261+
self?.onShouldResynchronizeIfViewIsVisible?()
261262
}
262263
}
263264

WooCommerce/WooCommerceTests/ViewRelated/Orders/OrdersViewModelTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ final class OrdersViewModelTests: XCTestCase {
334334
let viewModel = OrdersViewModel(notificationCenter: notificationCenter, statusFilter: nil)
335335

336336
var resynchronizeRequested = false
337-
viewModel.onShouldResynchronizeAfterAppActivation = {
337+
viewModel.onShouldResynchronizeIfViewIsVisible = {
338338
resynchronizeRequested = true
339339
}
340340

@@ -354,7 +354,7 @@ final class OrdersViewModelTests: XCTestCase {
354354
let viewModel = OrdersViewModel(notificationCenter: notificationCenter, statusFilter: nil)
355355

356356
var resynchronizeRequested = false
357-
viewModel.onShouldResynchronizeAfterAppActivation = {
357+
viewModel.onShouldResynchronizeIfViewIsVisible = {
358358
resynchronizeRequested = true
359359
}
360360

@@ -375,7 +375,7 @@ final class OrdersViewModelTests: XCTestCase {
375375
let viewModel = OrdersViewModel(pushNotificationsManager: pushNotificationsManager, statusFilter: nil)
376376

377377
var resynchronizeRequested = false
378-
viewModel.onShouldResynchronizeAfterAppActivation = {
378+
viewModel.onShouldResynchronizeIfViewIsVisible = {
379379
resynchronizeRequested = true
380380
}
381381

@@ -395,7 +395,7 @@ final class OrdersViewModelTests: XCTestCase {
395395
let viewModel = OrdersViewModel(pushNotificationsManager: pushNotificationsManager, statusFilter: nil)
396396

397397
var resynchronizeRequested = false
398-
viewModel.onShouldResynchronizeAfterAppActivation = {
398+
viewModel.onShouldResynchronizeIfViewIsVisible = {
399399
resynchronizeRequested = true
400400
}
401401

0 commit comments

Comments
 (0)