Skip to content

Commit

Permalink
make favorites work with reload/reconfigure
Browse files Browse the repository at this point in the history
needed to implement a proper `==`, the default was comparing the full view model, which is not what we want

#1
  • Loading branch information
jessesquires committed Sep 13, 2021
1 parent 1ece8fc commit 2bd1416
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Example/Sources/Grid/GridColorCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ struct GridColorCellViewModel: CellViewModel {
cell.label.text = self.color.name
cell.backgroundColor = self.color.uiColor
}

// MARK: Equatable

public static func == (left: GridColorCellViewModel, right: GridColorCellViewModel) -> Bool {
left.color == right.color
}
}
6 changes: 6 additions & 0 deletions Example/Sources/Grid/GridPersonCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ struct GridPersonCellViewModel: CellViewModel {
let personVC = PersonViewController(person: self.person)
controller.navigationController?.pushViewController(personVC, animated: true)
}

// MARK: Equatable

public static func == (left: GridPersonCellViewModel, right: GridPersonCellViewModel) -> Bool {
left.person == right.person
}
}
6 changes: 6 additions & 0 deletions Example/Sources/List/ListColorCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ struct ListColorCellViewModel: CellViewModel {
cell.accessories = []
}
}

// MARK: Equatable

public static func == (left: ListColorCellViewModel, right: ListColorCellViewModel) -> Bool {
left.color == right.color
}
}
6 changes: 6 additions & 0 deletions Example/Sources/List/ListPersonCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ struct ListPersonCellViewModel: CellViewModel {
let personVC = PersonViewController(person: self.person)
controller.navigationController?.pushViewController(personVC, animated: true)
}

// MARK: Equatable

public static func == (left: ListPersonCellViewModel, right: ListPersonCellViewModel) -> Bool {
left.person == right.person
}
}
3 changes: 3 additions & 0 deletions Sources/DiffableDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ extension _DiffableDataSource {
destinationSnapshot.reloadItems(itemsToReload)
}

// TODO: reload headers/footers and supplementary views?
// (gets out-of-sync when deleting items)

self.applySnapshot(destinationSnapshot, animated: animated, completion: completion)
}

Expand Down

0 comments on commit 2bd1416

Please sign in to comment.